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
'''一个简单的通联数据客户端主要使用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

View File

@ -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))

View File

@ -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

View File

@ -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()
input()

View File

@ -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: