diff --git a/vn.trader/ibGateway/ibGateway.py b/vn.trader/ibGateway/ibGateway.py index c7cba073..e9a17ec2 100644 --- a/vn.trader/ibGateway/ibGateway.py +++ b/vn.trader/ibGateway/ibGateway.py @@ -13,7 +13,8 @@ ibpy的gateway接入 import os import json -from datetime import datetime +import calendar +from datetime import datetime, timedelta from copy import copy from PyQt4 import QtGui, QtCore @@ -45,6 +46,7 @@ directionMapReverse['SLD'] = DIRECTION_SHORT # 交易所类型映射 exchangeMap = {} exchangeMap[EXCHANGE_SMART] = 'SMART' +exchangeMap[EXCHANGE_NYMEX] = 'NYMEX' exchangeMap[EXCHANGE_GLOBEX] = 'GLOBEX' exchangeMap[EXCHANGE_IDEALPRO] = 'IDEALPRO' exchangeMapReverse = {v:k for k,v in exchangeMap.items()} @@ -181,7 +183,14 @@ class IbGateway(VtGateway): contract.m_expiry = subscribeReq.expiry contract.m_strike = subscribeReq.strikePrice contract.m_right = optionTypeMap.get(subscribeReq.optionType, '') - + + if contract.m_secType == 'FUT' and not subscribeReq.expiry: + # 期货 如果没有设置过期时间, 默认设置为下个月 + dt_obj = datetime.now() + days = calendar.monthrange(dt_obj.year, dt_obj.month)[1] + nextMonth = dt_obj + timedelta(days=days) + contract.m_expiry = nextMonth.strftime('%Y%m') + self.connection.reqMktData(self.tickerId, contract, '', False) # 获取合约详细信息 diff --git a/vn.trader/uiBasicWidget.py b/vn.trader/uiBasicWidget.py index d1fc75b6..7fe68f35 100644 --- a/vn.trader/uiBasicWidget.py +++ b/vn.trader/uiBasicWidget.py @@ -641,6 +641,7 @@ class TradingWidget(QtGui.QFrame): EXCHANGE_SGE, EXCHANGE_HKEX, EXCHANGE_SMART, + EXCHANGE_NYMEX, EXCHANGE_GLOBEX, EXCHANGE_IDEALPRO] diff --git a/vn.trader/vtConstant.py b/vn.trader/vtConstant.py index 0492cc4b..d8ed868a 100644 --- a/vn.trader/vtConstant.py +++ b/vn.trader/vtConstant.py @@ -64,6 +64,7 @@ EXCHANGE_NONE = '' # 空交易所 EXCHANGE_HKEX = 'HKEX' # 港交所 EXCHANGE_SMART = 'SMART' # IB智能路由(股票、期权) +EXCHANGE_NYMEX = 'NYMEX' # IB 期货 EXCHANGE_GLOBEX = 'GLOBEX' # CME电子交易平台 EXCHANGE_IDEALPRO = 'IDEALPRO' # IB外汇ECN