Merge branch 'dev' of https://github.com/vnpy/vnpy into dev
This commit is contained in:
commit
50277d79a5
@ -4,6 +4,7 @@ import urllib
|
||||
import hashlib
|
||||
|
||||
import json
|
||||
import logging
|
||||
import requests
|
||||
import hmac
|
||||
import time
|
||||
@ -374,4 +375,3 @@ class Korbit_DataApi(object):
|
||||
def onOrderbooks(self, data):
|
||||
"""实时成交推送"""
|
||||
print data
|
||||
|
||||
|
@ -1,8 +1,4 @@
|
||||
{
|
||||
"MONGO_HOST": "localhost",
|
||||
"MONGO_PORT": 27017,
|
||||
|
||||
"SYMBOLS": ["IF1710", "IF1711", "IF1712", "IF1803",
|
||||
"IH1710", "IH1711", "IH1712", "IH1803",
|
||||
"IC1710", "IC1711", "IC1712", "IC1803"]
|
||||
"MONGO_PORT": 27017
|
||||
}
|
@ -18,7 +18,6 @@ setting = json.load(config)
|
||||
|
||||
MONGO_HOST = setting['MONGO_HOST']
|
||||
MONGO_PORT = setting['MONGO_PORT']
|
||||
SYMBOLS = setting['SYMBOLS']
|
||||
|
||||
mc = MongoClient(MONGO_HOST, MONGO_PORT) # Mongo连接
|
||||
db = mc[MINUTE_DB_NAME] # 数据库
|
||||
@ -80,16 +79,16 @@ def downMinuteBarBySymbol(symbol, num):
|
||||
api.subscribe_chart(symbol, 60, num, onChart)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def downloadAllMinuteBar(num):
|
||||
def downloadAllMinuteBar(num, symbols):
|
||||
"""下载所有配置中的合约的分钟线数据"""
|
||||
print '-' * 50
|
||||
print u'开始下载合约分钟线数据'
|
||||
print '-' * 50
|
||||
|
||||
# 添加下载任务
|
||||
taskList.extend(SYMBOLS)
|
||||
taskList.extend(symbols)
|
||||
|
||||
for symbol in SYMBOLS:
|
||||
for symbol in symbols:
|
||||
downMinuteBarBySymbol(str(symbol), num)
|
||||
|
||||
while True:
|
||||
|
@ -2,10 +2,16 @@
|
||||
|
||||
"""
|
||||
立即下载数据到数据库中,用于手动执行更新操作。
|
||||
|
||||
注意: 请先在本机启动天勤终端 (0.8.0 以上版本) 并保持运行, 再执行本程序
|
||||
"""
|
||||
|
||||
from dataService import *
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
downloadAllMinuteBar(1000)
|
||||
symbols = ["CFFEX.IF1710", "CFFEX.IF1711", "CFFEX.IF1712", "CFFEX.IF1803",
|
||||
"CFFEX.IH1710", "CFFEX.IH1711", "CFFEX.IH1712", "CFFEX.IH1803",
|
||||
"CFFEX.IC1710", "CFFEX.IC1711", "CFFEX.IC1712", "CFFEX.IC1803"]
|
||||
downloadAllMinuteBar(1000, symbols)
|
@ -2,6 +2,8 @@
|
||||
|
||||
"""
|
||||
定时服务,可无人值守运行,实现每日自动下载更新历史行情数据到数据库中。
|
||||
|
||||
注意: 请确保本程序运行时, 本机天勤终端 (0.8.0 以上版本)正在运行中
|
||||
"""
|
||||
|
||||
import time
|
||||
@ -16,6 +18,10 @@ if __name__ == '__main__':
|
||||
# 生成一个随机的任务下载时间,用于避免所有用户在同一时间访问数据服务器
|
||||
taskTime = datetime.time(hour=17, minute=0)
|
||||
|
||||
symbols = ["CFFEX.IF1710", "CFFEX.IF1711", "CFFEX.IF1712", "CFFEX.IF1803",
|
||||
"CFFEX.IH1710", "CFFEX.IH1711", "CFFEX.IH1712", "CFFEX.IH1803",
|
||||
"CFFEX.IC1710", "CFFEX.IC1711", "CFFEX.IC1712", "CFFEX.IC1803"]
|
||||
|
||||
# 进入主循环
|
||||
while True:
|
||||
t = datetime.datetime.now()
|
||||
@ -23,7 +29,7 @@ if __name__ == '__main__':
|
||||
# 每天到达任务下载时间后,执行数据下载的操作
|
||||
if t.time() > taskTime and (taskCompletedDate is None or t.date() != taskCompletedDate):
|
||||
# 下载1000根分钟线数据,足以覆盖过去两天的行情
|
||||
downloadAllMinuteBar(1000)
|
||||
downloadAllMinuteBar(1000, symbols)
|
||||
|
||||
# 更新任务完成的日期
|
||||
taskCompletedDate = t.date()
|
||||
|
@ -277,4 +277,5 @@ class TqApi(object):
|
||||
def _generate_chart_id(self, ins_id, duration_seconds):
|
||||
"""生成图表编号"""
|
||||
chart_id = "VN_%s_%d" % (ins_id, duration_seconds)
|
||||
chart_id = chart_id.replace(".", "_")
|
||||
return chart_id
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
from time import sleep
|
||||
|
||||
from vnrpc import RpcClient
|
||||
@ -17,7 +18,7 @@ class TestClient(RpcClient):
|
||||
#----------------------------------------------------------------------
|
||||
def callback(self, topic, data):
|
||||
"""回调函数实现"""
|
||||
print 'client received topic:', topic, ', data:', data
|
||||
print('client received topic:', topic, ', data:', data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -29,5 +30,5 @@ if __name__ == '__main__':
|
||||
tc.start()
|
||||
|
||||
while 1:
|
||||
print tc.add(1, 3)
|
||||
print(tc.add(1, 3))
|
||||
sleep(2)
|
@ -1,5 +1,6 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
from __future__ import print_function
|
||||
from time import sleep, time
|
||||
|
||||
from vnrpc import RpcServer
|
||||
@ -19,7 +20,7 @@ class TestServer(RpcServer):
|
||||
#----------------------------------------------------------------------
|
||||
def add(self, a, b):
|
||||
"""测试函数"""
|
||||
print 'receiving: %s, %s' % (a,b)
|
||||
print('receiving: %s, %s' % (a,b))
|
||||
return a + b
|
||||
|
||||
|
||||
@ -32,6 +33,6 @@ if __name__ == '__main__':
|
||||
|
||||
while 1:
|
||||
content = 'current server time is %s' % time()
|
||||
print content
|
||||
print(content)
|
||||
ts.publish('test', content)
|
||||
sleep(2)
|
@ -313,5 +313,3 @@ class RemoteException(Exception):
|
||||
def __str__(self):
|
||||
"""输出错误信息"""
|
||||
return self.__value
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user