Topics
Replies
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
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:
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