From 14a761b030bf3637de91154ee6a4182bf65df351 Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 8 May 2018 09:09:15 +0200 Subject: [PATCH] Futurize vnpy/data --- vnpy/data/datayes/__init__.py | 3 ++- vnpy/data/datayes/vndatayes.py | 7 +++--- vnpy/data/shcifco/test.py | 12 +++++----- vnpy/data/shcifco/vnshcifco.py | 3 ++- vnpy/data/tq/test.py | 41 +++++++++++++++------------------- vnpy/data/tq/vntq.py | 3 ++- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/vnpy/data/datayes/__init__.py b/vnpy/data/datayes/__init__.py index e06b8545..05395b56 100644 --- a/vnpy/data/datayes/__init__.py +++ b/vnpy/data/datayes/__init__.py @@ -1 +1,2 @@ -from vndatayes import DatayesApi \ No newline at end of file +from __future__ import absolute_import +from .vndatayes import DatayesApi \ No newline at end of file diff --git a/vnpy/data/datayes/vndatayes.py b/vnpy/data/datayes/vndatayes.py index f64aaf68..ed6e44bd 100644 --- a/vnpy/data/datayes/vndatayes.py +++ b/vnpy/data/datayes/vndatayes.py @@ -1,6 +1,7 @@ # encoding: UTF-8 '''一个简单的通联数据客户端,主要使用requests开发,比通联官网的python例子更为简洁。''' +from __future__ import print_function import os import requests @@ -34,7 +35,7 @@ class DatayesApi(object): r = requests.get(url=url, headers=self.header, params=params) if r.status_code != HTTP_OK: - print u'http请求失败,状态代码%s' %r.status_code + print(u'http请求失败,状态代码%s' %r.status_code) return None else: result = r.json() @@ -42,9 +43,9 @@ class DatayesApi(object): return result['data'] else: if 'retMsg' in result: - print u'查询失败,返回信息%s' %result['retMsg'] + print(u'查询失败,返回信息%s' %result['retMsg']) elif 'message' in result: - print u'查询失败,返回信息%s' %result['message'] + print(u'查询失败,返回信息%s' %result['message']) return None diff --git a/vnpy/data/shcifco/test.py b/vnpy/data/shcifco/test.py index eb2f88d8..df9df384 100644 --- a/vnpy/data/shcifco/test.py +++ b/vnpy/data/shcifco/test.py @@ -1,6 +1,8 @@ # encoding: UTF-8 -from vnshcifco import ShcifcoApi, PERIOD_1MIN +from __future__ import print_function +from __future__ import absolute_import +from .vnshcifco import ShcifcoApi, PERIOD_1MIN if __name__ == "__main__": @@ -13,15 +15,15 @@ if __name__ == "__main__": api = ShcifcoApi(ip, port, token) # 获取最新tick - print api.getLastTick(symbol) + print(api.getLastTick(symbol)) # 获取最新价格 - print api.getLastPrice(symbol) + print(api.getLastPrice(symbol)) # 获取最新分钟线 - print api.getLastBar(symbol) + print(api.getLastBar(symbol)) # 获取历史分钟线 - print api.getHisBar(symbol, 500, period=PERIOD_1MIN) + print(api.getHisBar(symbol, 500, period=PERIOD_1MIN)) \ No newline at end of file diff --git a/vnpy/data/shcifco/vnshcifco.py b/vnpy/data/shcifco/vnshcifco.py index e7ace167..2d6c7ab4 100644 --- a/vnpy/data/shcifco/vnshcifco.py +++ b/vnpy/data/shcifco/vnshcifco.py @@ -1,6 +1,7 @@ # encoding: UTF-8 +from __future__ import print_function import requests HTTP_OK = 200 @@ -34,7 +35,7 @@ class ShcifcoApi(object): r = requests.get(url=url, params=params) if r.status_code != HTTP_OK: - print u'http请求失败,状态代码%s' %r.status_code + print(u'http请求失败,状态代码%s' %r.status_code) return None else: return r.text diff --git a/vnpy/data/tq/test.py b/vnpy/data/tq/test.py index 0392ff22..f91cb0a9 100644 --- a/vnpy/data/tq/test.py +++ b/vnpy/data/tq/test.py @@ -1,9 +1,10 @@ # encoding: UTF-8 -from time import sleep - -from vntq import TqApi +from __future__ import print_function +from __future__ import absolute_import +from six import input +from .vntq import TqApi # 接口对象 api = None @@ -12,43 +13,37 @@ api = None #---------------------------------------------------------------------- def onQuote(symbol): """Tick更新""" - print '-' * 30 - print 'onQuote' + print('-' * 30) + print('onQuote') quote = api.get_quote(symbol) - print quote + print(quote) + #---------------------------------------------------------------------- def onChart(symbol, seconds): """K线更新""" - print '-' * 30 - print 'onChart' - + print('-' * 30) + print('onChart') + if seconds == 0: serial = api.get_tick_serial(symbol) else: serial = api.get_kline_serial(symbol, seconds) - - print serial - + + print(serial) + if __name__ == "__main__": symbol = 'CFFEX.IF1710' - api = TqApi() - api.connect() - + # 订阅Tick推送 #api.subscribe_quote([symbol], onQuote) - + # 订阅Tick图表 #api.subscribe_chart(symbol, 0, 100, onChart) - + # 订阅K线图表 api.subscribe_chart(symbol, 60, 1000, onChart) - - raw_input() - - - - \ No newline at end of file + input() diff --git a/vnpy/data/tq/vntq.py b/vnpy/data/tq/vntq.py index 87268c75..e4ca49ea 100644 --- a/vnpy/data/tq/vntq.py +++ b/vnpy/data/tq/vntq.py @@ -6,6 +6,7 @@ 天勤行情终端: http://www.tq18.cn 天勤接口文档: http://doc.tq18.cn/tq/latest/extension/wsapi/index.html """ +from __future__ import print_function import json @@ -221,7 +222,7 @@ class TqApi(object): if 'data' in pack: l = pack["data"] else: - print u'on_receive_msg收到的数据中没有data字段,数据内容%s' %str(pack) + print(u'on_receive_msg收到的数据中没有data字段,数据内容%s' %str(pack)) return for data in l: