Merge pull request #851 from cclauss/modernize-vnpy_data

Modernize vnpy/data
This commit is contained in:
vn.py 2018-05-10 10:43:43 +08:00 committed by GitHub
commit a92ac2e951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 34 deletions

View File

@ -1 +1,2 @@
from vndatayes import DatayesApi from __future__ import absolute_import
from .vndatayes import DatayesApi

View File

@ -1,6 +1,7 @@
# encoding: UTF-8 # encoding: UTF-8
'''一个简单的通联数据客户端主要使用requests开发比通联官网的python例子更为简洁。''' '''一个简单的通联数据客户端主要使用requests开发比通联官网的python例子更为简洁。'''
from __future__ import print_function
import os import os
import requests import requests
@ -34,7 +35,7 @@ class DatayesApi(object):
r = requests.get(url=url, headers=self.header, params=params) r = requests.get(url=url, headers=self.header, params=params)
if r.status_code != HTTP_OK: if r.status_code != HTTP_OK:
print u'http请求失败状态代码%s' %r.status_code print(u'http请求失败状态代码%s' %r.status_code)
return None return None
else: else:
result = r.json() result = r.json()
@ -42,9 +43,9 @@ class DatayesApi(object):
return result['data'] return result['data']
else: else:
if 'retMsg' in result: if 'retMsg' in result:
print u'查询失败,返回信息%s' %result['retMsg'] print(u'查询失败,返回信息%s' %result['retMsg'])
elif 'message' in result: elif 'message' in result:
print u'查询失败,返回信息%s' %result['message'] print(u'查询失败,返回信息%s' %result['message'])
return None return None

View File

@ -1,6 +1,8 @@
# encoding: UTF-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__": if __name__ == "__main__":
@ -13,15 +15,15 @@ if __name__ == "__main__":
api = ShcifcoApi(ip, port, token) api = ShcifcoApi(ip, port, token)
# 获取最新tick # 获取最新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))

View File

@ -1,6 +1,7 @@
# encoding: UTF-8 # encoding: UTF-8
from __future__ import print_function
import requests import requests
HTTP_OK = 200 HTTP_OK = 200
@ -34,7 +35,7 @@ class ShcifcoApi(object):
r = requests.get(url=url, params=params) r = requests.get(url=url, params=params)
if r.status_code != HTTP_OK: if r.status_code != HTTP_OK:
print u'http请求失败状态代码%s' %r.status_code print(u'http请求失败状态代码%s' %r.status_code)
return None return None
else: else:
return r.text return r.text

View File

@ -1,9 +1,10 @@
# encoding: UTF-8 # encoding: UTF-8
from time import sleep from __future__ import print_function
from __future__ import absolute_import
from vntq import TqApi from six import input
from .vntq import TqApi
# 接口对象 # 接口对象
api = None api = None
@ -12,30 +13,29 @@ api = None
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onQuote(symbol): def onQuote(symbol):
"""Tick更新""" """Tick更新"""
print '-' * 30 print('-' * 30)
print 'onQuote' print('onQuote')
quote = api.get_quote(symbol) quote = api.get_quote(symbol)
print quote print(quote)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def onChart(symbol, seconds): def onChart(symbol, seconds):
"""K线更新""" """K线更新"""
print '-' * 30 print('-' * 30)
print 'onChart' print('onChart')
if seconds == 0: if seconds == 0:
serial = api.get_tick_serial(symbol) serial = api.get_tick_serial(symbol)
else: else:
serial = api.get_kline_serial(symbol, seconds) serial = api.get_kline_serial(symbol, seconds)
print serial print(serial)
if __name__ == "__main__": if __name__ == "__main__":
symbol = 'CFFEX.IF1710' symbol = 'CFFEX.IF1710'
api = TqApi() api = TqApi()
api.connect() api.connect()
# 订阅Tick推送 # 订阅Tick推送
@ -46,9 +46,4 @@ if __name__ == "__main__":
# 订阅K线图表 # 订阅K线图表
api.subscribe_chart(symbol, 60, 1000, onChart) api.subscribe_chart(symbol, 60, 1000, onChart)
input()
raw_input()

View File

@ -6,6 +6,7 @@
天勤行情终端: http://www.tq18.cn 天勤行情终端: http://www.tq18.cn
天勤接口文档: http://doc.tq18.cn/tq/latest/extension/wsapi/index.html 天勤接口文档: http://doc.tq18.cn/tq/latest/extension/wsapi/index.html
""" """
from __future__ import print_function
import json import json
@ -221,7 +222,7 @@ class TqApi(object):
if 'data' in pack: if 'data' in pack:
l = pack["data"] l = pack["data"]
else: else:
print u'on_receive_msg收到的数据中没有data字段数据内容%s' %str(pack) print(u'on_receive_msg收到的数据中没有data字段数据内容%s' %str(pack))
return return
for data in l: for data in l: