From c430bc93c67b7d9ecb7e1a89b14141c990c38470 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 5 Aug 2018 22:44:00 +0800 Subject: [PATCH] [Fix]Close #1002 --- examples/FutuTrader/run.py | 4 +-- examples/VnTrader/CTP_connect.json | 2 +- vnpy/trader/app/ctaStrategy/ctaHistoryData.py | 35 ++++++++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/examples/FutuTrader/run.py b/examples/FutuTrader/run.py index 123cf5de..05bb3146 100644 --- a/examples/FutuTrader/run.py +++ b/examples/FutuTrader/run.py @@ -12,7 +12,7 @@ from vnpy.trader.uiMainWindow import MainWindow from vnpy.trader.gateway import futuGateway # 加载上层应用 -from vnpy.trader.app import riskManager#, ctaStrategy +from vnpy.trader.app import riskManager, ctaStrategy #---------------------------------------------------------------------- @@ -32,7 +32,7 @@ def main(): # 添加上层应用 me.addApp(riskManager) - #me.addApp(ctaStrategy) + me.addApp(ctaStrategy) # 创建主窗口 mw = MainWindow(me, ee) diff --git a/examples/VnTrader/CTP_connect.json b/examples/VnTrader/CTP_connect.json index 11beaff8..4ab4bb76 100644 --- a/examples/VnTrader/CTP_connect.json +++ b/examples/VnTrader/CTP_connect.json @@ -3,5 +3,5 @@ "mdAddress": "tcp://180.168.146.187:10031", "tdAddress": "tcp://180.168.146.187:10030", "userID": "000300", - "password": "19890624" + "password": "123456789" } \ No newline at end of file diff --git a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py index 362a66e2..a979e806 100644 --- a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py +++ b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py @@ -84,23 +84,24 @@ def loadMcCsv(fileName, dbName, symbol): collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True) # 读取数据和插入到数据库 - reader = csv.DictReader(file(fileName, 'r')) - for d in reader: - bar = VtBarData() - bar.vtSymbol = symbol - bar.symbol = symbol - bar.open = float(d['Open']) - bar.high = float(d['High']) - bar.low = float(d['Low']) - bar.close = float(d['Close']) - bar.date = datetime.strptime(d['Date'], '%Y-%m-%d').strftime('%Y%m%d') - bar.time = d['Time'] - bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S') - bar.volume = d['TotalVolume'] - - flt = {'datetime': bar.datetime} - collection.update_one(flt, {'$set':bar.__dict__}, upsert=True) - print(bar.date, bar.time) + with open(fileName, 'r') as f: + reader = csv.DictReader(f) + for d in reader: + bar = VtBarData() + bar.vtSymbol = symbol + bar.symbol = symbol + bar.open = float(d['Open']) + bar.high = float(d['High']) + bar.low = float(d['Low']) + bar.close = float(d['Close']) + bar.date = datetime.strptime(d['Date'], '%Y-%m-%d').strftime('%Y%m%d') + bar.time = d['Time'] + bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S') + bar.volume = d['TotalVolume'] + + flt = {'datetime': bar.datetime} + collection.update_one(flt, {'$set':bar.__dict__}, upsert=True) + print(bar.date, bar.time) print(u'插入完毕,耗时:%s' % (time()-start))