I built a small program to test SubmitOrderUnmanaged(). If my account is flat, call SubmitOrderUnmanaged(...,OrderAction.Buy,..) to buy 100 shares of IBM stocks, if my account has positions as 100 share of IBM stocks, it calls SubmitOrderUnmanaged(...,OrderAction.Sell,..) to sell them.
When I send a limited buy order, the order can be shown in SupreDOM as my bid price is lower than market price for sometime.
But when I send a limit sell order, it doesn't shown in SuperDOM. Can you tell the reason?
My sell order price is 0.1 higher than market price, so it should be pending for some time before it is executed.
protected override void OnBarUpdate()
{
Print ("need_flat =" + need_flat);
if (need_flat)
{
Print ("Current Price = " + GetCurrentAsk());
myExit = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, 100, GetCurrentAsk() + 0.1, 0, "", "Buying 100");
Print (" myExit ======= " + myExit); // this print shows outputs.
need_flat = false;
first_time = false;
}
Print ("first_time =" + first_time);
if (first_time)
{
myEntry = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 100, GetCurrentBid() - 0.1, 0, "", "Buying 100");
first_time = false;
Print (" GetCurrentBid() = " + GetCurrentBid() + "myOrder = " + myEntry);
need_flat = false;
}
}
Current Price = 123.06
myExit ======= orderId='NT-00000-338' account='Sim101' name='Buying 100' orderState=Working instrument='IBM' orderAction=Sell orderType='Limit' limitPrice=123.16 stopPrice=0 quantity=100 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-09-23 15:56:10' gtd='2099-12-01' statementDate='2020-09-23'
I also added onOrderUpdate(), it shows the sell order looks normal: orderState is changing from Submitted -> Accepted -> Working
Comment