What is an exact order of events Positions.* and PendingOrders.*
What is an exact order of events Positions.* and PendingOrders.*
30 Jul 2020, 09:56
The current position is flat. No pending order. The account is NETTING.
Current price is 10.
There are 6 event handlers. All not relevant details are missed. Sleep(100ms); means some long time to handle an event.
Positions.Opened += (...) => { Print ("Position opened "+ PositionSize); Sleep(100ms);};
Positions.Modified += (...) => { Print ("Position modified "+PositionSize); Sleep(100ms);};
Positions.Closed += (...) => { Print ("Position closed"); Sleep(100ms);};;
PendingOrders.Filled += (..) =>{ Print ("Filled" + OrderComment); Sleep(100ms);};
PendingOrders.Cancelled += (...) =>{ Print ( "Cancelled" +OrderComment); Sleep(100ms);};
PendingOrders.Created += (...) =>{ Print ("Created" +OrderComment); Sleep(100ms);};
Somewhere in the bot 4 orders with the comment were placed. No error:
PlaceLimitOrder (Sell, 1 lot @ 23, "It is the ORDER 1")
PlaceLimitOrder (Sell, 10 lots @ 23, "It is the ORDER 2")
PlaceLimitOrder (Sell, 100 lots @ 23, "It is the ORDER 3")
PlaceLimitOrder (Sell, 1000 lots @ 23, "It is the ORDER 4")
Print("all orders are placed. ****")
I am expecting to see these lines as an output:
Created It is the ORDER 1
Created It is the ORDER 2
Created It is the ORDER 3
Created It is the ORDER 4
all orders are placed. ****
The market moves from the price 10 to 30 with a gap. All orders should be filled. Assume all of them are filled at the same price 23
What is an exact order of calling PendingOrders.Filled and Positions.Opened and Positions.Modified
What is an expected output of this code, please?
Thank you!
Replies
koktos632
04 Aug 2020, 15:26
RE:
"The first order will be filled and the position will open. The subsequent orders will then be filled and the position will be modified accordingly."
Thank you for your answer. It does not answer my question however.
My question is more specific.
What is an expected output of this code, please?
@koktos632
PanagiotisCharalampous
04 Aug 2020, 15:30
Hi koktos632,
There is no single expected outcome. Events will be triggered as soon as responses arrive from the server. Many operations happen asynchronously on the server therefore there is no expected sequence of events. Orders can be executed in any order.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
31 Jul 2020, 08:48
Hi koktos632,
The first order will be filled and the position will open. The subsequent orders will then be filled and the position will be modified accordingly.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous