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