From e58a71c79bee3a79d08fdb5da3309aef69d88d2a Mon Sep 17 00:00:00 2001 From: cclauss Date: Thu, 17 May 2018 08:49:28 +0200 Subject: [PATCH] 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