From bc7c9cd92b053c888a1dff3ab2152d0e8a334f20 Mon Sep 17 00:00:00 2001 From: yangyang Date: Mon, 9 Apr 2018 16:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=A4=A9=E5=8B=A4=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8E=A5=E5=8F=A3=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/TqDataService/config.json | 6 +----- examples/TqDataService/dataService.py | 7 +++---- examples/TqDataService/downloadData.py | 8 +++++++- examples/TqDataService/runService.py | 10 ++++++++-- vnpy/data/tq/vntq.py | 1 + 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/TqDataService/config.json b/examples/TqDataService/config.json index ff747220..467e7857 100644 --- a/examples/TqDataService/config.json +++ b/examples/TqDataService/config.json @@ -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 } \ No newline at end of file diff --git a/examples/TqDataService/dataService.py b/examples/TqDataService/dataService.py index 0861fe22..cfeb3b93 100644 --- a/examples/TqDataService/dataService.py +++ b/examples/TqDataService/dataService.py @@ -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: diff --git a/examples/TqDataService/downloadData.py b/examples/TqDataService/downloadData.py index 3cf6f3cc..246df77a 100644 --- a/examples/TqDataService/downloadData.py +++ b/examples/TqDataService/downloadData.py @@ -2,10 +2,16 @@ """ 立即下载数据到数据库中,用于手动执行更新操作。 + +注意: 请先在本机启动天勤终端 (0.8.0 以上版本) 并保持运行, 再执行本程序 """ from dataService import * + if __name__ == '__main__': - downloadAllMinuteBar(1000) \ No newline at end of file + 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) \ No newline at end of file diff --git a/examples/TqDataService/runService.py b/examples/TqDataService/runService.py index 17d6d165..3b5d356f 100644 --- a/examples/TqDataService/runService.py +++ b/examples/TqDataService/runService.py @@ -2,6 +2,8 @@ """ 定时服务,可无人值守运行,实现每日自动下载更新历史行情数据到数据库中。 + +注意: 请确保本程序运行时, 本机天勤终端 (0.8.0 以上版本)正在运行中 """ import time @@ -15,7 +17,11 @@ 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() diff --git a/vnpy/data/tq/vntq.py b/vnpy/data/tq/vntq.py index 8f3a9797..87268c75 100644 --- a/vnpy/data/tq/vntq.py +++ b/vnpy/data/tq/vntq.py @@ -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 \ No newline at end of file