Error: TRADE permission required

Created at 21 Mar 2022, 11:13
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
CS

csabz90

Joined 09.03.2022

Error: TRADE permission required
21 Mar 2022, 11:13


Hi All,

 

I am using OpenApiPy and am able to authenticate application, then account, then do anything I want such as getting historical data, but the one thing I can't seem to do is opening a trade. The response I get is 'TRADE permission required'. Any ideas on why this is the case? Maybe I missed something in the API application process? 

I am using a demo account currently so my first thought was maybe that's the reason, but I am able to open trades using FIX API for the same demo account, only lacking the permission through Open API.

Code I'm using is this:

from ctrader_open_api import Client, Protobuf, TcpProtocol, Auth, EndPoints
from ctrader_open_api.messages.OpenApiCommonMessages_pb2 import *
from ctrader_open_api.messages.OpenApiCommonMessages_pb2 import *
from ctrader_open_api.messages.OpenApiMessages_pb2 import *
from ctrader_open_api.messages.OpenApiModelMessages_pb2 import *
from twisted.internet import reactor
import json
import datetime

credentialsFile = open("credentials-dev.json")
credentials = json.load(credentialsFile)

host = EndPoints.PROTOBUF_LIVE_HOST if credentials["HostType"].lower() == "live" else EndPoints.PROTOBUF_DEMO_HOST
client = Client(host, EndPoints.PROTOBUF_PORT, TcpProtocol)

def open_order(result):
    print('Opening order!')
    request = ProtoOANewOrderReq()
    request.ctidTraderAccountId = credentials["AccountId"]
    request.symbolId = 1
    request.volume = 100000
    request.orderType = 1
    request.tradeSide = 1
    deferred = client.send(request)

def accountAuthResponseCallback(result):
    print("\nAccount authenticated")
    request = ProtoOASymbolsListReq()
    request.ctidTraderAccountId = credentials["AccountId"]
    request.includeArchivedSymbols = False
    deferred = client.send(request)
    deferred.addCallbacks(open_order, onError)
    
def applicationAuthResponseCallback(result):
    print("\nApplication authenticated")
    request = ProtoOAAccountAuthReq()
    request.ctidTraderAccountId = credentials["AccountId"]
    request.accessToken = credentials["AccessToken"]
    deferred = client.send(request)
    deferred.addCallbacks(accountAuthResponseCallback, onError)

def onError(client, failure): # Call back for errors
    print("\nMessage Error: ", failure)

def disconnected(client, reason): # Callback for client disconnection
    print("\nDisconnected: ", reason)

def onMessageReceived(client, message): # Callback for receiving all messages
    if message.payloadType in [ProtoHeartbeatEvent().payloadType, ProtoOAAccountAuthRes().payloadType, ProtoOAApplicationAuthRes().payloadType, ProtoOASymbolsListRes().payloadType, ProtoOAGetTrendbarsRes().payloadType]:
        return
    print("\nMessage received: \n", Protobuf.extract(message))
    
def connected(client): # Callback for client connection
    print("\nConnected")
    request = ProtoOAApplicationAuthReq()
    request.clientId = credentials["ClientId"]
    request.clientSecret = credentials["Secret"]
    deferred = client.send(request)
    deferred.addCallbacks(applicationAuthResponseCallback, onError)
    
# Setting optional client callbacks
client.setConnectedCallback(connected)
client.setDisconnectedCallback(disconnected)
client.setMessageReceivedCallback(onMessageReceived)

# Starting the client service
client.startService()
# Run Twisted reactor, we imported it earlier
reactor.run()

Thanks!


@csabz90
Replies

amusleh
21 Mar 2022, 12:55

Hi,

Did you checked all the checkbox(s) on your application form under Application Usages?

If you did that then please send an email to connect@spotware.com with your application name and your cID.


@amusleh

csabz90
21 Mar 2022, 19:22

RE:

amusleh said:

Hi,

Did you checked all the checkbox(s) on your application form under Application Usages?

If you did that then please send an email to connect@spotware.com with your application name and your cID.

Thanks, I have just sent an email to the address you provided. I ticked the checkboxes that I felt were appropriate (get own account information, trade on own behalf), and now just out of curiosity I checked all boxes, still no luck with opening a trade. Will see what response I get back to my email!


@csabz90

amusleh
22 Mar 2022, 08:29

Hi,

I tested the Python console sample on your application, it worked fine, I was able to create new market orders on my demo trading accounts.

Can you tell me which broker you are using?

And please try on console sample, see if it works or not.


@amusleh

csabz90
22 Mar 2022, 10:57

Thanks for checking! I had a go at it using the console sample from your repo as you suggested, same error unfortunately.

I have a demo account with IC Markets, that's what I'm trying to use. What's weird is using FIX API to communicate with cTrader I am able to open a market order, but with Open API I can't, 'TRADE permission required'... Can you imagine the broker allowing demo trading through cTrader through FIX API but not through Open API? Anyway, I'll try with another broker just to check. Please don't hold back if you have any broker suggestions for this purpose!

 


@csabz90

amusleh
22 Mar 2022, 11:30

RE:

csabz90 said:

Thanks for checking! I had a go at it using the console sample from your repo as you suggested, same error unfortunately.

I have a demo account with IC Markets, that's what I'm trying to use. What's weird is using FIX API to communicate with cTrader I am able to open a market order, but with Open API I can't, 'TRADE permission required'... Can you imagine the broker allowing demo trading through cTrader through FIX API but not through Open API? Anyway, I'll try with another broker just to check. Please don't hold back if you have any broker suggestions for this purpose!

 

Hi,

I tested on IC demo, and it worked fine.


@amusleh

mywebsidekicks
12 Jun 2024, 17:40

So have you found the solution since then?


@mywebsidekicks