Reputation: 1949
I need to get a commission of execution in TWS. I connect to them through ib_insync library for python.
I do abt:
ib = IB()
ib.connect('127.0.0.1', 7497, 1)
ib.placeOrder(contract, order)
for e in ib.executions():
print(e)
The question is - where is the commissions for this executions is flying? how can i catch them all?
Upvotes: 0
Views: 1518
Reputation: 1949
Ok, I find a solution:
from ib_insync import IB
class MyTrader:
def __init__(self):
self.ib = IB()
self.ib.setCallback('commissionReport', self.commissionCallback)
def commissionCallback(self, *args):
print(args[-1]) # CommissionReport object will be printed when order is filed
def trulala(self):
self.ib.connect('127.0.0.1', 7498, 1)
contract = Contract(...)
order = Order(...)
self.ib.placeOrder(contract, order)
Finally exist a more simpler method (and it useful if you need an access to objects), it:
self.ib.fills()
will return a list of Fill objects which contains a tuple of all necessary objects, like Contract, Order, Execution and CommissionReport.
Upvotes: 2
Reputation: 10989
You should ask specifics at https://groups.io/g/insync I doubt anybody here uses that library.
Commissions aren't returned in executions, they are returned in commissionReport. http://interactivebrokers.github.io/tws-api/classIBApi_1_1CommissionReport.html
Notice that the id is the execution id which is the same in the execution that matches the commission report.
Upvotes: 1