I've hacked together an example based on a chart trader button addon.
Upon pressing the button 5 limit orders are submitted on the sim account.
Make sure you are connected and orders are higher than your current AMZN price so they don't execute. ($104 to $108)
All 5 orders display as working in the orders list, but order1 does NOT display in chart trader.
Now after disconnecting and reconnecting to Sim101, order5 and order1 will vanish from the order list, order5 from chart trader too.
Basically that's it. Why does manual creation of order5 fail to display in chart trader? why does only order1 vanish after reconnect?
This isn't the same error as in my real code, but they both give the same error in the NT log file, so I'm hoping your solution will help. My real code is long and I was unable to reproduce that same error. It places 1-4 orders using createorder(), which work fine until reconnect. Then they all vanish except for one in the order list which is stuck on orange initialize.
If I now run my test code it will add the orders as stated earlier, but now on reconnect ALL 5 will vanish except that orange one that is stuck on initialize.
So I'm thinking that stuck order blocks up your database somehow. You can repeat the test by resetting the Sim account, it's the only way to escape.
Log complains about the 'Kind' of time being wrong, that's why in my test file I have prints of that value.
From the debug prints it seems the Gtd time gets reset to 2099 after reconnect, and the 'Kind' becomes unspecified. Maybe that's causing a problem.
------------------------------------------------------------------------------------------------------------------------
Log Error:
2023-02-10 13:48:09:493|3|524288|Error on executing DB command: System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.
Parameter name: sourceTimeZone
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
at NinjaTrader.Cbi.Order.DbAdd()
at NinjaTrader.Cbi.DB.DBThread()
------------------------------------------------------------------------------------------------------------------------
Trace file has the same error, but also an SQLite error:
2023-02-10 13:31:34:504 (Db) Cbi.DB.DBThread.Exception: error=-1 [orderId='04b667aa3b114bae8c83fec0de4c9606' account='Sim101' name='name1' orderState=Working instrument='AMZN' orderAction=Sell orderType='Limit' limitPrice=101 stopPrice=0 quantity=100 tif=Gtd oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=66 time='2023-02-10 13:31:24' gtd='2023-02-12' statementDate='2023-02-10', Update]
System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local.
Parameter name: sourceTimeZone
at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData)
at NinjaTrader.Cbi.Order.DbUpdate()
at NinjaTrader.Cbi.DB.DBThread()
2023-02-10 13:31:34:505 ERROR: Error on executing DB command: System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData) at NinjaTrader.Cbi.Order.DbUpdate() at NinjaTrader.Cbi.DB.DBThread()
2023-02-10 13:31:44:506 SQLite error (787): abort at 35 in [INSERT INTO OrderUpdates([Order],Nr,AvgFillPrice,Comment,[Error],Filled,LimitPrice,OrderId,OrderState,Quantity,Ser verName,StatementDate,StopPrice,Time) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)]: FO
2023-02-10 13:31:44:507 Cbi.Order.DbAddOrderUpdate.Failed.!PF!: id=638116326846563602 orderId='' orderId='' account='Sim101' name='name5' orderState=Submitted instrument='AMZN' orderAction=Sell limitPrice=105 stopPrice=0 quantity=100 orderType='Limit' filled=0 averageFillPrice=0 time='2023-02-10 13:31:24' statementDate='2023-02-10' error=NoError comment='' nr=0
i=0 orderId='' account='Sim101' name='name5' orderState=Submitted instrument='AMZN' orderAction=Sell limitPrice=105 stopPrice=0 quantity=100 orderType='Limit' filled=0 averageFillPrice=0 time='2023-02-10 13:31:24' statementDate='2023-02-10' error=NoError comment='' nr=0
i=1 orderId='' account='Sim101' name='name5' orderState=Accepted instrument='AMZN' orderAction=Sell limitPrice=105 stopPrice=0 quantity=100 orderType='Limit' filled=0 averageFillPrice=0 time='2023-02-10 13:31:24' statementDate='2023-02-10' error=NoError comment='' nr=-1
i=2 orderId='' account='Sim101' name='name5' orderState=Working instrument='AMZN' orderAction=Sell limitPrice=105 stopPrice=0 quantity=100 orderType='Limit' filled=0 averageFillPrice=0 time='2023-02-10 13:31:24' statementDate='2023-02-10' error=NoError comment='' nr=-1
code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed
FOREIGN KEY constraint failed
at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCo mmand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(Com mandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(C ommandBehavior behavior)
at NinjaTrader.Cbi.Order.DbAddOrderUpdate(OrderEventA rgs e)
**********************
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at NinjaTrader.Cbi.Order.DbAddOrderUpdate(OrderEventA rgs e)
at NinjaTrader.Cbi.Order.DbUpdate()
at NinjaTrader.Cbi.DB.DBThread()
at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
------------------------------------------------------------------------------------------------------------------------
In the SQLite exception there is '[Error]' for one of the parameters:
2023-02-10 13:31:44:506 SQLite error (787): abort at 35 in [INSERT INTO OrderUpdates([Order],Nr,AvgFillPrice,Comment,[Error],Filled,LimitPrice
This is possibly for order5 which is my manual submit attempt (see code), could be I've not set a value which is required.
Since I use createorder() in my real code I'd like to fix the issues with that method as priority. What's going on with that date Kind error and how to fix it.
Oh I almost forgot, If I place an order normally by right clicking the chart and selecting sell limit, then that order will persist between reconnects.
So it's just the orders placed via code which have the problem.
Edit: It got worse! In my manual submit I just realised I was setting the Order.Id instead of Order.OrderId. After switching to OrderId it's now completely broken everything. Now after reconnect EVERY order is gone, even ones I placed with right click. The SQLite error seems to be gone now, it's just that date 'Kind' error flooding the log and trace files.
I've reset the Sim account several times now and the vanishing behavior is consistent. In my real code I use the Gtd value and my own OrderIds, basically the 2 parameters which are seeming to cause problems.
Attached code is the completely broken version.
Notes: code might be buggy, I moved some things around and haven't made a safe implementation regarding the button.
If the button doesn't appear then try a recompile while a chart trader window is open.
Version 8.0.27.1

Comment