Today I had to make a call to the emergency trading desk because an error in rejection handling on my part caused repeated orders to be submitted. In hindsight it was unwise of me to deploy this code into live markets after only a few tests appeared to demonstrate expected behavior.
Below is the problem code...
if (e.OrderState == OrderState.Rejected)
{
if (e.Order.IsLong)
{
Order remedyLong = null;
TriggerCustomEvent( o =>
{
remedyLong = myAccount.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, OrderEntry.Manual,
TimeInForce.Day, quantity, 0, 0, "", "remedyLong"+DateTime.Now.ToString(), DateTime.MaxValue, null);
myAccount.Submit(new[] { remedyLong });
}, null);
}
else
{
Order remedyShort = null;
TriggerCustomEvent( o =>
{
remedyShort = myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, OrderEntry.Manual,
TimeInForce.Day, quantity, 0, 0, "", "remedyShort"+DateTime.Now.ToString(), DateTime.MaxValue, null);
myAccount.Submit(new[] { remedyShort });
}, null);
}
}
If anyone could offer insight as to why what happened today happened and what I can do to fix it I would be really appreciative. I want to be up and running with my code as soon as possible. I know the reference page for add on orders even says implementing them improperly has the ability to wreck your account, I wish I had taken a beat.
A related but much less important issue I'm having is that whenever I try to change parameters in the Indicators interface for this code I get an error that the Calling Thread Cannot Access the Object Because a different thread owns it. Is this an issue with the dispatcher i'm using to create the grid in the same script? if needed i will post instances where i am using a dispatcher.
Thank you everyone!

Comment