Order Lifecycle in Open API

Created at 01 Aug 2024, 10:09
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
serge.owonaokoa's avatar

serge.owonaokoa

Joined 31.05.2024

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.


@serge.owonaokoa
Replies

PanagiotisCharalampous
02 Aug 2024, 08:45

Hi there,

  • How do I find the reason for rejection e.g not enough fund?
  • How do I find the Order cancelled reason?

There is the ErrorCode filed with some textual explanation.

  • How do I find if it's closed by Take Profit, closed by Stop Loss or any other reason like not enough margin?

For SL/TP check theProtoOAOrder. ProtoOAOrderType. For stop outs check ProtoOAOrder.isStopOut

I hope this helps.

Best regards,

Panagiotis


@PanagiotisCharalampous