Topics
Replies
wwzz
16 Dec 2024, 18:27
( Updated at: 17 Dec 2024, 07:44 )
RE: is there a way to close all positions at once from the openapi?
swapd0 said:
Why you don't already have the position list? Try to create the list when your application start.
Also, for each ProtoOAClosePositionReq() message, are you waiting for the response or just “send and forget” style?
Hi, Thanks for reply - I am using python + crochet. I am creating the position list as part of code. and for every request I have to wait for response (My bot trade 5 mins bars, need to open/close on everything 4:59)
@wwzz
wwzz
16 Dec 2024, 18:20
( Updated at: 17 Dec 2024, 07:44 )
RE: is there a way to close all positions at once from the openapi?
PanagiotisCharalampous said:
Hi there,
Please share your source code so that we can understand what you are doing.
Best regards,
Panagiotis
Hi, Thanks for your reply. Here are my code - python + jupyter notebook + crochet + win11 (not the best setup I know…)
########message call back to extract position list
elif message.payloadType == ProtoOAReconcileRes().payloadType:
global position_list;
position_list = Protobuf.extract(message)
########create a dictionary contains volumn and position id #
request = ProtoOAReconcileReq()
request.ctidTraderAccountId = ctrader_log["AccountId"]
client.send(request, responseTimeoutInSeconds = 1)
close_list = {};
for p in position_list.position:
close_list[p.positionId] = [p.tradeData.volume];
########loop the close list to close all positions #
for c in close_list:
request = ProtoOAClosePositionReq()
request.ctidTraderAccountId = ctrader_log["AccountId"]
request.positionId = c
request.volume = close_list[c][0]
client.send(request, responseTimeoutInSeconds = 10)
this process takes about 10 seconds to close 50 positions (5 per second), way below 50/second limit.
maybe the open api doesn't like python loop? I also tried joblib / ThreadPoolExecutor/ multiprocess to do this in parallel, but no luck. Thanks!
@wwzz
wwzz
21 Dec 2024, 02:17 ( Updated at: 23 Dec 2024, 00:18 )
RE: RE: RE: is there a way to close all positions at once from the openapi?
PanagiotisCharalampous said:
Thanks Panagiotis, I am switching to ctrader's fix API - it seems be able to avoid the sync/async issue completely .
@wwzz