下订单后如何在盈透证券(IBPY)中获得交易价格和佣金?

下订单后如何在盈透证券(IBPY)中获得交易价格和佣金?,第1张

下订单后如何在盈透证券(IBPY)中获得交易价格佣金
from ib.opt import Connection, messagefrom ib.ext.Contract import Contractfrom ib.ext.Order import Orderfrom ib.ext.CommissionReport import CommissionReportfrom ib.ext.TickType import TickType as tt

使函数可以处理您感兴趣的每种回调类型。

def error_handler(msg):    print (msg)def execDetails(msg):    print('ID',msg.execution.m_execId,'PRICE',msg.execution.m_price)def commReport(msg):    print('ID',msg.commissionReport.m_execId,'COM',msg.commissionReport.m_commission)tws = Connection.create(port = 4001, clientId=123)tws.register(execDetails, message.execDetails)tws.register(commReport, message.commissionReport)tws.register(error_handler, 'Error')tws.connect()

您应该等待

connect()
完成,我通常只在准备就绪时使用nextOrderId回调通知我,但是在python中您可以sleep(2)或在这种情况下,我使用的是笔记本,因此我稍后才运行下一个单元格。

fx = Contract()fx.m_secType = "CASH" fx.m_symbol = "USD"fx.m_currency = "CAD"fx.m_exchange = "IDEALPRO"#tws.reqMktData(1,fx,"",False)ord = Order()ord.m_orderType = 'MKT'ord.m_totalQuantity = 100000ord.m_action = 'SELL'tws.placeOrder(123,fx,ord) #increment this every order

此打印

ID 0001f4e8.57427bd9.01.01 PRICE 1.31565ID 0001f4e8.57427bd9.01.01 COM 2.6313`

别忘

tws.disconnect()



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5663425.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存