修正天勤数据接口不能正常获取数据的bug
This commit is contained in:
parent
880e0b3868
commit
bc7c9cd92b
@ -1,8 +1,4 @@
|
|||||||
{
|
{
|
||||||
"MONGO_HOST": "localhost",
|
"MONGO_HOST": "localhost",
|
||||||
"MONGO_PORT": 27017,
|
"MONGO_PORT": 27017
|
||||||
|
|
||||||
"SYMBOLS": ["IF1710", "IF1711", "IF1712", "IF1803",
|
|
||||||
"IH1710", "IH1711", "IH1712", "IH1803",
|
|
||||||
"IC1710", "IC1711", "IC1712", "IC1803"]
|
|
||||||
}
|
}
|
@ -18,7 +18,6 @@ setting = json.load(config)
|
|||||||
|
|
||||||
MONGO_HOST = setting['MONGO_HOST']
|
MONGO_HOST = setting['MONGO_HOST']
|
||||||
MONGO_PORT = setting['MONGO_PORT']
|
MONGO_PORT = setting['MONGO_PORT']
|
||||||
SYMBOLS = setting['SYMBOLS']
|
|
||||||
|
|
||||||
mc = MongoClient(MONGO_HOST, MONGO_PORT) # Mongo连接
|
mc = MongoClient(MONGO_HOST, MONGO_PORT) # Mongo连接
|
||||||
db = mc[MINUTE_DB_NAME] # 数据库
|
db = mc[MINUTE_DB_NAME] # 数据库
|
||||||
@ -80,16 +79,16 @@ def downMinuteBarBySymbol(symbol, num):
|
|||||||
api.subscribe_chart(symbol, 60, num, onChart)
|
api.subscribe_chart(symbol, 60, num, onChart)
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def downloadAllMinuteBar(num):
|
def downloadAllMinuteBar(num, symbols):
|
||||||
"""下载所有配置中的合约的分钟线数据"""
|
"""下载所有配置中的合约的分钟线数据"""
|
||||||
print '-' * 50
|
print '-' * 50
|
||||||
print u'开始下载合约分钟线数据'
|
print u'开始下载合约分钟线数据'
|
||||||
print '-' * 50
|
print '-' * 50
|
||||||
|
|
||||||
# 添加下载任务
|
# 添加下载任务
|
||||||
taskList.extend(SYMBOLS)
|
taskList.extend(symbols)
|
||||||
|
|
||||||
for symbol in SYMBOLS:
|
for symbol in symbols:
|
||||||
downMinuteBarBySymbol(str(symbol), num)
|
downMinuteBarBySymbol(str(symbol), num)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -2,10 +2,16 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
立即下载数据到数据库中,用于手动执行更新操作。
|
立即下载数据到数据库中,用于手动执行更新操作。
|
||||||
|
|
||||||
|
注意: 请先在本机启动天勤终端 (0.8.0 以上版本) 并保持运行, 再执行本程序
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from dataService import *
|
from dataService import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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
|
import time
|
||||||
@ -16,6 +18,10 @@ if __name__ == '__main__':
|
|||||||
# 生成一个随机的任务下载时间,用于避免所有用户在同一时间访问数据服务器
|
# 生成一个随机的任务下载时间,用于避免所有用户在同一时间访问数据服务器
|
||||||
taskTime = datetime.time(hour=17, minute=0)
|
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:
|
while True:
|
||||||
t = datetime.datetime.now()
|
t = datetime.datetime.now()
|
||||||
@ -23,7 +29,7 @@ if __name__ == '__main__':
|
|||||||
# 每天到达任务下载时间后,执行数据下载的操作
|
# 每天到达任务下载时间后,执行数据下载的操作
|
||||||
if t.time() > taskTime and (taskCompletedDate is None or t.date() != taskCompletedDate):
|
if t.time() > taskTime and (taskCompletedDate is None or t.date() != taskCompletedDate):
|
||||||
# 下载1000根分钟线数据,足以覆盖过去两天的行情
|
# 下载1000根分钟线数据,足以覆盖过去两天的行情
|
||||||
downloadAllMinuteBar(1000)
|
downloadAllMinuteBar(1000, symbols)
|
||||||
|
|
||||||
# 更新任务完成的日期
|
# 更新任务完成的日期
|
||||||
taskCompletedDate = t.date()
|
taskCompletedDate = t.date()
|
||||||
|
@ -277,4 +277,5 @@ class TqApi(object):
|
|||||||
def _generate_chart_id(self, ins_id, duration_seconds):
|
def _generate_chart_id(self, ins_id, duration_seconds):
|
||||||
"""生成图表编号"""
|
"""生成图表编号"""
|
||||||
chart_id = "VN_%s_%d" % (ins_id, duration_seconds)
|
chart_id = "VN_%s_%d" % (ins_id, duration_seconds)
|
||||||
|
chart_id = chart_id.replace(".", "_")
|
||||||
return chart_id
|
return chart_id
|
Loading…
Reference in New Issue
Block a user