Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IB : Exception in message dispatch. Handler 'commissionReport' for 'commissionReport' <...> in push_commissionreport ex = self.executions.pop(cr.m_execId) #53

Open
FGU1 opened this issue Feb 9, 2021 · 0 comments

Comments

@FGU1
Copy link

FGU1 commented Feb 9, 2021

Not really a technical bug on Backtrader side, IMO more a design problem on IB side, but I create this issue for information.
When trading with BT via IB, one can get this kind of message :

08-Oct-20 17:47:24 ERROR Exception in message dispatch. Handler 'commissionReport' for 'commissionReport' Traceback (most recent call last): File "x/backtrader-J2SaRgr0/lib/python3.7/site-packages/ib/opt/dispatcher.py", line 44, in __call__ results.append(listener(message)) File "x/backtrader/backtrader/backtrader/stores/ibstore.py", line 1323, in commissionReport self.broker.push_commissionreport(msg.commissionReport) File x/labs/backtrader/backtrader/backtrader/brokers/ibbroker.py", line 482, in push_commissionreport ex = self.executions.pop(cr.m_execId) KeyError: '0000e215.5f7e7752.01.01

This exception is raised when backtrader is running with a given ClientID, and that an order is placed manually or with another API connection and a different ClientID.
The reason is that BT cannot filter by ClientID when receiving commissionReport, as IB do not send a ClientID in the commissionReport message.

More details on this :

  • IB do send the ClientID and the OrderId with the openorder callback but not the ExecId (Which is normal as the order may not have been executed)

  • IB send the ExecId, the ClientID and the OrderId with the execDetails messages.

  • IB do not send the ClientID or OrderId with the commissionReport messages, the only thing that can be linked to an order that is then sent is the ExecId

So a running strategy will receive commissionReport messages for all order executed on TWS : its own orders, orders placed manually and from another clientId, but not the openorder and execDetails messages.
There are 2 exception for this :

  • ClientID 0 will receive openorders, execDetails and commissionReports for itself and for orders placed manually

  • If a ClientID is set as "Master API client ID" (in Global configuration / API / Settings) it will receive openorder, execDetails and commissionReport for all clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant