Unable to find cTID trader account with id=XXXXXX
Unable to find cTID trader account with id=XXXXXX
03 Dec 2023, 13:02
Hello
I'm running a script to test Open API:
from ctrader_open_api import Client, Protobuf, TcpProtocol, Auth, EndPoints
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
import calendar
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)
print(client)
symbolName = "EURUSD"
dailyBars = []
# We will use below method to transform the Open API trend bar to a tuple with bar open time, open price, high price, low price, and close price:
def transformTrendbar(trendbar):
openTime = datetime.datetime.fromtimestamp(trendbar.utcTimestampInMinutes * 60, datetime.timezone.utc)
openPrice = (trendbar.low + trendbar.deltaOpen) / 100000.0
highPrice = (trendbar.low + trendbar.deltaHigh) / 100000.0
lowPrice = trendbar.low / 100000.0
closePrice = (trendbar.low + trendbar.deltaClose) / 100000.0
return [openTime, openPrice, highPrice, lowPrice, closePrice, trendbar.volume]
def trendbarsResponseCallback(result):
print("\nTrendbars received")
trendbars = Protobuf.extract(result)
barsData = list(map(transformTrendbar, trendbars.trendbar))
global dailyBars
dailyBars.clear()
dailyBars.extend(barsData)
print("\ndailyBars length:", len(dailyBars))
print("\Stopping reactor...")
reactor.stop()
def symbolsResponseCallback(result):
print("\nSymbols received")
symbols = Protobuf.extract(result)
global symbolName
symbolsFilterResult = list(filter(lambda symbol: symbol.symbolName == symbolName, symbols.symbol))
if len(symbolsFilterResult) == 0:
raise Exception(f"There is symbol that matches to your defined symbol name: {symbolName}")
elif len(symbolsFilterResult) > 1:
raise Exception(
f"More than one symbol matched with your defined symbol name: {symbolName}, match result: {symbolsFilterResult}")
symbol = symbolsFilterResult[0]
request = ProtoOAGetTrendbarsReq()
request.symbolId = symbol.symbolId
request.ctidTraderAccountId = credentials["AccountId"]
request.period = ProtoOATrendbarPeriod.D1
# We set the from/to time stamps to 50 weeks, you can load more data by sending multiple requests
# Please check the ProtoOAGetTrendbarsReq documentation for more detail
request.fromTimestamp = int(
calendar.timegm((datetime.datetime.utcnow() - datetime.timedelta(weeks=50)).utctimetuple())) * 1000
request.toTimestamp = int(calendar.timegm(datetime.datetime.utcnow().utctimetuple())) * 1000
deferred = client.send(request)
deferred.addCallbacks(trendbarsResponseCallback, onError)
def accountAuthResponseCallback(result):
print("\nAccount authenticated")
request = ProtoOASymbolsListReq()
request.ctidTraderAccountId = credentials["AccountId"]
request.includeArchivedSymbols = False
deferred = client.send(request)
deferred.addCallbacks(symbolsResponseCallback, 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()
I've created credentials-dev.json
{
"ClientId": "myClientId",
"Secret": "mySecret",
"AccountId": 601509,
"AccessToken": "AccessTokenHere",
"HostType": "live"
}
And then I'm getting an output with an error like this:
Connected
Application authenticated
Message received:
errorCode: "CH_CTID_TRADER_ACCOUNT_NOT_FOUND"
description: "Unable to find cTID trader account with id=601509"
Account authenticated
Message received:
ctidTraderAccountId: 601509
errorCode: "INVALID_REQUEST"
description: "Trading account is not authorized"
Symbols received
Unhandled error in Deferred:
Traceback (most recent call last):
File "C:\Users\irmsc\OneDrive\pp\Backtimization2\venv\lib\site-packages\ctrader_open_api\factory.py", line 15, in received
self.client._received(message)
File "C:\Users\irmsc\OneDrive\pp\Backtimization2\venv\lib\site-packages\ctrader_open_api\client.py", line 46, in _received
responseDeferred.callback(message)
File "C:\Users\irmsc\OneDrive\pp\Backtimization2\venv\lib\site-packages\twisted\internet\defer.py", line 662, in callback
self._startRunCallbacks(result)
File "C:\Users\irmsc\OneDrive\pp\Backtimization2\venv\lib\site-packages\twisted\internet\defer.py", line 764, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
File "C:\Users\irmsc\OneDrive\pp\Backtimization2\venv\lib\site-packages\twisted\internet\defer.py", line 858, in _runCallbacks
current.result = callback( # type: ignore[misc]
File "C:/Users/irmsc/OneDrive/pp/Backtimization2/OpenAPI.py", line 47, in symbolsResponseCallback
symbolsFilterResult = list(filter(lambda symbol: symbol.symbolName == symbolName, symbols.symbol))
builtins.AttributeError: symbol
I'm pretty sure I've added the right cTID (it's the 6 digit number, right?), but it's unable to find it for some strange reason.
What else perhaps have I've done wrong?
Thanks for your help! :)
Replies
mywebsidekicks
23 Dec 2023, 16:40
RE: Unable to find cTID trader account with id=XXXXXX
wonepo@gmail.com said:
Hi,
Do you have a solution since ??
Nope :(
@mywebsidekicks
PanagiotisCharalampous
24 Dec 2023, 06:09
RE: RE: Unable to find cTID trader account with id=XXXXXX
mywebsidekicks said:
wonepo@gmail.com said:
Hi,
Do you have a solution since ??
Nope :(
Hi there,
You should not use the account number or the cTrader ID number in that field. You should use the ctidTraderAccountId that is included in ProtoOACtidTraderAccount
Best regards,
Panagiotis
@PanagiotisCharalampous
mywebsidekicks
13 Mar 2024, 11:58
( Updated at: 16 Mar 2024, 16:38 )
PanagiotisCharalampous said:
mywebsidekicks said:
wonepo@gmail.com said:
Hi,
Do you have a solution since ??
Nope :(
Hi there,
You should not use the account number or the cTrader ID number in that field. You should use the ctidTraderAccountId that is included in ProtoOACtidTraderAccount
Best regards,
Panagiotis
I'm a bit confused now, can you please give a code example
@mywebsidekicks
irmscher9
16 Mar 2024, 16:35
( Updated at: 17 Mar 2024, 07:14 )
RE: RE: RE: Unable to find cTID trader account with id=XXXXXX
PanagiotisCharalampous said:
mywebsidekicks said:
wonepo@gmail.com said:
Hi,
Do you have a solution since ??
Nope :(
Hi there,
You should not use the account number or the cTrader ID number in that field. You should use the ctidTraderAccountId that is included in ProtoOACtidTraderAccount
Best regards,
Panagiotis
Yes, can you give a working code example please
@irmscher9
PanagiotisCharalampous
17 Mar 2024, 07:24
RE: RE: RE: RE: Unable to find cTID trader account with id=XXXXXX
irmscher9 said:
PanagiotisCharalampous said:
mywebsidekicks said:
wonepo@gmail.com said:
Hi,
Do you have a solution since ??
Nope :(
Hi there,
You should not use the account number or the cTrader ID number in that field. You should use the ctidTraderAccountId that is included in ProtoOACtidTraderAccount
Best regards,
Panagiotis
Yes, can you give a working code example please
You can check the API examples below
https://github.com/spotware/OpenAPI.Net/tree/master/samples
https://github.com/spotware/OpenApiPy/tree/main/samples
@PanagiotisCharalampous
mywebsidekicks
11 Jun 2024, 10:42
( Updated at: 12 Jun 2024, 05:46 )
OK, finally I have found these so called ‘account IDs’! Hope this might be helpful to someone:
- Go to your cTrader apps page: https://openapi.ctrader.com/apps
- Click on the ‘Playground’ button next to an app you are working with
- Next click ‘Trading accounts’, there you'll find raw webpage with all your account data in JSON format
- You are interested in number under the "accountId"
@mywebsidekicks
wonepo@gmail.com
23 Dec 2023, 13:35
Hi,
Do you have a solution since ??
@wonepo@gmail.com