Order Lifecycle in Open API
Order Lifecycle in Open API
01 Aug 2024, 10:09
Hi everyone,
I manage to create a cTrade Java client so that I can copy orders from JForex to CTrader.
So far I'm struggling with the order lifecycle. I look at the .NET example in github but still can't find clear rule to detect the current state of an order.
I understand that from an Order -→ we can have 1 or many Positions and we can also have one or many deals.
After submitting an order, I'll receive many ProtoOAExecutionEvent events.
I would like clear rules on how to translate an ProtoOAExecutionEvent event into the correct Order State:
- Order Rejected
- How do I find the reason for rejection e.g not enough fund?
- Order Open
- Order Cancelled
- How do I find the Order cancelled reason?
- Order Filled
- Order Filled Partial
- Order Closed
- How do I find if it's closed by Take Profit, closed by Stop Loss or any other reason like not enough margin?
- Order Updated
- SL, TP or Entry change…
Finally when an Order is closed, which object should use to find profitloss information? is it Deal, Position or both?
Thank you in advance for your help.
Serge.
PanagiotisCharalampous
02 Aug 2024, 08:45
Hi there,
There is the ErrorCode filed with some textual explanation.
For SL/TP check theProtoOAOrder. ProtoOAOrderType. For stop outs check ProtoOAOrder.isStopOut
I hope this helps.
Best regards,
Panagiotis
@PanagiotisCharalampous