From 4cb8baaf5b57f7e2333180e0c747760103856d41 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Sun, 23 Apr 2017 20:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=83=BD=E6=BA=90=E6=89=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/ctpGateway/ctpGateway.py | 20 ++++++++++++++++++-- vn.trader/vtConstant.py | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/vn.trader/ctpGateway/ctpGateway.py b/vn.trader/ctpGateway/ctpGateway.py index 0d05616a..36fcebac 100644 --- a/vn.trader/ctpGateway/ctpGateway.py +++ b/vn.trader/ctpGateway/ctpGateway.py @@ -20,7 +20,6 @@ from datetime import datetime import logging - # 以下为一些VT类型和CTP类型的映射字典 # 价格类型映射 priceTypeMap = {} @@ -53,6 +52,7 @@ exchangeMap[EXCHANGE_SHFE] = 'SHFE' exchangeMap[EXCHANGE_CZCE] = 'CZCE' exchangeMap[EXCHANGE_DCE] = 'DCE' exchangeMap[EXCHANGE_SSE] = 'SSE' +exchangeMap[EXCHANGE_INE] = 'INE' exchangeMap[EXCHANGE_UNKNOWN] = '' exchangeMapReverse = {v:k for k,v in exchangeMap.items()} @@ -63,6 +63,14 @@ posiDirectionMap[DIRECTION_LONG] = defineDict["THOST_FTDC_PD_Long"] posiDirectionMap[DIRECTION_SHORT] = defineDict["THOST_FTDC_PD_Short"] posiDirectionMapReverse = {v:k for k,v in posiDirectionMap.items()} +# 产品类型映射 +productClassMap = {} +productClassMap[PRODUCT_FUTURES] = defineDict["THOST_FTDC_PC_Futures"] +productClassMap[PRODUCT_OPTION] = defineDict["THOST_FTDC_PC_Options"] +productClassMap[PRODUCT_COMBINATION] = defineDict["THOST_FTDC_PC_Combination"] +productClassMapReverse = {v:k for k,v in productClassMap.items()} + + ######################################################################## class CtpGateway(VtGateway): @@ -345,6 +353,10 @@ class CtpMdApi(MdApi): #---------------------------------------------------------------------- def onRtnDepthMarketData(self, data): """行情推送""" + # 忽略成交量为0的无效tick数据 + if not data['Volume']: + return + tick = VtTickData() tick.gatewayName = self.gatewayName @@ -687,7 +699,7 @@ class CtpTdApi(TdApi): def onRspRemoveParkedOrder(self, data, error, n, last): """""" pass - + #---------------------------------------------------------------------- def onRspRemoveParkedOrderAction(self, data, error, n, last): """""" @@ -731,6 +743,10 @@ class CtpTdApi(TdApi): #---------------------------------------------------------------------- def onRspQryInvestorPosition(self, data, error, n, last): """持仓查询回报""" + + if not data['InstrumentID']: + return + # 获取缓存字典中的持仓缓存,若无则创建并初始化 positionName = '.'.join([data['InstrumentID'], data['PosiDirection']]) diff --git a/vn.trader/vtConstant.py b/vn.trader/vtConstant.py index 46f02069..70eff122 100644 --- a/vn.trader/vtConstant.py +++ b/vn.trader/vtConstant.py @@ -71,6 +71,7 @@ EXCHANGE_SGE = 'SGE' # 上金所 EXCHANGE_UNKNOWN = 'UNKNOWN'# 未知交易所 EXCHANGE_NONE = '' # 空交易所 EXCHANGE_HKEX = 'HKEX' # 港交所 +EXCHANGE_INE = 'INE' # 国际能源交易中心 EXCHANGE_SMART = 'SMART' # IB智能路由(股票、期权) EXCHANGE_NYMEX = 'NYMEX' # IB 期货