Receive Positions from IB which are not submitted by IBController

to sync my IB-Account, I need to know, which positions are already in the TWS.
To receive a current Positionlist, I call ibc.GetPositionList(), but this receives only the positions submitted by the controller. All positions I entered manually are not shown.

How can I get a full list of all current positions ?


According to Interactive Brokers docs:

you should be getting those orders because IBController uses client ID = 0 and it calls reqAllOpenOrders() every two seconds here:

Whenever IB Traders Workstation works as documented or not, it is another story.

Hi Tomasz,
thanks for the reply. BTW I have a FA Account. ( dont know if this matters )
After inserting a couple of sleep(1000) before GetPendingList, GetPositionList and GetExecInfo,
it seems to work properly.
GetExecInfo doesnt need the sleep, i think.

This is so because Traders Workstation (TWS) sends account (portfolio) updates SLOWLY (approximately every second or less). That's the problem of TWS not IBController. Other updates are (almost) immediate.

@sven inserting a sleep can't change the behaviour. Updates can be delayed due to IB and IBC but they must occur anyway if your script runs periodically.

A side note about getting all orders: it's possible to configure a Master ID in TWS (Global Config > API...). Once set, all open orders & updates are sent to the client with this ID.
IBController needs ID 0 to connect properly though.

@alligator the script runs only once a day for eod trading.
In fact it behave different, if i dont do a sleep, i do not get the the open positions.

	ibc = GetTradingInterface("IB");
	if (ibc.IsConnected() ) {
		ibc.SetAccount( account ); 
		ibc.Sleep(1000);   // this is necessary on my pc
		openPositions = ibc.GetPositionList();
		_TRACE ("positions: " +openPositions);

@Tomasz is there a flag which is set to false once the GetPendingList/GetPositionsList is called and in openOrderEnd/PositionEnd to true to make sure all data is ready?

1 Like

It's not implemented as you seem to believe (read the code). GetPositionList() fetches data from the IBController list, not directly from IB servers. IBC doesn't send a request to IB servers when you call GetPositionList(), so it doesn't wait for an answer. It gives you what is in the Portfolio Tab, exactly what you can read from the GUI. When IBC gets a message from IB servers about portfolio, it is updated. There's no guarantee the list in IBC is exactly the list of positions for IB at the time of call. Not a problem in practice, especially if one only needs them eod.

thanks for your answer. maybe my approach for automating eod trading is wrong ?!
I want to trade different systems on one account. for this i do the following:
run a backtest of all systems and save the positions of each system to one file.
Then i compare my positions in tws with the positions in this file.
(this is where i need the readout positions from tws)

is there a better way to automate this ?

Portfolio tab holds the very same position list as TWS own "Account" page. There you can find all positions and they are updated periodically BUT SLOWLY (every second or less). When TWS own "Account" page is updated the same information is present in IBController. This is in contrast to all other information present in IBController that is updated "as things happen", when for example order status is changing or order gets filled.

As @alligator wrote, if you look at the code, you will see that all IBController calls retrive the exact same information which is displayed in IBController GUI. It does not wait for TWS. It is rather TWS itself sends updates in its own pace and these updates are reflected in IBController immediately as they arrive from TWS, but not sooner.