Modernize vnpy/trader/gateway

This commit is contained in:
cclauss 2018-05-14 16:02:15 +02:00
parent 29eb606e1c
commit 314dece44b
31 changed files with 80 additions and 55 deletions

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from cshshlpGateway import CshshlpGateway
from .cshshlpGateway import CshshlpGateway
gatewayClass = CshshlpGateway
gatewayName = 'CSHSHLP'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from ctpGateway import CtpGateway
from .ctpGateway import CtpGateway
gatewayClass = CtpGateway
gatewayName = 'CTP'

View File

@ -1,15 +1,16 @@
# encoding: UTF-8
from __future__ import absolute_import
import json
import os
import traceback
# 默认设置
from chinese import text
from .chinese import text
# 获取全局配置
from vnpy.trader.vtGlobal import globalSetting
# 打开配置文件,读取语言配置
if globalSetting['language'] == 'english':
from english import text
from .english import text

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from femasGateway import FemasGateway
from .femasGateway import FemasGateway
gatewayClass = FemasGateway
gatewayName = 'FEMAS'

View File

@ -5,6 +5,7 @@ vn.femas的gateway接入
考虑到飞马只对接期货目前只有中金所, vtSymbol直接使用symbol
'''
from __future__ import print_function
import os
@ -599,10 +600,10 @@ class FemasTdApi(TdApi):
# 如果登录成功,推送日志信息
if error['ErrorID'] == 0:
for k, v in data.items():
print k, ':', v
print(k, ':', v)
if data['MaxOrderLocalID']:
self.localID = int(data['MaxOrderLocalID']) # 目前最大本地报单号
print 'id now', self.localID
print('id now', self.localID)
self.loginStatus = True
self.gateway.mdConnected = True

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from .futuGateway import FutuGateway

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from fxcmGateway import FxcmGateway
from .fxcmGateway import FxcmGateway
gatewayClass = FxcmGateway
gatewayName = 'FXCM'

View File

@ -1,5 +1,6 @@
# encoding: UTF-8
from __future__ import print_function
import os
import json
from datetime import datetime
@ -434,22 +435,22 @@ class Api(FxcmApi):
#----------------------------------------------------------------------
def onOpenTrade(self, data, reqid):
"""开仓回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onCloseTrade(self, data, reqid):
"""平仓回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onChangeOrder(self, data, reqid):
"""改单回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onDeleteOrder(self, data, reqid):
"""撤单回调"""
print data, reqid
print(data, reqid)
#----------------------------------------------------------------------
def onPriceUpdate(self, data):

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from huobiGateway import HuobiGateway
from .huobiGateway import HuobiGateway
gatewayClass = HuobiGateway
gatewayName = 'HUOBI'

View File

@ -3,8 +3,8 @@
'''
vn.sec的gateway接入
'''
from __future__ import print_function
import os
import json
from datetime import datetime, timedelta
from copy import copy
@ -12,7 +12,7 @@ from math import pow
from vnpy.api.huobi import TradeApi, DataApi
from vnpy.trader.vtGateway import *
from vnpy.trader.vtFunction import getJsonPath, getTempPath
from vnpy.trader.vtFunction import getJsonPath
# 委托状态类型映射
@ -29,11 +29,9 @@ statusMapReverse['canceled'] = STATUS_CANCELLED
#----------------------------------------------------------------------
def print_dict(d):
""""""
print '-' * 30
l = d.keys()
l.sort()
for k in l:
print '%s:%s' %(k, d[k])
print('-' * 30)
for key in sorted(d):
print('%s:%s' % (key, d[key]))
########################################################################
@ -60,7 +58,7 @@ class HuobiGateway(VtGateway):
def connect(self):
"""连接"""
try:
f = file(self.filePath)
f = open(self.filePath)
except IOError:
log = VtLogData()
log.gatewayName = self.gatewayName
@ -294,7 +292,7 @@ class HuobiDataApi(DataApi):
#----------------------------------------------------------------------
def onTradeDetail(self, data):
"""成交细节推送"""
print data
print(data)
#----------------------------------------------------------------------
def onMarketDetail(self, data):
@ -322,7 +320,6 @@ class HuobiDataApi(DataApi):
self.gateway.onTick(tick)
########################################################################
class HuobiTradeApi(TradeApi):
"""交易API实现"""
@ -693,7 +690,7 @@ class HuobiTradeApi(TradeApi):
#----------------------------------------------------------------------
def onGetMatchResult(self, data, reqid):
"""查询单一成交回调"""
print reqid, data
print(reqid, data)
#----------------------------------------------------------------------
def onPlaceOrder(self, data, reqid):
@ -717,4 +714,4 @@ class HuobiTradeApi(TradeApi):
#----------------------------------------------------------------------
def onBatchCancel(self, data, reqid):
"""批量撤单回调"""
print reqid, data
print(reqid, data)

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from ibGateway import IbGateway
from .ibGateway import IbGateway
gatewayClass = IbGateway
gatewayName = 'IB'

View File

@ -10,6 +10,7 @@ Interactive Brokers的gateway接入已经替换为vn.ib封装。
4. 目前只支持股票和期货交易ib api里期权合约的确定是基于Contract对象的多个字段比较复杂暂时没做
5. 海外市场的交易规则和国内有很多细节上的不同所以一些字段类型的映射可能不合理如果发现问题欢迎指出
'''
from __future__ import print_function
import os
import json
@ -375,7 +376,7 @@ class IbWrapper(IbApi):
newtick = copy(tick)
self.gateway.onTick(newtick)
else:
print field
print(field)
#----------------------------------------------------------------------
def tickSize(self, tickerId, field, size):
@ -385,7 +386,7 @@ class IbWrapper(IbApi):
key = tickFieldMap[field]
tick.__setattr__(key, size)
else:
print field
print(field)
#----------------------------------------------------------------------
def tickOptionComputation(self, tickerId, tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice):

View File

@ -1,11 +1,12 @@
# encoding: UTF-8
from __future__ import absolute_import
import json
import os
import traceback
# 默认设置
from chinese import text
from .chinese import text
# 获取目录上级路径
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
@ -14,10 +15,9 @@ SETTING_FILENAME = os.path.join(path, SETTING_FILENAME)
# 打开配置文件,读取语言配置
try:
f = file(SETTING_FILENAME)
setting = json.load(f)
with open(SETTING_FILENAME) as f:
setting = json.load(f)
if setting['language'] == 'english':
from english import text
f.close()
except:
from .english import text
except Exception:
traceback.print_exc()

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from ksgoldGateway import KsgoldGateway
from .ksgoldGateway import KsgoldGateway
gatewayClass = KsgoldGateway
gatewayName = 'KSGOLD'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from ksotpGateway import KsotpGateway
from .ksotpGateway import KsotpGateway
gatewayClass = KsotpGateway
gatewayName = 'KSOTP'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from lbankGateway import LbankGateway
from .lbankGateway import LbankGateway
gatewayClass = LbankGateway
gatewayName = 'LBANK'

View File

@ -3,6 +3,7 @@
'''
vn.lhang的gateway接入
'''
from __future__ import print_function
import os
@ -244,11 +245,11 @@ class LbankApi(LbankApi):
# ----------------------------------------------------------------------
def onGetTrades(self, data, req, reqID):
"""查询历史成交"""
print data, reqID
print(data, reqID)
# ----------------------------------------------------------------------
def onGetKline(self, data, req, reqID):
print data, reqID
print(data, reqID)
# ----------------------------------------------------------------------
def onGetUserInfo(self, data, req, reqID):

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from ltsGateway import LtsGateway
from .ltsGateway import LtsGateway
gatewayClass = LtsGateway
gatewayName = 'LTS'

View File

@ -3,6 +3,7 @@
'''
vn.lts的gateway接入
'''
from __future__ import print_function
import os
import json
@ -980,7 +981,7 @@ class LtsQryApi(QryApi):
elif data['ProductClass'] == '8':
contract.productClass = PRODUCT_EQUITY
else:
print data['ProductClass']
print(data['ProductClass'])
# 期权类型
if data['InstrumentType'] == '1':

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from oandaGateway import OandaGateway
from .oandaGateway import OandaGateway
gatewayClass = OandaGateway
gatewayName = 'OANDA'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from qdpGateway import QdpGateway
from .qdpGateway import QdpGateway
gatewayClass = QdpGateway
gatewayName = 'QDP'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from secGateway import SecGateway
from .secGateway import SecGateway
gatewayClass = SecGateway
gatewayName = 'SEC'

View File

@ -3,6 +3,7 @@
'''
vn.sec的gateway接入
'''
from __future__ import print_function
import os
import json
@ -50,11 +51,11 @@ exchangeMapReverse = {v:k for k,v in exchangeMap.items()}
#----------------------------------------------------------------------
def print_dict(d):
""""""
print '-' * 30
print('-' * 30)
l = d.keys()
l.sort()
for k in l:
print '%s:%s' %(k, d[k])
print('%s:%s' %(k, d[k]))
########################################################################

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from sgitGateway import SgitGateway
from .sgitGateway import SgitGateway
gatewayClass = SgitGateway
gatewayName = 'SGIT'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from shzdGateway import ShzdGateway
from .shzdGateway import ShzdGateway
gatewayClass = ShzdGateway
gatewayName = 'SHZD'

View File

@ -8,6 +8,7 @@ vn.shzd的gateway接入
3. 持仓全部平光后再次查询时会没有该合约的推送和CTP不同为了避免最后平仓
不更新的情况使用缓存机制来处理
'''
from __future__ import print_function
import os
@ -721,9 +722,9 @@ class ShzdGatewayApi(ShzdApi):
#----------------------------------------------------------------------
def printDict(d):
"""打印字典"""
print '-' * 50
print('-' * 50)
l = d.keys()
l.sort()
for k in l:
print k, ':', d[k]
print(k, ':', d[k])

View File

@ -570,7 +570,7 @@ class TkproDataApi(object):
tick.lowerLimit = data['limit_down']
self.gateway.onTick(tick)
except Exception, e:
except Exception as e:
self.writeLog(u'行情更新失败,错误信息:%s' % str(e))
#----------------------------------------------------------------------

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from windGateway import WindGateway
from .windGateway import WindGateway
gatewayClass = WindGateway
gatewayName = 'WIND'

View File

@ -3,6 +3,7 @@
'''
Wind Python API的gateway接入
'''
from __future__ import print_function
from copy import copy
@ -11,7 +12,7 @@ w = None
try:
from WindPy import w
except ImportError:
print u'请先安装WindPy接口'
print(u'请先安装WindPy接口')
from vnpy.trader.vtGateway import *

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from xspeedGateway import XspeedGateway
from .xspeedGateway import XspeedGateway
gatewayClass = XspeedGateway
gatewayName = 'XSPEED'

View File

@ -1,7 +1,8 @@
# encoding: UTF-8
from __future__ import absolute_import
from vnpy.trader import vtConstant
from xtpGateway import XtpGateway
from .xtpGateway import XtpGateway
gatewayClass = XtpGateway
gatewayName = 'XTP'