I cannot figure out how to cancel or modify the bad order unless called from a strategy addon. But this call has to come from a SuperDOM add on.
void AutoCorrectManualLimitOrderInadvertentlyPlacedInTheMoneyInTheSuperDOM()
{
[COLOR="SeaGreen"]//code simplified in anonymous event handlers; try-catch blocks omitted;[/COLOR]
Account myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
int slippage = 2;
myAccount.OrderUpdate += (o, e) =>
{
if (e == null)
return;
bool isInadvertentLimitOrder =
(
(e.Order.OrderEntry == OrderEntry.Manual) &&
(e.Order.OrderType == OrderType.Limit) &&
(e.Order.LimitPrice > 0) &&
(e.Order.LimitPrice != e.Order.StopPrice) &&
(
(
(e.Order.OrderAction == OrderAction.Buy) &&
(e.Order.Instrument.MarketData.Last.Ask > 0) &&
(e.Order.LimitPrice > (e.Order.Instrument.MarketData.Last.Ask + slippage * e.Order.Instrument.MasterInstrument.TickSize))
)
||
(
(e.Order.OrderAction == OrderAction.Sell) &&
(e.Order.Instrument.MarketData.Last.Bid > 0) &&
(e.Order.LimitPrice < (e.Order.Instrument.MarketData.Last.Bid - slippage * e.Order.Instrument.MasterInstrument.TickSize))
)
)
);
//there is still time to intercept the order before it is submitted
if ((e.OrderState == OrderState.Initialized) && (e.Order.Filled==0))
{
if (isInadvertentLimitOrder) {
Dispatcher.InvokeAsync(() =>
{
[COLOR="SeaGreen"][B]//How can the inadvertent order be cancelled or modified?
//CancelOrder() is a method only of the Strategies.Strategy class
//but I want to cancel a MANUAL order[/B][/COLOR]
myAccount.Submit(new[] { myAccount.CreateOrder (
e.Order.Instrument,
e.Order.OrderAction,
OrderType.StopLimit, // only this param changed from OrderType.Limit
e.Order.OrderEntry,
e.Order.TimeInForce,
e.Order.Quantity,
e.Order.LimitPrice,
e.Order.StopPrice,
e.Order.Oco,
e.Order.Name,
e.Order.Gtd,
null
)});
});
}
}
};
}

SFT-535
But it is bad for one's health.
It does not mean the platform should not provide protection against such stupid behavior. There is absolutely no reason why any trader would EVER intentionally buy limit above market.
Except some annoyance. Intercepting it with a confirmation reduce that further. But not making me suffer with confirmations for everything else with that unusable global confirmation preference.
Comment