diff --git a/vnpy/trader/gateway/cshshlpGateway/__init__.py b/vnpy/trader/gateway/cshshlpGateway/__init__.py index ff1cd68e..e340ebe5 100644 --- a/vnpy/trader/gateway/cshshlpGateway/__init__.py +++ b/vnpy/trader/gateway/cshshlpGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/ctpGateway/__init__.py b/vnpy/trader/gateway/ctpGateway/__init__.py index 3078d854..8a8d5827 100644 --- a/vnpy/trader/gateway/ctpGateway/__init__.py +++ b/vnpy/trader/gateway/ctpGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/ctpGateway/language/__init__.py b/vnpy/trader/gateway/ctpGateway/language/__init__.py index 2ca0ef80..8f68ed7f 100644 --- a/vnpy/trader/gateway/ctpGateway/language/__init__.py +++ b/vnpy/trader/gateway/ctpGateway/language/__init__.py @@ -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 diff --git a/vnpy/trader/gateway/femasGateway/__init__.py b/vnpy/trader/gateway/femasGateway/__init__.py index 646b363e..e6897beb 100644 --- a/vnpy/trader/gateway/femasGateway/__init__.py +++ b/vnpy/trader/gateway/femasGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/femasGateway/femasGateway.py b/vnpy/trader/gateway/femasGateway/femasGateway.py index c5962a49..88ba3d42 100644 --- a/vnpy/trader/gateway/femasGateway/femasGateway.py +++ b/vnpy/trader/gateway/femasGateway/femasGateway.py @@ -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 diff --git a/vnpy/trader/gateway/futuGateway/__init__.py b/vnpy/trader/gateway/futuGateway/__init__.py index 827c2b6c..3778ebc6 100644 --- a/vnpy/trader/gateway/futuGateway/__init__.py +++ b/vnpy/trader/gateway/futuGateway/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import absolute_import from vnpy.trader import vtConstant from .futuGateway import FutuGateway diff --git a/vnpy/trader/gateway/fxcmGateway/__init__.py b/vnpy/trader/gateway/fxcmGateway/__init__.py index 26e36c12..53254b47 100644 --- a/vnpy/trader/gateway/fxcmGateway/__init__.py +++ b/vnpy/trader/gateway/fxcmGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/fxcmGateway/fxcmGateway.py b/vnpy/trader/gateway/fxcmGateway/fxcmGateway.py index 712b0692..fc5f323f 100644 --- a/vnpy/trader/gateway/fxcmGateway/fxcmGateway.py +++ b/vnpy/trader/gateway/fxcmGateway/fxcmGateway.py @@ -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): diff --git a/vnpy/trader/gateway/huobiGateway/__init__.py b/vnpy/trader/gateway/huobiGateway/__init__.py index b6bb6efe..34044316 100644 --- a/vnpy/trader/gateway/huobiGateway/__init__.py +++ b/vnpy/trader/gateway/huobiGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/huobiGateway/huobiGateway.py b/vnpy/trader/gateway/huobiGateway/huobiGateway.py index b3fc31d4..b84cf580 100644 --- a/vnpy/trader/gateway/huobiGateway/huobiGateway.py +++ b/vnpy/trader/gateway/huobiGateway/huobiGateway.py @@ -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) diff --git a/vnpy/trader/gateway/ibGateway/__init__.py b/vnpy/trader/gateway/ibGateway/__init__.py index c7be4fdd..8d6335a4 100644 --- a/vnpy/trader/gateway/ibGateway/__init__.py +++ b/vnpy/trader/gateway/ibGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/ibGateway/ibGateway.py b/vnpy/trader/gateway/ibGateway/ibGateway.py index 9c6c251e..3f70826b 100644 --- a/vnpy/trader/gateway/ibGateway/ibGateway.py +++ b/vnpy/trader/gateway/ibGateway/ibGateway.py @@ -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): diff --git a/vnpy/trader/gateway/ibGateway/language/__init__.py b/vnpy/trader/gateway/ibGateway/language/__init__.py index 8325ae0c..e9efec4b 100644 --- a/vnpy/trader/gateway/ibGateway/language/__init__.py +++ b/vnpy/trader/gateway/ibGateway/language/__init__.py @@ -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() diff --git a/vnpy/trader/gateway/ksgoldGateway/__init__.py b/vnpy/trader/gateway/ksgoldGateway/__init__.py index b81b6ef3..cc9ef208 100644 --- a/vnpy/trader/gateway/ksgoldGateway/__init__.py +++ b/vnpy/trader/gateway/ksgoldGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/ksotpGateway/__init__.py b/vnpy/trader/gateway/ksotpGateway/__init__.py index cf9c5dbb..d18f121a 100644 --- a/vnpy/trader/gateway/ksotpGateway/__init__.py +++ b/vnpy/trader/gateway/ksotpGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/lbankGateway/__init__.py b/vnpy/trader/gateway/lbankGateway/__init__.py index 4d5d6e00..72ba49d8 100644 --- a/vnpy/trader/gateway/lbankGateway/__init__.py +++ b/vnpy/trader/gateway/lbankGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/lbankGateway/lbankGateway.py b/vnpy/trader/gateway/lbankGateway/lbankGateway.py index 85f82ae3..3cade80e 100644 --- a/vnpy/trader/gateway/lbankGateway/lbankGateway.py +++ b/vnpy/trader/gateway/lbankGateway/lbankGateway.py @@ -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): diff --git a/vnpy/trader/gateway/ltsGateway/__init__.py b/vnpy/trader/gateway/ltsGateway/__init__.py index cbb88696..72306493 100644 --- a/vnpy/trader/gateway/ltsGateway/__init__.py +++ b/vnpy/trader/gateway/ltsGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/ltsGateway/ltsGateway.py b/vnpy/trader/gateway/ltsGateway/ltsGateway.py index 83610ac2..00942059 100644 --- a/vnpy/trader/gateway/ltsGateway/ltsGateway.py +++ b/vnpy/trader/gateway/ltsGateway/ltsGateway.py @@ -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': diff --git a/vnpy/trader/gateway/oandaGateway/__init__.py b/vnpy/trader/gateway/oandaGateway/__init__.py index 0ce2fb0d..7ba3dbdb 100644 --- a/vnpy/trader/gateway/oandaGateway/__init__.py +++ b/vnpy/trader/gateway/oandaGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/qdpGateway/__init__.py b/vnpy/trader/gateway/qdpGateway/__init__.py index 4fb85e9b..2c8b6685 100644 --- a/vnpy/trader/gateway/qdpGateway/__init__.py +++ b/vnpy/trader/gateway/qdpGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/secGateway/__init__.py b/vnpy/trader/gateway/secGateway/__init__.py index c919bb29..ba50b638 100644 --- a/vnpy/trader/gateway/secGateway/__init__.py +++ b/vnpy/trader/gateway/secGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/secGateway/secGateway.py b/vnpy/trader/gateway/secGateway/secGateway.py index 095341b8..a5ff3d01 100644 --- a/vnpy/trader/gateway/secGateway/secGateway.py +++ b/vnpy/trader/gateway/secGateway/secGateway.py @@ -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])) ######################################################################## diff --git a/vnpy/trader/gateway/sgitGateway/__init__.py b/vnpy/trader/gateway/sgitGateway/__init__.py index 2be6983b..52c55412 100644 --- a/vnpy/trader/gateway/sgitGateway/__init__.py +++ b/vnpy/trader/gateway/sgitGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/shzdGateway/__init__.py b/vnpy/trader/gateway/shzdGateway/__init__.py index 7f5d3497..fd10bb58 100644 --- a/vnpy/trader/gateway/shzdGateway/__init__.py +++ b/vnpy/trader/gateway/shzdGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/shzdGateway/shzdGateway.py b/vnpy/trader/gateway/shzdGateway/shzdGateway.py index 3ed9f305..d49ba6b0 100644 --- a/vnpy/trader/gateway/shzdGateway/shzdGateway.py +++ b/vnpy/trader/gateway/shzdGateway/shzdGateway.py @@ -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]) \ No newline at end of file diff --git a/vnpy/trader/gateway/tkproGateway/tkproGateway.py b/vnpy/trader/gateway/tkproGateway/tkproGateway.py index 85d406cc..ddd53e4a 100644 --- a/vnpy/trader/gateway/tkproGateway/tkproGateway.py +++ b/vnpy/trader/gateway/tkproGateway/tkproGateway.py @@ -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)) #---------------------------------------------------------------------- diff --git a/vnpy/trader/gateway/windGateway/__init__.py b/vnpy/trader/gateway/windGateway/__init__.py index f2508aee..fc9949b4 100644 --- a/vnpy/trader/gateway/windGateway/__init__.py +++ b/vnpy/trader/gateway/windGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/windGateway/windGateway.py b/vnpy/trader/gateway/windGateway/windGateway.py index 1a872cdf..e244b6c5 100644 --- a/vnpy/trader/gateway/windGateway/windGateway.py +++ b/vnpy/trader/gateway/windGateway/windGateway.py @@ -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 * diff --git a/vnpy/trader/gateway/xspeedGateway/__init__.py b/vnpy/trader/gateway/xspeedGateway/__init__.py index 50d26714..ee1f848b 100644 --- a/vnpy/trader/gateway/xspeedGateway/__init__.py +++ b/vnpy/trader/gateway/xspeedGateway/__init__.py @@ -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' diff --git a/vnpy/trader/gateway/xtpGateway/__init__.py b/vnpy/trader/gateway/xtpGateway/__init__.py index bd4dfe6d..b9ea0af4 100644 --- a/vnpy/trader/gateway/xtpGateway/__init__.py +++ b/vnpy/trader/gateway/xtpGateway/__init__.py @@ -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'