Profile Picture

Disappearing orders using RE/TWS

Posted By Zora 7 Years Ago
Message
Posted Monday July 12 2010
I see strange behavior when placing orders for a live system using RE2010 and TWS (Build 894.4). Shortly after starting, my system places limit orders for a number of stocks - sometimes in the tens - by calling SymbolScriptBase.OpenPosition for each one. All of the position parameters are defined in a PositionSettings object. The problem is that some of the orders placed this way vanish after being placed in RE. After calling OpenPosition, the error property of the returned Position is null, the position´s state is pending and the event handler for the OrderSubmitted event is triggered, allowing me to check the order id by printing it to a log. However, the order does not appear in the API tab of TWS like a successfully placed order should. There is also no mention of the order in the TWS xml audit file.
This problem does not affect all orders placed, but only the first few that are placed within several second of system startup. Subsequent orders placed using the same method are processed correctly and show up in TWS.
There is also a sudden jump in order id values between the "vanishing" orders and ones that placed correctly, i.e. the order id of the last order that vanished may be 20 and the order id of the next order (first correctly placed order) may be 29711.
All of this leads me to believe that the orders are getting lost somewhere before reaching TWS. This is a serious problem, preventing my system from working consistently. Do you have any idea what could be wrong? Can you suggest a way to track more closely what happens to an order sent from RE? Can you also describe how order id's are assigned?

Thank you!
Posted Tuesday July 13 2010
Are you looking at the OrderUpdated function? This may be providing some clues. Our order IDs are sequential and do not care if the order was successfully placed or not. It's simply a way to match things up later.

If OrderUpdated isn't being called or yielding any clues, the next step would be to look at the plugin itself. I'm not sure if you're running your system in Visual Studio, but there are Trace.WriteLine's in the plugin code that should spit out internal messages that may also yield clues.

Finally, is something relatively recent?

Zora (7/12/2010)
I see strange behavior when placing orders for a live system using RE2010 and TWS (Build 894.4). Shortly after starting, my system places limit orders for a number of stocks - sometimes in the tens - by calling SymbolScriptBase.OpenPosition for each one. All of the position parameters are defined in a PositionSettings object. The problem is that some of the orders placed this way vanish after being placed in RE. After calling OpenPosition, the error property of the returned Position is null, the position´s state is pending and the event handler for the OrderSubmitted event is triggered, allowing me to check the order id by printing it to a log. However, the order does not appear in the API tab of TWS like a successfully placed order should. There is also no mention of the order in the TWS xml audit file.
This problem does not affect all orders placed, but only the first few that are placed within several second of system startup. Subsequent orders placed using the same method are processed correctly and show up in TWS.
There is also a sudden jump in order id values between the "vanishing" orders and ones that placed correctly, i.e. the order id of the last order that vanished may be 20 and the order id of the next order (first correctly placed order) may be 29711.
All of this leads me to believe that the orders are getting lost somewhere before reaching TWS. This is a serious problem, preventing my system from working consistently. Do you have any idea what could be wrong? Can you suggest a way to track more closely what happens to an order sent from RE? Can you also describe how order id's are assigned?

Thank you!
Posted Monday July 19 2010
Problem solved (but I'm still puzzled by the cause) - the "vanishing" orders that were being placed right after system startup were actually going to the paper broker instead of the live one (I checked by outputing messages from within the paper broker). I have no idea why that happened (maybe you can explain it?), but by adding a small delay to give the system a little more time to finish whatever it needs to finish during statup, I made the system work correctly. I.e., now, after starting the live system, I just wait a few seconds before I start to place orders and all of them are correctly routed to TWS.

This also explains the order ID discrepancy - two different brokers were being used - and the fact that only the first few orders were disappearing. I always had the number of live lead bars set to 0 and the live data start date set to today's date. Additionally, I was checking to ensure the system was not in lead bars before placing my orders.

So why would a live system route any orders to the paper broker?
Posted Monday July 19 2010
I don't see anything that switches on the fly, can you send me a screen shot of your system properties and I'll try and duplicate it here?


Zora (7/19/2010)
Problem solved (but I'm still puzzled by the cause) - the "vanishing" orders that were being placed right after system startup were actually going to the paper broker instead of the live one (I checked by outputing messages from within the paper broker). I have no idea why that happened (maybe you can explain it?), but by adding a small delay to give the system a little more time to finish whatever it needs to finish during statup, I made the system work correctly. I.e., now, after starting the live system, I just wait a few seconds before I start to place orders and all of them are correctly routed to TWS.

This also explains the order ID discrepancy - two different brokers were being used - and the fact that only the first few orders were disappearing. I always had the number of live lead bars set to 0 and the live data start date set to today's date. Additionally, I was checking to ensure the system was not in lead bars before placing my orders.

So why would a live system route any orders to the paper broker?
Posted Thursday July 22 2010
I always had the number of live lead bars set to 0 and the live data start date set to today's date.


You probably want to just delete the value in the live data start date field. That field is for when you want to load historical data from the data store and run the system using it before switching to live mode. So in your case you probably have a bit of data in the data store for the current day and it is loading that data and running your system with it. Normally your system would be in lead bar mode during that period, and the orders would fail (the Error property would say that you were in the lead bars), but if the "Run full sim before starting live system" option is enabled in the RightEdge options then it will allow those orders to go to the paper broker. So that's probably what's happening for you.

If you disable that option, you should probably be able to take out the delay you added.

Thanks,
Daniel
Posted Monday August 02 2010
When I try to delete the date in Live Data Start Date, the system doesn't start properly. I don't remember exactly what happened, but I think it just hangs during initialization. When I set this date to today's date, I know for a fact that the system processes several lead bars (by checking InLeadBars property), even though the latest archive data is from yesterday. Also, I checked and the "Run full sim before starting live system" option was not selected.

Screenshot of my system params, as used today (August 2, 2010):

Posted Tuesday August 03 2010
I'm not able to reproduce. Perhaps you can send me the rep file?

Zora (8/2/2010)
When I try to delete the date in Live Data Start Date, the system doesn't start properly. I don't remember exactly what happened, but I think it just hangs during initialization. When I set this date to today's date, I know for a fact that the system processes several lead bars (by checking InLeadBars property), even though the latest archive data is from yesterday. Also, I checked and the "Run full sim before starting live system" option was not selected.

Screenshot of my system params, as used today (August 2, 2010):

Posted Friday August 06 2010
When I try to delete the date in Live Data Start Date, the system doesn't start properly. I don't remember exactly what happened, but I think it just hangs during initialization


You could try attaching a debugger and seeing what code is executing when it appears to hang.

If you just want to prevent it from sending orders to the paper broker when starting a live system, you can disable the "Run full sim before starting live system" option.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems