C# TWS API - get position information

Hello Rodras,

Happy to see this post, I have the same issue, I'm trying to use the function self.reqAccountUpdates(True, self.account) or self.reqPositions() in Python and it always returns all the positions together, I tried to filter the output, but was not successful!!

Any chance to share your thoughts on how you solved it? my end goal is to return the position of the contract I want, let's say AAPL, I will need the position (qty) and AvgCost variable to use in another function

I appreciate your help
Hi Topper,

First of all I must say that I'm a C# newbie that picks some program routines in forums and then adapts them to my needs.

Regarding to your issue, the way I found to get around the position problem was direct the reqPositions() return - of all open (and opened) positions in the session - into a grid, in a sort of thread similar to an holowczak (http://holowczak.com/ib-api-socket-csharp-realtime-winforms) example.
After having that in information in a grid, you can access the data you wish (contract, position size, average cost) by filtering the data in a particular column (in my case I filter by contract symbol to get the open position size).

Just after I wrote the reply I above noticed that you are using Python. My suggestion then it to change the position function to output as list instead of printing and then create a function to run a search thru the list elements to get the information you desire.

I believe there will be several other ways, more technically correct and more efficient to get that info, but that's how I patched my problem.

I hope the above will be helpful.
 
Last edited:
Back
Top