From 6610836a048d56314fdfab8debc35ebdcc5b108d Mon Sep 17 00:00:00 2001 From: Hunggin <516672315@qq.com> Date: Tue, 10 Oct 2017 14:31:25 +0800 Subject: [PATCH] TBPlus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加了TB极速版数据导入 --- vnpy/trader/app/ctaStrategy/ctaHistoryData.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py index dbe0394a..9ca98c7e 100644 --- a/vnpy/trader/app/ctaStrategy/ctaHistoryData.py +++ b/vnpy/trader/app/ctaStrategy/ctaHistoryData.py @@ -430,6 +430,44 @@ def loadTbCsv(fileName, dbName, symbol): print bar.date, bar.time print u'插入完毕,耗时:%s' % (time()-start) + + #---------------------------------------------------------------------- +def loadTbPlusCsv(fileName, dbName, symbol): + """将TB极速版导出的csv格式的历史分钟数据插入到Mongo数据库中""" + import csv + + start = time() + print u'开始读取CSV文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol) + + # 锁定集合,并创建索引 + client = pymongo.MongoClient(globalSetting['mongoHost'], globalSetting['mongoPort']) + collection = client[dbName][symbol] + collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True) + + # 读取数据和插入到数据库 + reader = csv.reader(file(fileName, 'r')) + for d in reader: + bar = VtBarData() + bar.vtSymbol = symbol + bar.symbol = symbol + bar.open = float(d[2]) + bar.high = float(d[3]) + bar.low = float(d[4]) + bar.close = float(d[5]) + bar.date = str(d[0]) + + tempstr=str(round(float(d[1])*10000)).split(".")[0].zfill(4) + bar.time = tempstr[:2]+":"+tempstr[2:4]+":00" + + bar.datetime = datetime.strptime(bar.date + ' ' + bar.time, '%Y%m%d %H:%M:%S') + bar.volume = d[6] + bar.openInterest = d[7] + flt = {'datetime': bar.datetime} + collection.update_one(flt, {'$set':bar.__dict__}, upsert=True) + print bar.date, bar.time + + print u'插入完毕,耗时:%s' % (time()-start) + #---------------------------------------------------------------------- def loadTdxCsv(fileName, dbName, symbol):