From b4ccfdc3780623267796d1e00c304a0c2a1ce493 Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 14 May 2018 16:30:28 +0200 Subject: [PATCH] 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