From e204af935d51de232d0d560aaa1ad4dd5cf07b29 Mon Sep 17 00:00:00 2001 From: Bian Jiang Date: Wed, 4 May 2016 22:00:57 +0800 Subject: [PATCH] =?UTF-8?q?IB=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=90=88?= =?UTF-8?q?=E7=BA=A6=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ibGateway/ibGateway.py | 34 ++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/vn.trader/ibGateway/ibGateway.py b/vn.trader/ibGateway/ibGateway.py index 6e243b74..f0711c78 100644 --- a/vn.trader/ibGateway/ibGateway.py +++ b/vn.trader/ibGateway/ibGateway.py @@ -184,6 +184,9 @@ class IbGateway(VtGateway): self.connection.reqMktData(self.tickerId, contract, '', False) + # 获取合约详细信息 + self.connection.reqContractDetails(self.tickerId, contract) + # 创建Tick对象并保存到字典中 tick = VtTickData() tick.symbol = subscribeReq.symbol @@ -429,17 +432,40 @@ class IbWrapper(EWrapper): #---------------------------------------------------------------------- def contractDetails(self, reqId, contractDetails): - """ generated source for method contractDetails """ - pass + """合约查询回报""" + contract = VtContractData() + contract.gatewayName = self.gatewayName + contract.symbol = contractDetails.m_summary.m_symbol + contract.exchange = contractDetails.m_summary.m_exchange + contract.vtSymbol = '.'.join([contract.symbol, contract.exchange]) + contract.name = contractDetails.m_marketName.decode('UTF-8') + + # 合约类型 + if contractDetails.m_summary.m_secType == 'STK': + contract.productClass = PRODUCT_EQUITY + elif contractDetails.m_summary.m_secType == 'CASH': + contract.productClass = PRODUCT_FOREX + elif contractDetails.m_summary.m_secType == 'FUT': + contract.productClass = PRODUCT_FUTURES + elif contractDetails.m_summary.m_secType == 'OPT': + contract.productClass = PRODUCT_OPTION + else: + contract.productClass = PRODUCT_UNKNOWN + # 推送 + self.gateway.onContract(contract) + #---------------------------------------------------------------------- def bondContractDetails(self, reqId, contractDetails): """ generated source for method bondContractDetails """ #---------------------------------------------------------------------- def contractDetailsEnd(self, reqId): - """ generated source for method contractDetailsEnd """ - pass + """ 获取合约结束 """ + log = VtLogData() + log.gatewayName = self.gatewayName + log.logContent = u'交易合约信息获取完成' + self.gateway.onLog(log) #---------------------------------------------------------------------- def execDetails(self, reqId, contract, execution):