[英]How can I get a commission of execution in ib_insync TWS
I need to get a commission of execution in TWS. 我需要在交易平台中获得执行佣金。 I connect to them through ib_insync library for python. 我通过ib_insync库连接到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? 我怎样才能抓住他们?
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. 将返回一个Fill对象的列表,其中包含所有必需对象的元组,例如Contract,Order,Execution和CommissionReport。
You should ask specifics at https://groups.io/g/insync I doubt anybody here uses that library. 您应该在https://groups.io/g/insync上询问具体信息。我怀疑这里是否有人使用该库。
Commissions aren't returned in executions, they are returned in commissionReport. 佣金不会在执行中返回,而是在CommissionReport中返回。 http://interactivebrokers.github.io/tws-api/classIBApi_1_1CommissionReport.html 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. 请注意,该ID是执行ID,与匹配佣金报告的执行中的ID相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.