【问题标题】:How can I get a commission of execution in ib_insync TWS我如何在 ib_insync TWS 中获得执行佣金
【发布时间】:2018-07-30 13:00:52
【问题描述】:

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

我是这样做的:

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

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

问题是 - 这次处决的佣金在哪里?我怎样才能把它们都抓起来?

【问题讨论】:

    标签: python python-3.x tws


    【解决方案1】:

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

    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()  
    

    将返回一个 Fill 对象列表,其中包含所有必要对象的元组,例如 Contract、Order、Execution 和 CommissionReport。

    【讨论】:

      【解决方案2】:

      您应该在https://groups.io/g/insync 询问具体信息我怀疑这里有人使用该库。

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-19
        • 1970-01-01
        • 2017-07-10
        • 1970-01-01
        • 2021-10-01
        • 1970-01-01
        相关资源
        最近更新 更多