IB 增加期货支持

This commit is contained in:
Bian Jiang 2016-05-05 13:47:49 +08:00
parent 8d73c80919
commit adaf10c96e
3 changed files with 13 additions and 2 deletions

View File

@ -13,7 +13,8 @@ ibpy的gateway接入
import os import os
import json import json
from datetime import datetime import calendar
from datetime import datetime, timedelta
from copy import copy from copy import copy
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
@ -45,6 +46,7 @@ directionMapReverse['SLD'] = DIRECTION_SHORT
# 交易所类型映射 # 交易所类型映射
exchangeMap = {} exchangeMap = {}
exchangeMap[EXCHANGE_SMART] = 'SMART' exchangeMap[EXCHANGE_SMART] = 'SMART'
exchangeMap[EXCHANGE_NYMEX] = 'NYMEX'
exchangeMap[EXCHANGE_GLOBEX] = 'GLOBEX' exchangeMap[EXCHANGE_GLOBEX] = 'GLOBEX'
exchangeMap[EXCHANGE_IDEALPRO] = 'IDEALPRO' exchangeMap[EXCHANGE_IDEALPRO] = 'IDEALPRO'
exchangeMapReverse = {v:k for k,v in exchangeMap.items()} exchangeMapReverse = {v:k for k,v in exchangeMap.items()}
@ -181,7 +183,14 @@ class IbGateway(VtGateway):
contract.m_expiry = subscribeReq.expiry contract.m_expiry = subscribeReq.expiry
contract.m_strike = subscribeReq.strikePrice contract.m_strike = subscribeReq.strikePrice
contract.m_right = optionTypeMap.get(subscribeReq.optionType, '') 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) self.connection.reqMktData(self.tickerId, contract, '', False)
# 获取合约详细信息 # 获取合约详细信息

View File

@ -641,6 +641,7 @@ class TradingWidget(QtGui.QFrame):
EXCHANGE_SGE, EXCHANGE_SGE,
EXCHANGE_HKEX, EXCHANGE_HKEX,
EXCHANGE_SMART, EXCHANGE_SMART,
EXCHANGE_NYMEX,
EXCHANGE_GLOBEX, EXCHANGE_GLOBEX,
EXCHANGE_IDEALPRO] EXCHANGE_IDEALPRO]

View File

@ -64,6 +64,7 @@ EXCHANGE_NONE = '' # 空交易所
EXCHANGE_HKEX = 'HKEX' # 港交所 EXCHANGE_HKEX = 'HKEX' # 港交所
EXCHANGE_SMART = 'SMART' # IB智能路由股票、期权 EXCHANGE_SMART = 'SMART' # IB智能路由股票、期权
EXCHANGE_NYMEX = 'NYMEX' # IB 期货
EXCHANGE_GLOBEX = 'GLOBEX' # CME电子交易平台 EXCHANGE_GLOBEX = 'GLOBEX' # CME电子交易平台
EXCHANGE_IDEALPRO = 'IDEALPRO' # IB外汇ECN EXCHANGE_IDEALPRO = 'IDEALPRO' # IB外汇ECN