Print log for Pending Order fail to fill

Created at 11 Jul 2018, 05:19
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!
TH

thongbaogiaodich

Joined 19.05.2018

Print log for Pending Order fail to fill
11 Jul 2018, 05:19


Dear cTrader,

My robot places some Pending Orders and wait to they're filled. But sometimes, account doesn't have enough free money to fill, and this Pending Order disappear with no notification.

How can I log when and which Order fail to fill?

Thanks!


@thongbaogiaodich
Replies

ap11
12 Jul 2018, 15:43

Hi Thongbaogiaodich,

You can use PendingOrders.Cancelled event. Event arguments have a property called Reason. And in case it will be 'Rejected'

Here is the example:

protected override void OnStart()
{
    PendingOrders.Cancelled += PendingOrders_Cancelled;
    PlaceStopOrder(TradeType.Buy, Symbol, Symbol.VolumeInUnitsMax, Symbol.Ask);
}

private void PendingOrders_Cancelled(PendingOrderCancelledEventArgs obj)
{
    var ord = obj.PendingOrder;
    Print("{0} order {1} {2} at {3} was cancelled, reason: {4}", ord.OrderType, ord.TradeType, ord.SymbolCode, ord.TargetPrice, obj.Reason);
}

It will output following log entry:
Stop order Buy EURUSD at 1.16634 was cancelled, reason: Rejected

Regards,
Andrey


@ap11

thongbaogiaodich
12 Jul 2018, 18:36

Thank Andrey for your reply! That all I need.


@thongbaogiaodich