From fc4699bc3915d61c839810b4ce1412e23b55fe36 Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 29 May 2018 12:47:36 +0200 Subject: [PATCH] Modernize vnpy/api/xtp --- vnpy/api/xtp/__init__.py | 7 +- vnpy/api/xtp/pyscript/generate_data_type.py | 3 +- .../api/xtp/pyscript/generate_md_functions.py | 3 +- vnpy/api/xtp/pyscript/generate_struct_oms.py | 5 +- .../api/xtp/pyscript/generate_struct_quote.py | 3 +- .../api/xtp/pyscript/generate_td_functions.py | 7 +- vnpy/api/xtp/test/quotetest.py | 17 ++-- vnpy/api/xtp/test/tradertest.py | 77 ++++++++++--------- 8 files changed, 66 insertions(+), 56 deletions(-) diff --git a/vnpy/api/xtp/__init__.py b/vnpy/api/xtp/__init__.py index 4978cf9f..792f0dcc 100644 --- a/vnpy/api/xtp/__init__.py +++ b/vnpy/api/xtp/__init__.py @@ -1,5 +1,6 @@ # encoding: UTF-8 -from vnxtpquote import QuoteApi -from vnxtptrader import TraderApi -from xtp_data_type import * \ No newline at end of file +from __future__ import absolute_import +from .vnxtpquote import QuoteApi +from .vnxtptrader import TraderApi +from .xtp_data_type import * \ No newline at end of file diff --git a/vnpy/api/xtp/pyscript/generate_data_type.py b/vnpy/api/xtp/pyscript/generate_data_type.py index e04ae76e..ba72d668 100644 --- a/vnpy/api/xtp/pyscript/generate_data_type.py +++ b/vnpy/api/xtp/pyscript/generate_data_type.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = u'用Python的交易员' # C++和python类型的映射字典 @@ -128,7 +129,7 @@ def main(): fcpp.close() fpy.close() - print u'data_type.py生成过程完成' + print(u'data_type.py生成过程完成') if __name__ == '__main__': diff --git a/vnpy/api/xtp/pyscript/generate_md_functions.py b/vnpy/api/xtp/pyscript/generate_md_functions.py index 94aa92e2..54e089be 100644 --- a/vnpy/api/xtp/pyscript/generate_md_functions.py +++ b/vnpy/api/xtp/pyscript/generate_md_functions.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from string import join @@ -331,4 +332,4 @@ fheaderon.close() fheaderfunction.close() fwrap.close() -print 'md functions done' \ No newline at end of file +print('md functions done') \ No newline at end of file diff --git a/vnpy/api/xtp/pyscript/generate_struct_oms.py b/vnpy/api/xtp/pyscript/generate_struct_oms.py index b230050c..dbab14ef 100644 --- a/vnpy/api/xtp/pyscript/generate_struct_oms.py +++ b/vnpy/api/xtp/pyscript/generate_struct_oms.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from xtp_data_type import * @@ -27,7 +28,7 @@ def main(): fpy.write('\n') for row, line in enumerate(fcpp): - print row + print(row) # 结构体申明注释 if '///' in line and '\t' not in line: py_line = '#' + line[3:] @@ -38,7 +39,7 @@ def main(): # 结构体申明 elif 'struct ' in line: - print line + print(line) content = line.split(' ') name = content[1].replace('\n','') name = name.replace('\r', '') diff --git a/vnpy/api/xtp/pyscript/generate_struct_quote.py b/vnpy/api/xtp/pyscript/generate_struct_quote.py index 0f4e7833..b8ade4d7 100644 --- a/vnpy/api/xtp/pyscript/generate_struct_quote.py +++ b/vnpy/api/xtp/pyscript/generate_struct_quote.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from xtp_data_type import * @@ -38,7 +39,7 @@ def main(): lcpp = replaceTabs(fcpp) for n, line in enumerate(lcpp): - print n + print(n) # 结构体申明注释 if '///' in line and '\t' not in line: py_line = '#' + line[3:] diff --git a/vnpy/api/xtp/pyscript/generate_td_functions.py b/vnpy/api/xtp/pyscript/generate_td_functions.py index ede47e4a..7d4081f3 100644 --- a/vnpy/api/xtp/pyscript/generate_td_functions.py +++ b/vnpy/api/xtp/pyscript/generate_td_functions.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function __author__ = 'CHENXY' from string import join @@ -194,7 +195,7 @@ def createProcess(cbName, cbArgsTypeList, cbArgsValueList): fprocess.write(" PyLock lock;\n") onArgsList = [] - print cbName, cbArgsTypeList + print(cbName, cbArgsTypeList) for i, type_ in enumerate(cbArgsTypeList): if 'XTPRI' in type_: @@ -258,7 +259,7 @@ def processFunction(line): fcArgs = fcArgs.replace(')', '') fcArgsList = fcArgs.split(', ') # 将每个参数转化为列表 - print fcArgsList + print(fcArgsList) fcArgsTypeList = [] fcArgsValueList = [] @@ -352,4 +353,4 @@ fheaderon.close() fheaderfunction.close() fwrap.close() -print 'td functions done' \ No newline at end of file +print('td functions done') \ No newline at end of file diff --git a/vnpy/api/xtp/test/quotetest.py b/vnpy/api/xtp/test/quotetest.py index e353940b..deec29e8 100644 --- a/vnpy/api/xtp/test/quotetest.py +++ b/vnpy/api/xtp/test/quotetest.py @@ -1,5 +1,6 @@ # encoding: UTF-8 +from __future__ import print_function import os from time import sleep @@ -8,11 +9,11 @@ from vnxtpquote import * #---------------------------------------------------------------------- def printDict(d): """""" - print '-' * 50 + print('-' * 50) l = d.keys() l.sort() for k in l: - print k, d[k] + print(k, d[k]) @@ -28,32 +29,32 @@ class TestApi(QuoteApi): #---------------------------------------------------------------------- def onDisconnected(self, reason): """""" - print 'disconnect', reason + print('disconnect', reason) #---------------------------------------------------------------------- def onError(self, data): """""" - print 'error' + print('error') printDict(data) #---------------------------------------------------------------------- def onSubMarketData(self, data, error, last): """""" - print 'sub market data' + print('sub market data') printDict(data) printDict(error) #---------------------------------------------------------------------- def onUnSubMarketData(self, data, error, last): """""" - print 'unsub market data' + print('unsub market data') printDict(data) printDict(error) #---------------------------------------------------------------------- def onMarketData(self, data): """""" - print 'new market data' + print('new market data') printDict(data) #---------------------------------------------------------------------- @@ -75,7 +76,7 @@ if __name__ == '__main__': # 登录 n = api.login(ip, port, user, password, 1) - print 'login result', n + print('login result', n) # 订阅行情 api.subscribeMarketData('000001', 2) diff --git a/vnpy/api/xtp/test/tradertest.py b/vnpy/api/xtp/test/tradertest.py index 86f012d3..843e3b8f 100644 --- a/vnpy/api/xtp/test/tradertest.py +++ b/vnpy/api/xtp/test/tradertest.py @@ -1,20 +1,23 @@ # encoding: UTF-8 +from __future__ import print_function import os from time import sleep +from six.moves import input + from vnxtptrader import * + #---------------------------------------------------------------------- def printDict(d): """""" - print '-' * 50 + print('-' * 50) l = d.keys() l.sort() for k in l: - print k, d[k] - - + print(k, d[k]) + ######################################################################## class TestApi(TraderApi): @@ -28,79 +31,79 @@ class TestApi(TraderApi): #---------------------------------------------------------------------- def onDisconnected(self, reason): """""" - print '-' * 30 - print 'onDisconnected' - print reason + print('-' * 30) + print('onDisconnected') + print(reason) #---------------------------------------------------------------------- def onError(self, data): """""" - print '-' * 30 - print 'onError' + print('-' * 30) + print('onError') printDict(data) #---------------------------------------------------------------------- def onOrderEvent(self, data, error): """""" - print '-' * 30 - print 'onOrderEvent' + print('-' * 30) + print('onOrderEvent') printDict(data) printDict(error) #---------------------------------------------------------------------- def onTradeEvent(self, data): """""" - print '-' * 30 - print 'onTradeEvent' + print('-' * 30) + print('onTradeEvent') printDict(data) #---------------------------------------------------------------------- def onCancelOrderError(self, data, error): """""" - print '-' * 30 - print 'onCancelOrderError' + print('-' * 30) + print('onCancelOrderError') printDict(data) printDict(error) #---------------------------------------------------------------------- def onQueryOrder(self, data, error, reqid, last): """""" - print '-' * 30 - print 'onQueryOrder' + print('-' * 30) + print('onQueryOrder') printDict(data) printDict(error) - print reqid - print last + print(reqid) + print(last) #---------------------------------------------------------------------- def onQueryTrade(self, data, error, reqid, last): """""" - print '-' * 30 - print 'onQueryTrade' + print('-' * 30) + print('onQueryTrade') printDict(data) printDict(error) - print reqid - print last + print(reqid) + print(last) #---------------------------------------------------------------------- def onQueryPosition(self, data, error, reqid, last): """""" - print '-' * 30 - print 'onQueryPosition' + print('-' * 30) + print('onQueryPosition') printDict(data) printDict(error) - print reqid - print last + print(reqid) + print(last) #---------------------------------------------------------------------- def onQueryAsset(self, data, error, reqid, last): """""" - print '-' * 30 - print 'onQueryAsset' + print('-' * 30) + print('onQueryAsset') printDict(data) printDict(error) - print reqid - print last + print(reqid) + print(last) @@ -121,12 +124,12 @@ if __name__ == '__main__': # 登录 session = api.login(ip, port, user, password, 1) - print 'login result', session + print('login result', session) # 调用同步函数查询一些信息 - print 'trading day is:', api.getTradingDay() - print 'api version is:', api.getApiVersion() - print 'last error is:', api.getApiLastError() + print('trading day is:', api.getTradingDay()) + print('api version is:', api.getApiVersion()) + print('last error is:', api.getApiLastError()) # 查询资产 sleep(2) @@ -166,7 +169,7 @@ if __name__ == '__main__': # 登出 sleep(5) - print 'logout:', api.logout(session) + print('logout:', api.logout(session)) # 阻塞 - raw_input() + input()