From b4ccfdc3780623267796d1e00c304a0c2a1ce493 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 14 May 2018 16:30:28 +0200 Subject: [PATCH 1/4] Modernize vnpy/api/c* and vnpy/api/f* --- vnpy/api/cshshlp/__init__.py | 3 +- vnpy/api/cshshlp/test/cstest.py | 73 ++++++++++--------- vnpy/api/ctp/__init__.py | 7 +- .../ctp/py3/pyscript/generate_data_type.py | 5 +- .../ctp/py3/pyscript/generate_td_functions.py | 3 +- vnpy/api/ctp/pyscript/generate_data_type.py | 5 +- .../api/ctp/pyscript/generate_td_functions.py | 5 +- vnpy/api/ctp/vnctpmd/test/mdtest.py | 11 +-- vnpy/api/ctp/vnctptd/test/tdtest.py | 15 ++-- vnpy/api/femas/__init__.py | 7 +- vnpy/api/femas/pyscript/generate_data_type.py | 5 +- vnpy/api/femas/vnfemasmd/test/mdtest.py | 11 +-- vnpy/api/femas/vnfemastd/test/tdtest.py | 15 ++-- vnpy/api/fxcm/__init__.py | 3 +- vnpy/api/fxcm/test.py | 8 +- vnpy/api/fxcm/vnfxcm.py | 39 +++++----- 16 files changed, 116 insertions(+), 99 deletions(-) diff --git a/vnpy/api/cshshlp/__init__.py b/vnpy/api/cshshlp/__init__.py index e1ff327f..abf415a1 100644 --- a/vnpy/api/cshshlp/__init__.py +++ b/vnpy/api/cshshlp/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vncshshlp import CsHsHlp \ No newline at end of file +from __future__ import absolute_import +from .vncshshlp import CsHsHlp \ No newline at end of file diff --git a/vnpy/api/cshshlp/test/cstest.py b/vnpy/api/cshshlp/test/cstest.py index 801a1a29..f78a9566 100644 --- a/vnpy/api/cshshlp/test/cstest.py +++ b/vnpy/api/cshshlp/test/cstest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -14,21 +15,21 @@ branch_no = '' def print_list(l): """""" for d in l: - print d + print(d) #---------------------------------------------------------------------- def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print '-' * 20 - print str(func.__name__) + print('-' * 20) + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -59,18 +60,18 @@ class TestHlp(CsHsHlp): @simple_log def onMsg(self, type_, data, reqNo, errorNo, errorInfo): """""" - print 'type:', type_ + print('type:', type_) # print_list(data) - print 'reqNo:', reqNo - print 'errorNo:', errorNo - print 'errorInfo:', errorInfo + print('reqNo:', reqNo) + print('errorNo:', errorNo) + print('errorInfo:', errorInfo) ''' for i in data[0].keys(): print "key=%s,value=%s"%(i,data[0][i]) ''' for dd in data: - print dd + print(dd) self.data = data @@ -101,23 +102,23 @@ class TestHlp(CsHsHlp): ''' i = self.loadConfig("Hsconfig.ini") if i: - print u'加载配置失败:', i + print(u'加载配置失败:', i) return i - print u'加载配置成功' + print(u'加载配置成功') # 初始化 i = self.init() if i: - print u'初始化失败:', i + print(u'初始化失败:', i) return i - print u'初始化成功' + print(u'初始化成功') # 连接服务器 i = self.connectServer() if i: - print u'服务器连接失败:', i + print(u'服务器连接失败:', i) return i - print u'服务器连接成功' + print(u'服务器连接成功') return int(0) @@ -135,10 +136,10 @@ def test(): # 初始化端口 i = api.init_api() if i: - print u'初始化端口失败,请检查clog文件', i + print(u'初始化端口失败,请检查clog文件', i) return # 登录 - print u'尝试登录' + print(u'尝试登录') i = api.beginParam() api.setValue("identity_type", "2") api.setValue("password_type", "2") @@ -150,7 +151,7 @@ def test(): api.setValue('option_fund_account', account['id']) api.setValue('op_station', '') i = api.bizCallAndCommit(331100) - print u'尝试登录返回', i + print(u'尝试登录返回', i) sleep(3) #--------------------------------------------------------- # 配置self的变量 @@ -170,34 +171,34 @@ def test(): api.request_num = '500' api.op_station = '' else: - print 'error in set the value' + print('error in set the value') #------------------------------------------ # 订阅 620001 成交回报 33011 # 订阅 620001 委托回写 33012 # api.setNessaryParam() - print u'订阅 33011' + print(u'订阅 33011') api.beginParam() acc_info = '~' .join([api.branch_no, api.fund_account]) api.setValue('issue_type', "33011") api.setValue('acc_info', acc_info) i = api.subscribeData(620001) - print i + print(i) sleep(1) - print u'订阅 33012' + print(u'订阅 33012') api.beginParam() acc_info = '~' .join([api.branch_no, api.fund_account]) api.setValue('issue_type', "33012") api.setValue('acc_info', acc_info) i = api.subscribeData(620001) - print i + print(i) sleep(1) - print u'配置参数,进行下单' + print(u'配置参数,进行下单') # 配置 api.setNessaryParam() # 下单参数 338011 @@ -211,22 +212,22 @@ def test(): api.setValue('entrust_prop', '0') api.setValue('covered_flag', '') i = api.bizCallAndCommit(338011) - print u'尝试下单返回', i + print(u'尝试下单返回', i) sleep(3) - print u'查询持仓' + print(u'查询持仓') # 查询持仓 # api.beginParam() api.setNessaryParam() i = api.bizCallAndCommit(338023) sleep(3) - print u'查询持仓返回',i + print(u'查询持仓返回',i) if(len(api.data)): for dd in api.data: - print "-----------------------" + print("-----------------------") for i in dd.keys(): - print "key=%s,value=%s"%(i,api.data[0][i]) + print("key=%s,value=%s"%(i,api.data[0][i])) # -------------------------------------------------------------------------- # 测试撤单 338012,先下单,间隔后撤单 @@ -241,7 +242,7 @@ def test(): api.setValue('entrust_prop', '0') api.setValue('covered_flag', '') i = api.bizCallAndCommit(338011) - print u'尝试下单返回', i + print(u'尝试下单返回', i) sleep(3) # print api.data @@ -251,16 +252,16 @@ def test(): e_no = tt['entrust_no'] api.order[e_no] = tt - print api.order + print(api.order) api.setNessaryParam() api.setValue('exchange_type','1') for kk in api.order.keys(): api.setValue('entrust_no', kk) i = api.bizCallAndCommit(338012) - print u'尝试撤单', kk + print(u'尝试撤单', kk) sleep(1) #pop or del - print api.data + print(api.data) #----------------------------------- @@ -271,15 +272,15 @@ def test(): api.setValue('locate_entrust_no', kk) i = api.bizCallAndCommit(338020) - print u'查询指定订单', kk + print(u'查询指定订单', kk) sleep(1) - print api.data + print(api.data) api.setNessaryParam() api.setValue('query_kind', '1') i = api.bizCallAndCommit(338020) sleep(1) - print api.data + print(api.data) diff --git a/vnpy/api/ctp/__init__.py b/vnpy/api/ctp/__init__.py index a6e551c0..d22b7b55 100644 --- a/vnpy/api/ctp/__init__.py +++ b/vnpy/api/ctp/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnctpmd import MdApi -from vnctptd import TdApi -from ctp_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnctpmd import MdApi +from .vnctptd import TdApi +from .ctp_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/ctp/py3/pyscript/generate_data_type.py b/vnpy/api/ctp/py3/pyscript/generate_data_type.py index df13ec83..ea339b81 100644 --- a/vnpy/api/ctp/py3/pyscript/generate_data_type.py +++ b/vnpy/api/ctp/py3/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -92,9 +93,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/ctp/py3/pyscript/generate_td_functions.py b/vnpy/api/ctp/py3/pyscript/generate_td_functions.py index 220d0fa9..10aa3c2f 100644 --- a/vnpy/api/ctp/py3/pyscript/generate_td_functions.py +++ b/vnpy/api/ctp/py3/pyscript/generate_td_functions.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from ctp_struct import structDict @@ -257,7 +258,7 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList): ffunction.write(line) if type_ == 'CThostFtdcInputOrderField': - print(key, value) + print((key, value)) print(line) ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n') diff --git a/vnpy/api/ctp/pyscript/generate_data_type.py b/vnpy/api/ctp/pyscript/generate_data_type.py index df13ec83..ea339b81 100644 --- a/vnpy/api/ctp/pyscript/generate_data_type.py +++ b/vnpy/api/ctp/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -92,9 +93,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/ctp/pyscript/generate_td_functions.py b/vnpy/api/ctp/pyscript/generate_td_functions.py index 48af5fb2..506f409d 100644 --- a/vnpy/api/ctp/pyscript/generate_td_functions.py +++ b/vnpy/api/ctp/pyscript/generate_td_functions.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from string import join @@ -250,8 +251,8 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList): ffunction.write(line) if type_ == 'CThostFtdcInputOrderField': - print key, value - print line + print(key, value) + print(line) ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n') ffunction.write('\treturn i;\n') diff --git a/vnpy/api/ctp/vnctpmd/test/mdtest.py b/vnpy/api/ctp/vnctpmd/test/mdtest.py index 4b288ac5..fd7c9e0d 100644 --- a/vnpy/api/ctp/vnctpmd/test/mdtest.py +++ b/vnpy/api/ctp/vnctpmd/test/mdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from vnctpmd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,13 +45,13 @@ class TestMdApi(MdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log diff --git a/vnpy/api/ctp/vnctptd/test/tdtest.py b/vnpy/api/ctp/vnctptd/test/tdtest.py index 5774c25c..aea38856 100644 --- a/vnpy/api/ctp/vnctptd/test/tdtest.py +++ b/vnpy/api/ctp/vnctptd/test/tdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -11,15 +12,15 @@ from vnctptd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -43,13 +44,13 @@ class TestTdApi(TdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log @@ -95,8 +96,8 @@ class TestTdApi(TdApi): """查询合约回报""" print_dict(data) print_dict(error) - print n - print last + print(n) + print(last) #---------------------------------------------------------------------- diff --git a/vnpy/api/femas/__init__.py b/vnpy/api/femas/__init__.py index 29825585..4932856b 100644 --- a/vnpy/api/femas/__init__.py +++ b/vnpy/api/femas/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnfemasmd import MdApi -from vnfemastd import TdApi -from femas_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnfemasmd import MdApi +from .vnfemastd import TdApi +from .femas_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/femas/pyscript/generate_data_type.py b/vnpy/api/femas/pyscript/generate_data_type.py index 9095440e..47073bb2 100644 --- a/vnpy/api/femas/pyscript/generate_data_type.py +++ b/vnpy/api/femas/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -88,9 +89,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/femas/vnfemasmd/test/mdtest.py b/vnpy/api/femas/vnfemasmd/test/mdtest.py index b42f6912..2423df53 100644 --- a/vnpy/api/femas/vnfemasmd/test/mdtest.py +++ b/vnpy/api/femas/vnfemasmd/test/mdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from vnfemasmd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,13 +45,13 @@ class TestMdApi(MdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log diff --git a/vnpy/api/femas/vnfemastd/test/tdtest.py b/vnpy/api/femas/vnfemastd/test/tdtest.py index 3cc3f0a1..d4d3dbcf 100644 --- a/vnpy/api/femas/vnfemastd/test/tdtest.py +++ b/vnpy/api/femas/vnfemastd/test/tdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -11,15 +12,15 @@ from vnfemastd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -43,13 +44,13 @@ class TestTdApi(TdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log @@ -95,8 +96,8 @@ class TestTdApi(TdApi): """查询合约回报""" print_dict(data) print_dict(error) - print n - print last + print(n) + print(last) #---------------------------------------------------------------------- diff --git a/vnpy/api/fxcm/__init__.py b/vnpy/api/fxcm/__init__.py index 824509ee..2ac2bcd7 100644 --- a/vnpy/api/fxcm/__init__.py +++ b/vnpy/api/fxcm/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnfxcm import FxcmApi \ No newline at end of file +from __future__ import absolute_import +from .vnfxcm import FxcmApi \ No newline at end of file diff --git a/vnpy/api/fxcm/test.py b/vnpy/api/fxcm/test.py index 3c67d4db..5a1146e2 100644 --- a/vnpy/api/fxcm/test.py +++ b/vnpy/api/fxcm/test.py @@ -1,8 +1,10 @@ # encoding: UTF-8 +from __future__ import print_function +from __future__ import absolute_import from time import sleep -from vnfxcm import FxcmApi +from .vnfxcm import FxcmApi url = 'https://api-demo.fxcm.com:443' port = 443 @@ -10,10 +12,10 @@ token = '48055b5d9afac0a300143ac067ce04cd2430a434' proxy = 'https://localhost:1080' api = FxcmApi() -print 'api created' +print('api created') api.connect(url, port, token, proxy) -print api.bearer +print(api.bearer) sleep(20) #api.getInstruments() diff --git a/vnpy/api/fxcm/vnfxcm.py b/vnpy/api/fxcm/vnfxcm.py index dc5f6146..37546c95 100644 --- a/vnpy/api/fxcm/vnfxcm.py +++ b/vnpy/api/fxcm/vnfxcm.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import json import requests from socketIO_client import SocketIO @@ -334,32 +335,32 @@ class FxcmApi(object): #---------------------------------------------------------------------- def onConnect(self): """连接回调""" - print 'onConnect' + print('onConnect') #---------------------------------------------------------------------- def onDisconnect(self): """断开回调""" - print 'onClose' + print('onClose') #---------------------------------------------------------------------- def onError(self, error, reqid): """错误回调""" - print 'onError', error + print('onError', error) #---------------------------------------------------------------------- def onGetInstruments(self, data, reqid): """查询合约代码回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- def onGetModel(self, data, reqid): """查询表回调""" - print '*' * 30 - print data + print('*' * 30) + print(data) for d in data['offers']: #if str(d['currency']) == 'EUR/USD': # print d - print d['currency']#, d['visible'] + print(d['currency'])#, d['visible'] #print len(data['summary']) #print data @@ -367,47 +368,47 @@ class FxcmApi(object): #---------------------------------------------------------------------- def onSubscribe(self, data, reqid): """订阅行情回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- def onUnsubscribe(self, data, reqid): """退订行情回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- def onSubscribeModel(self, data, reqid): """订阅表回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- def onUnsubscribeModel(self, data, reqid): """退订表回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- def onUpdateSubscriptions(self, data, reqid): """订阅报价表回调""" - print data, reqid + print(data, reqid) #---------------------------------------------------------------------- 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 processPriceUpdate(self, msg): @@ -418,19 +419,19 @@ class FxcmApi(object): #---------------------------------------------------------------------- def processModelUpdate(self, msg): """表推送""" - print msg + print(msg) data = json.loads(msg) self.onModelUpdate(data) #---------------------------------------------------------------------- def onPriceUpdate(self, data): """行情推送""" - print data + print(data) #---------------------------------------------------------------------- def onModelUpdate(self, data): """表推送""" - print data + print(data) #print '*' * 30 #fsubscribeModel #print len(data), data.get('isTotal', None), data From 7e224ba5af86fa7febe7dd5d9c662942e4efa960 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 May 2018 08:40:02 +0200 Subject: [PATCH 2/4] Modernize vnpy/api/k* --- vnpy/api/ksgold/__init__.py | 5 +++-- vnpy/api/ksgold/pyscript/generate_data_type.py | 13 +++++++------ vnpy/api/ksgold/pyscript/generate_struct.py | 3 ++- vnpy/api/ksotp/__init__.py | 7 ++++--- vnpy/api/ksotp/pyscript/generate_data_type.py | 5 +++-- vnpy/api/ksotp/pyscript/generate_struct.py | 7 ++++--- vnpy/api/ksotp/vnksotpmd/test/mdtest.py | 9 +++++---- vnpy/api/ksotp/vnksotptd/test/tdtest.py | 13 +++++++------ 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/vnpy/api/ksgold/__init__.py b/vnpy/api/ksgold/__init__.py index c57e3924..a7a7a59e 100644 --- a/vnpy/api/ksgold/__init__.py +++ b/vnpy/api/ksgold/__init__.py @@ -1,4 +1,5 @@ # encoding: UTF-8 -from vnksgoldtd import TdApi -from ksgold_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnksgoldtd import TdApi +from .ksgold_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/ksgold/pyscript/generate_data_type.py b/vnpy/api/ksgold/pyscript/generate_data_type.py index 477d5288..e833bad2 100644 --- a/vnpy/api/ksgold/pyscript/generate_data_type.py +++ b/vnpy/api/ksgold/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -48,7 +49,7 @@ def process_typedef(line): else: keyword = content[-1] keyword = keyword.replace(';\n', '') - print content, keyword + print(content, keyword) if '[' in keyword: i = keyword.index('[') @@ -91,15 +92,15 @@ def main(): py_line = process_line(line) if py_line: fpy.write(py_line.decode('gbk').encode('utf-8')) - print n + print(n) fcpp.close() fpy.close() - print u'data_type.py生成过程完成' - except Exception, e: - print u'data_type.py生成过程出错' - print e + print(u'data_type.py生成过程完成') + except Exception as e: + print(u'data_type.py生成过程出错') + print(e) if __name__ == '__main__': diff --git a/vnpy/api/ksgold/pyscript/generate_struct.py b/vnpy/api/ksgold/pyscript/generate_struct.py index df86652b..60f9662b 100644 --- a/vnpy/api/ksgold/pyscript/generate_struct.py +++ b/vnpy/api/ksgold/pyscript/generate_struct.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from ksgold_data_type import * @@ -47,7 +48,7 @@ def main(): n = line.index('//') line = line[:n] - print no, ':', line + print(no, ':', line) content = line.split('\t') diff --git a/vnpy/api/ksotp/__init__.py b/vnpy/api/ksotp/__init__.py index c4295cbe..d2d3e92f 100644 --- a/vnpy/api/ksotp/__init__.py +++ b/vnpy/api/ksotp/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnksotpmd import MdApi -from vnksotptd import TdApi -from ksotp_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnksotpmd import MdApi +from .vnksotptd import TdApi +from .ksotp_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/ksotp/pyscript/generate_data_type.py b/vnpy/api/ksotp/pyscript/generate_data_type.py index 58fb009d..a34f38a8 100644 --- a/vnpy/api/ksotp/pyscript/generate_data_type.py +++ b/vnpy/api/ksotp/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -88,9 +89,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/ksotp/pyscript/generate_struct.py b/vnpy/api/ksotp/pyscript/generate_struct.py index 1e71da16..4018e530 100644 --- a/vnpy/api/ksotp/pyscript/generate_struct.py +++ b/vnpy/api/ksotp/pyscript/generate_struct.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from ksotp_data_type import * @@ -15,7 +16,7 @@ def main(): fpy.write('\n') for n, line in enumerate(fcpp): - print n + print(n) # 结构体申明注释 if '///' in line and '\t' not in line: py_line = '#' + line[3:] @@ -38,8 +39,8 @@ def main(): try: type_ = typedefDict[typedef] except KeyError: - print content - print typedef + print(content) + print(typedef) variable = content[2].replace(';\n', "") py_line = '%s["%s"] = "%s"\n' % (name, variable, type_) diff --git a/vnpy/api/ksotp/vnksotpmd/test/mdtest.py b/vnpy/api/ksotp/vnksotpmd/test/mdtest.py index 81f3cea0..d071b51d 100644 --- a/vnpy/api/ksotp/vnksotpmd/test/mdtest.py +++ b/vnpy/api/ksotp/vnksotpmd/test/mdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from vnksotpmd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,7 +45,7 @@ class TestMdApi(MdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log diff --git a/vnpy/api/ksotp/vnksotptd/test/tdtest.py b/vnpy/api/ksotp/vnksotptd/test/tdtest.py index 7a06c057..e2cb98ef 100644 --- a/vnpy/api/ksotp/vnksotptd/test/tdtest.py +++ b/vnpy/api/ksotp/vnksotptd/test/tdtest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import sys from time import sleep @@ -11,15 +12,15 @@ from vnksotptd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -43,7 +44,7 @@ class TestTdApi(TdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log @@ -89,8 +90,8 @@ class TestTdApi(TdApi): """查询合约回报""" print_dict(data) print_dict(error) - print n - print last + print(n) + print(last) #---------------------------------------------------------------------- From e58a71c79bee3a79d08fdb5da3309aef69d88d2a Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 May 2018 08:49:28 +0200 Subject: [PATCH 3/4] Modernize vnpy/api/l* --- vnpy/api/lbank/__init__.py | 3 ++- vnpy/api/lbank/test.py | 7 ++++-- vnpy/api/lbank/vnlbank.py | 23 ++++++++++--------- vnpy/api/lts/__init__.py | 9 ++++---- vnpy/api/lts/pyscript/generate_data_type.py | 5 ++-- .../api/lts/pyscript/l2/generate_data_type.py | 5 ++-- vnpy/api/lts/vnltsmd/test/mdtest.py | 13 ++++++----- vnpy/api/lts/vnltsqry/test/qrytest.py | 11 +++++---- vnpy/api/lts/vnltstd/test/tdtest.py | 11 +++++---- 9 files changed, 49 insertions(+), 38 deletions(-) diff --git a/vnpy/api/lbank/__init__.py b/vnpy/api/lbank/__init__.py index e16e0806..2e68766f 100644 --- a/vnpy/api/lbank/__init__.py +++ b/vnpy/api/lbank/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnlbank import LbankApi \ No newline at end of file +from __future__ import absolute_import +from .vnlbank import LbankApi \ No newline at end of file diff --git a/vnpy/api/lbank/test.py b/vnpy/api/lbank/test.py index 540e7476..463830e1 100644 --- a/vnpy/api/lbank/test.py +++ b/vnpy/api/lbank/test.py @@ -1,8 +1,11 @@ # encoding: utf-8 +from __future__ import absolute_import from time import time, sleep -from vnlbank import LbankApi +from six.moves import input + +from .vnlbank import LbankApi if __name__ == '__main__': @@ -44,4 +47,4 @@ if __name__ == '__main__': #api.getOrdersInfoHistory('btc_cny', '0', '1', '100') # 阻塞 - raw_input() + input() diff --git a/vnpy/api/lbank/vnlbank.py b/vnpy/api/lbank/vnlbank.py index 2c3fd5e4..d0f9158a 100644 --- a/vnpy/api/lbank/vnlbank.py +++ b/vnpy/api/lbank/vnlbank.py @@ -1,5 +1,6 @@ # encoding: utf-8 +from __future__ import print_function import urllib import hashlib @@ -120,7 +121,7 @@ class LbankApi(object): # 请求成功 else: if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data, req, reqID) # 流控等待 @@ -149,7 +150,7 @@ class LbankApi(object): #---------------------------------------------------------------------- def onError(self, error, req, reqID): """错误推送""" - print error, req, reqID + print(error, req, reqID) ############################################### # 行情接口 @@ -203,22 +204,22 @@ class LbankApi(object): #---------------------------------------------------------------------- def onGetTicker(self, data, req, reqID): """查询行情回调""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onGetDepth(self, data, req, reqID): """查询深度回调""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onGetTrades(self, data, req, reqID): """查询历史成交""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onGetKline(self, data, req, reqID): """查询K线回报""" - print data, reqID + print(data, reqID) ############################################### # 交易接口 @@ -283,25 +284,25 @@ class LbankApi(object): # ---------------------------------------------------------------------- def onGetUserInfo(self, data, req, reqID): """查询账户信息""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onCreateOrder(self, data, req, reqID): """委托回报""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onCancelOrder(self, data, req, reqID): """撤单回报""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onGetOrdersInfo(self, data, req, reqID): """查询委托回报""" - print data, reqID + print(data, reqID) # ---------------------------------------------------------------------- def onGetOrdersInfoHistory(self, data, req, reqID): """撤单回报""" - print data, reqID + print(data, reqID) diff --git a/vnpy/api/lts/__init__.py b/vnpy/api/lts/__init__.py index ab48b274..d0b48b16 100644 --- a/vnpy/api/lts/__init__.py +++ b/vnpy/api/lts/__init__.py @@ -1,6 +1,7 @@ # encoding: UTF-8 -from vnltsmd import MdApi -from vnltstd import TdApi -from vnltsqry import QryApi -from lts_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnltsmd import MdApi +from .vnltstd import TdApi +from .vnltsqry import QryApi +from .lts_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/lts/pyscript/generate_data_type.py b/vnpy/api/lts/pyscript/generate_data_type.py index 79a88eb0..51c6692c 100644 --- a/vnpy/api/lts/pyscript/generate_data_type.py +++ b/vnpy/api/lts/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -88,9 +89,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/lts/pyscript/l2/generate_data_type.py b/vnpy/api/lts/pyscript/l2/generate_data_type.py index 64374ff3..729b58d3 100644 --- a/vnpy/api/lts/pyscript/l2/generate_data_type.py +++ b/vnpy/api/lts/pyscript/l2/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -88,9 +89,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/lts/vnltsmd/test/mdtest.py b/vnpy/api/lts/vnltsmd/test/mdtest.py index 2b551348..72e22754 100644 --- a/vnpy/api/lts/vnltsmd/test/mdtest.py +++ b/vnpy/api/lts/vnltsmd/test/mdtest.py @@ -1,6 +1,7 @@ # encoding: UTF-8 # 内置模块 +from __future__ import print_function import sys from time import sleep @@ -11,15 +12,15 @@ from vnltsmd import * def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -43,13 +44,13 @@ class TestMdApi(MdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log @@ -124,7 +125,7 @@ def main(): #获取交易日,测试通过 day = api.getTradingDay() - print 'Trading Day is:' + str(day) + print('Trading Day is:' + str(day)) sleep(0.5) # 订阅合约,测试通过 diff --git a/vnpy/api/lts/vnltsqry/test/qrytest.py b/vnpy/api/lts/vnltsqry/test/qrytest.py index fd21877a..17ace694 100644 --- a/vnpy/api/lts/vnltsqry/test/qrytest.py +++ b/vnpy/api/lts/vnltsqry/test/qrytest.py @@ -1,6 +1,7 @@ # encoding: UTF-8 # 内置模块 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from lts_data_type import defineDict def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,13 +45,13 @@ class TestQryApi(QryApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log diff --git a/vnpy/api/lts/vnltstd/test/tdtest.py b/vnpy/api/lts/vnltstd/test/tdtest.py index 2c375f0e..ebb64317 100644 --- a/vnpy/api/lts/vnltstd/test/tdtest.py +++ b/vnpy/api/lts/vnltstd/test/tdtest.py @@ -1,6 +1,7 @@ # encoding: UTF-8 # 内置模块 +from __future__ import print_function import sys from time import sleep @@ -12,15 +13,15 @@ from lts_data_type import defineDict def print_dict(d): """按照键值打印一个字典""" for key,value in d.items(): - print key + ':' + str(value) + print(key + ':' + str(value)) #---------------------------------------------------------------------- def simple_log(func): """简单装饰器用于输出函数名""" def wrapper(*args, **kw): - print "" - print str(func.__name__) + print("") + print(str(func.__name__)) return func(*args, **kw) return wrapper @@ -44,13 +45,13 @@ class TestTdApi(TdApi): @simple_log def onFrontDisconnected(self, n): """服务器断开""" - print n + print(n) #---------------------------------------------------------------------- @simple_log def onHeartBeatWarning(self, n): """心跳报警""" - print n + print(n) #---------------------------------------------------------------------- @simple_log From 4c97f408b528b0a89c675a55f42e15ee7c3045e7 Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 May 2018 09:28:42 +0200 Subject: [PATCH 4/4] Modernize vnpy/api/o* and q* --- vnpy/api/oanda/__init__.py | 3 +- vnpy/api/oanda/test.py | 3 +- vnpy/api/oanda/vnoanda.py | 75 ++++++++++--------- vnpy/api/qdp/__init__.py | 7 +- vnpy/api/qdp/pyscript/generate_data_type.py | 5 +- .../api/qdp/pyscript/generate_td_functions.py | 5 +- 6 files changed, 52 insertions(+), 46 deletions(-) diff --git a/vnpy/api/oanda/__init__.py b/vnpy/api/oanda/__init__.py index 90ac6727..68530d94 100644 --- a/vnpy/api/oanda/__init__.py +++ b/vnpy/api/oanda/__init__.py @@ -1,3 +1,4 @@ # encoding: UTF-8 -from vnoanda import OandaApi \ No newline at end of file +from __future__ import absolute_import +from .vnoanda import OandaApi \ No newline at end of file diff --git a/vnpy/api/oanda/test.py b/vnpy/api/oanda/test.py index eb3fdb88..11e721c4 100644 --- a/vnpy/api/oanda/test.py +++ b/vnpy/api/oanda/test.py @@ -1,6 +1,7 @@ # encoding: utf-8 -from vnoanda import OandaApi +from __future__ import absolute_import +from .vnoanda import OandaApi if __name__ == '__main__': diff --git a/vnpy/api/oanda/vnoanda.py b/vnpy/api/oanda/vnoanda.py index 1bdfeef3..2f5f63fb 100644 --- a/vnpy/api/oanda/vnoanda.py +++ b/vnpy/api/oanda/vnoanda.py @@ -1,5 +1,6 @@ # encoding: utf-8 +from __future__ import print_function import json import requests from Queue import Queue, Empty @@ -208,7 +209,7 @@ class OandaApi(object): try: r = self.session.send(pre, stream=stream) - except Exception, e: + except Exception as e: error = e return r, error @@ -228,9 +229,9 @@ class OandaApi(object): try: data = r.json() if self.DEBUG: - print callback.__name__ + print(callback.__name__) callback(data, reqID) - except Exception, e: + except Exception as e: self.onError(str(e), reqID) else: self.onError(error, reqID) @@ -260,7 +261,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onError(self, error, reqID): """错误信息回调""" - print error, reqID + print(error, reqID) #---------------------------------------------------------------------- def getInstruments(self, params): @@ -270,7 +271,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetInstruments(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getPrices(self, params): @@ -280,7 +281,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetPrices(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getPriceHisory(self, params): @@ -290,7 +291,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetPriceHistory(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getAccounts(self): @@ -300,7 +301,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetAccounts(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getAccountInfo(self): @@ -310,7 +311,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetAccountInfo(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getOrders(self, params): @@ -320,7 +321,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetOrders(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def sendOrder(self, params): @@ -330,7 +331,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onSendOrder(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getOrderInfo(self, optional): @@ -340,7 +341,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetOrderInfo(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def modifyOrder(self, params, optional): @@ -350,7 +351,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onModifyOrder(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def cancelOrder(self, optional): @@ -360,7 +361,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onCancelOrder(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getTrades(self, params): @@ -370,7 +371,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetTrades(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getTradeInfo(self, optional): @@ -380,7 +381,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetTradeInfo(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def modifyTrade(self, params, optional): @@ -390,7 +391,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onModifyTrade(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def closeTrade(self, optional): @@ -400,7 +401,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onCloseTrade(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getPositions(self): @@ -410,7 +411,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetPositions(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getPositionInfo(self, optional): @@ -420,7 +421,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetPositionInfo(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def closePosition(self, optional): @@ -430,7 +431,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onClosePosition(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- @@ -441,7 +442,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetTransactions(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getTransactionInfo(self, optional): @@ -451,7 +452,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetTransactionInfo(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getAccountHistory(self): @@ -461,7 +462,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetAccountHistory(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getCalendar(self, params): @@ -471,7 +472,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetCalendar(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getPositionRatios(self, params): @@ -481,7 +482,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetPositionRatios(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getSpreads(self, params): @@ -491,7 +492,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetSpreads(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getCommitments(self, params): @@ -501,7 +502,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetCommitments(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getOrderbook(self, params): @@ -511,7 +512,7 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetOrderbook(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def getAutochartist(self, params): @@ -521,17 +522,17 @@ class OandaApi(object): #---------------------------------------------------------------------- def onGetAutochartist(self, data, reqID): """回调函数""" - print data, reqID + print(data, reqID) #---------------------------------------------------------------------- def onPrice(self, data): """行情推送""" - print data + print(data) #---------------------------------------------------------------------- def onEvent(self, data): """事件推送(成交等)""" - print data + print(data) #---------------------------------------------------------------------- def processStreamPrices(self): @@ -546,7 +547,7 @@ class OandaApi(object): try: data = r.json() symbols = [d['instrument'] for d in data['instruments']] - except Exception, e: + except Exception as e: self.onError(e, -1) return else: @@ -570,10 +571,10 @@ class OandaApi(object): msg = json.loads(line) if self.DEBUG: - print self.onPrice.__name__ + print(self.onPrice.__name__) self.onPrice(msg) - except Exception, e: + except Exception as e: self.onError(e, -1) if not self.active: @@ -597,10 +598,10 @@ class OandaApi(object): msg = json.loads(line) if self.DEBUG: - print self.onEvent.__name__ + print(self.onEvent.__name__) self.onEvent(msg) - except Exception, e: + except Exception as e: self.onError(e, -1) if not self.active: diff --git a/vnpy/api/qdp/__init__.py b/vnpy/api/qdp/__init__.py index 71eb926c..c52b48a3 100644 --- a/vnpy/api/qdp/__init__.py +++ b/vnpy/api/qdp/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnqdpmd import MdApi -from vnqdptd import TdApi -from qdp_data_type import defineDict \ No newline at end of file +from __future__ import absolute_import +from .vnqdpmd import MdApi +from .vnqdptd import TdApi +from .qdp_data_type import defineDict \ No newline at end of file diff --git a/vnpy/api/qdp/pyscript/generate_data_type.py b/vnpy/api/qdp/pyscript/generate_data_type.py index f6e574a0..4f421d0d 100644 --- a/vnpy/api/qdp/pyscript/generate_data_type.py +++ b/vnpy/api/qdp/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' # C++和python类型的映射字典 @@ -92,9 +93,9 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') except: - print u'data_type.py生成过程出错' + print(u'data_type.py生成过程出错') if __name__ == '__main__': diff --git a/vnpy/api/qdp/pyscript/generate_td_functions.py b/vnpy/api/qdp/pyscript/generate_td_functions.py index 03dbef43..535d7f38 100644 --- a/vnpy/api/qdp/pyscript/generate_td_functions.py +++ b/vnpy/api/qdp/pyscript/generate_td_functions.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from string import join @@ -250,8 +251,8 @@ def createFunction(fcName, fcArgsTypeList, fcArgsValueList): ffunction.write(line) if type_ == 'CQdpFtdcInputOrderField': - print key, value - print line + print(key, value) + print(line) ffunction.write('\tint i = this->api->' + fcName + '(&myreq, nRequestID);\n') ffunction.write('\treturn i;\n')