Profile Picture

Add/remove open and pending positions to/from PositionManager

Posted By alpha23 6 Years Ago

Add/remove open and pending positions to/from PositionManager

Message
Posted Monday June 20 2011
Is there a way to add/remove open and pending positions to/from PositionManager? If there is a connection issue between TWS, for example, and RE, position information may not be logged or can also be lost. I’ve worked around this issue by creating a separate list of open positions which are read from an excel file (created from TWS trade log) upon live system start. However, this does not work well since there are 2 code paths: 1 to handle positions in the LiveOpenPositions file and the 2nd to handle the positions from the excel file. I would greatly like to consolidate code and reduce the possibilities for errors.

Thanks, Duane
Posted Thursday June 23 2011
You can edit the LiveOpenPositions.xml file. It's not really practical to edit by hand but you could write a tool that did it. In the next major version of RightEdge we're planning to have that functionality built in.

In build 35/36 there are improvements to how the TWS plugin handles reconnection and resyncing, so hopefully you will run into this issue less anyway.

Thanks,
Daniel
Posted Thursday June 23 2011
Editing by hand is a painful alternative as I've attempted to do this before which lead me to write the two code paths. I will be testing build 36 over the upcoming weeks so hopefully there will be less issues.

Thanks, Duane
Posted Thursday September 20 2012
Daniel,

   Is there a way to add a method in the scripts that would allow positions to be added before live execution starts? This would allow positions that were executed by the broker, e.g. IB, but not tracked by RE, to be added seamlessly. While the improvements in the TWS plugin has helped there are settings that I save in the custom string for each position which are critical to my system. These settings are lost when they are not in the LiveOpenPositions file. This forces me to have 2 code paths which is extremely painful at times: a) one for positions tracked by RE and b) one that tracks positions lost because of a shutdown by RE followed by an execution of a trade in TWS. I would really like to collapse the code into 1 code path. Being able to do the above would be of significant help.

Note, the idea discussed in above posts of manually entering the position directly into RE, versus programmatically adding the positions, is a plus but will still be difficult in my case due to the custom string settings coupled with the number of positions that I may have opened at any one time. Being able to programmatically add the positions in by far superior.

Please let me know.

Thanks, Duane

Posted Friday September 21 2012
The LiveOpenPositions.xml file should keep track of not only the open positions but also "pending" positions. When you run your system again and reconnect to IB, it should process the fills that happened while you were disconnected, and you should get a fill pretty much like you normally would have.

Are you calling PositionManager.SaveOpenPositions() already? If so, when are you doing so? You probably should call it every time you submit an order. That way RightEdge should keep track of all the orders and when you reconnect you should get the behavior I described above.

Thanks,
Daniel
Posted Saturday September 22 2012
I think that will work. I didn’t realize that a reconnect would handle the pending orders upon a reconnect if executed in TWS while disconnected.

I’m using PositionManager.SaveOpenPositions() but in OrderFilled. Based on the above, I will change to before a submit.

Thanks for clarifying. It greatly simplifies things to be able to collapse these code paths.

Also, I appreciate the connectivity improvements between TWS and RE that have been made in builds over the past year or so. These improvements have been critical to running a live system against TWS.

Thanks, Duane

Edited: Saturday September 22 2012 by alpha23
Posted Sunday September 23 2012
I’m using PositionManager.SaveOpenPositions() but in OrderFilled. Based on the above, I will change to before a submit.


Well, you need to do the save after you submit the order. Otherwise what you save won't include the order you haven't submitted yet. Smile

Daniel
Posted Sunday September 23 2012
Or even better yet, SaveOpenPositions is probably best implemented in RE so I don’t have to worry about saving the file Smile

Joking aside, since every system that runs live needs to include these calls, manual insertions of SaveOpenPositions can be error prone especially if there are multiple places in the code where orders are placed. I’m grateful that the call is available but would it be possible to include this functionality in a future release?

Thanks, Duane

Edited: Sunday September 23 2012 by alpha23
Posted Tuesday September 25 2012
Daniel,

The exception below was thrown during a SaveOpenPositions call when a position was opened in TWS while my code was at a breakpoint in my code. Please advise as soon as possible because I need to ensure that the positions are always tracked between TWS and RE.

Thanks, Duane

An exception of type System.Collections.Generic.KeyNotFoundException was thrown.
The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at RightEdge.Common.SystemData.GetCurrentPrice(Symbol symbol)
at RightEdge.Common.Internal.PortfolioXml.AddLastPrice(Symbol symbol, SystemData systemData)
at RightEdge.Common.Internal.PortfolioXml.AddPosition(PositionData pos, Boolean bPending, PositionManager manager)
at RightEdge.Common.PositionManager.GetPortfolioXml()
at RightEdge.Common.PositionManager.SaveOpenPositions(String fileName)
at RightEdge.Shared.SystemWrapper.SaveOpenPositions(String fileName)
at RightEdge.Shared.SystemWrapper.SaveOpenPositions(String fileName)
at RightEdge.LiveSystemwindow.StopLiveSystem()
Posted Thursday September 27 2012
That error looks like it's caused because you submitted an order for a symbol that wasn't one of the symbols you selected in the watch list when you ran your system. It also might happen if you programmatically changed any of the Symbol objects in your trading system code.

Does that help?

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems