如何在 ib_insync TWS 中获得执行佣金

How can I get a commission of execution in ib_insync TWS

我需要在TWS中获得执行佣金。 我通过 ib_insync 库连接到他们 python。

我做的是:

ib = IB()
ib.connect('127.0.0.1', 7497, 1)
ib.placeOrder(contract, order)

for e in ib.executions():
    print(e)

问题是 - 此执行的佣金飞到哪里去了?我怎样才能抓住他们?

您应该在 https://groups.io/g/insync 询问具体情况,我怀疑这里是否有人使用该库。

佣金不会在执行中返回,而是在 commissionReport 中返回。 http://interactivebrokers.github.io/tws-api/classIBApi_1_1CommissionReport.html

注意id是执行id,在匹配佣金报告的执行中是相同的。

好的,我找到了解决办法:

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)

终于有了一个更简单的方法(如果你需要访问对象,它很有用),它:

self.ib.fills()  

将 return 包含所有必要对象的元组的 Fill 对象列表,例如 Contract、Order、Execution 和 CommissionReport。