栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

下订单后如何在盈透证券(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()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661469.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号