Multi accounts dictionary IB API
Hi there , Im having a bug when connecting to the IB api.
it's relating to the multi IB accounts
More specifically I get an error in the method _account_summary_handler of ibstate
acc = self.accounts[msg.account] KeyError: 'DU15195'
The problem is that I never see accounts initialised anywhere.
It is therefore trying to slice an empty dictionary.
Should the fix not be ?
acc=msg.account
Kind regards
Hi Jeroen
The reason it’s happening is because it’s setup for an advisor account (see IB friends and family https://www.interactivebrokers.com/ff/en/main.php). It should only be a few lines to change it to normal accounts, and I would accept that as a pull request too if you wanted to contribute it.
On 12 May 2018, at 16:48, Jeroen De Ryck [email protected] wrote:
Hi there , Im having a bug when connecting to the IB api.
it's relating to the multi IB accounts More specifically I get an error in acc = self.accounts[msg.account] KeyError: 'DU15195'
The problem is that I never see accounts initialised anywhere. It is therefore trying to slice an empty dictionary. Should the fix not be ? acc=msg.account
Kind regards
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
I'm working on a fix now. I'm just a bit confused as to where the Acc objects are being initialised. It seems to me that this is happening in _managed_accounts_handler, however because I will only be using only one account ,can I just initialise in _account_summary_handler?
@jerreyz You're right, it's in _managed_accounts_handler and I don't think it depends on whether you're using one or multiple accounts. In the case of single account you should just have a single-key dictionary in self.accounts
@imaginary-unit thanks for your comment.
I still kept getting errors because _account_summary_handler is being registered first and then tries to slice on an empty dictionary. I simply create the dictionary in _account_summary_handler and then ReqPositions from there. It's a quick and dirty fix, would be cleaner to just remove the accounts object alltogether as you don't really use it in a single account system
@jerreyz Well it depends on whether the multi-account support is needed to be maintained in this project or not, which I'm not really aware of :) If yes, then it's probably better to check if msg.account is in self.accounts inside _account_summary_handler and if it's not, just add it (and do the same thing in _managed_accounts_handler to avoid duplicates). If multi-account support is not needed, then sure accounts dictionary should be removed.