C# TWS API - get position information

Discussion in 'App Development' started by rodras, Jun 25, 2020.

  1. rodras

    rodras

    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: May 12, 2021
    #11     May 12, 2021