From 739364ebfead7790abb24c97e45f8c4acc3f3e7a Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Fri, 8 Dec 2017 21:23:42 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=E6=B7=BB=E5=8A=A0=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84future=E5=BA=93=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/QuantosDataService/dataService.py | 24 ++++++++++----------- examples/QuantosDataService/downloadData.py | 2 +- requirements.txt | 3 ++- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/QuantosDataService/dataService.py b/examples/QuantosDataService/dataService.py index 0d76fc70..dd6717e7 100644 --- a/examples/QuantosDataService/dataService.py +++ b/examples/QuantosDataService/dataService.py @@ -62,7 +62,7 @@ def generateVtBar(row): return bar #---------------------------------------------------------------------- -def downMinuteBarBySymbol(api, vtSymbol, startDate): +def downMinuteBarBySymbol(api, vtSymbol, startDate, endDate=''): """下载某一合约的分钟线数据""" start = time() @@ -70,13 +70,17 @@ def downMinuteBarBySymbol(api, vtSymbol, startDate): cl.ensure_index([('datetime', ASCENDING)], unique=True) # 添加索引 dt = datetime.strptime(startDate, '%Y%m%d') - today = datetime.now() + + if endDate: + end = datetime.strptime(endDate, '%Y%m%d') + else: + end = datetime.now() delta = timedelta(1) code, exchange = vtSymbol.split('.') symbol = '.'.join([code, exchangeMap[exchange]]) - while dt <= today: + while dt <= end: d = int(dt.strftime('%Y%m%d')) df, msg = api.bar(symbol, freq='1M', trade_date=d) dt += delta @@ -91,20 +95,20 @@ def downMinuteBarBySymbol(api, vtSymbol, startDate): cl.replace_one(flt, d, True) - end = time() - cost = (end - start) * 1000 + e = time() + cost = (e - start) * 1000 - print u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(vtSymbol, startDate, today.strftime('%Y%m%d'), cost) + print u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(vtSymbol, startDate, end.strftime('%Y%m%d'), cost) #---------------------------------------------------------------------- -def downloadAllMinuteBar(api): +def downloadAllMinuteBar(api, days=10): """下载所有配置中的合约的分钟线数据""" print '-' * 50 print u'开始下载合约分钟线数据' print '-' * 50 - startDt = datetime.today() - 10 * timedelta(1) + startDt = datetime.today() - days * timedelta(1) startDate = startDt.strftime('%Y%m%d') # 添加下载任务 @@ -115,7 +119,3 @@ def downloadAllMinuteBar(api): print u'合约分钟线数据下载完成' print '-' * 50 - -if __name__ == '__main__': - downloadAllMinuteBar() - \ No newline at end of file diff --git a/examples/QuantosDataService/downloadData.py b/examples/QuantosDataService/downloadData.py index 5ed97326..7c13838a 100644 --- a/examples/QuantosDataService/downloadData.py +++ b/examples/QuantosDataService/downloadData.py @@ -19,4 +19,4 @@ if __name__ == '__main__': print u'数据服务器登录失败,原因:%s' %msg # 下载数据 - downloadAllMinuteBar(api) \ No newline at end of file + downloadAllMinuteBar(api, 100) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index e9c96db4..180feca0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ msgpack-python qdarkstyle SortedContainers futuquant -wmi \ No newline at end of file +wmi +future \ No newline at end of file