Merge branch 'dev' of https://github.com/vnpy/vnpy
This commit is contained in:
commit
d5fc1fc12d
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
# C++源代码
|
||||
# C++源代码
|
||||
ipch/
|
||||
Release/
|
||||
|
||||
@ -49,4 +49,5 @@ vn.lts/build/*
|
||||
|
||||
vn.trader/ctaAlgo/data/*
|
||||
vn.trader/build/*
|
||||
vn.trader/dist/*
|
||||
vn.trader/dist/*
|
||||
*.bak
|
||||
|
@ -436,6 +436,52 @@ def loadTdxCsv(fileName, dbName, symbol):
|
||||
|
||||
print u'插入完毕,耗时:%s' % (time()-start)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def loadTBCsv(fileName, dbName, symbol):
|
||||
"""将TradeBlazer导出的csv格式的历史数据插入到Mongo数据库中
|
||||
数据样本:
|
||||
//时间,开盘价,最高价,最低价,收盘价,成交量,持仓量
|
||||
2017/04/05 09:00,3200,3240,3173,3187,312690,2453850
|
||||
"""
|
||||
import csv
|
||||
|
||||
start = time()
|
||||
print u'开始读取CSV文件%s中的数据插入到%s的%s中' %(fileName, dbName, symbol)
|
||||
|
||||
# 锁定集合,并创建索引
|
||||
host, port, logging = loadMongoSetting()
|
||||
|
||||
client = pymongo.MongoClient(host, port)
|
||||
collection = client[dbName][symbol]
|
||||
collection.ensure_index([('datetime', pymongo.ASCENDING)], unique=True)
|
||||
|
||||
# 读取数据和插入到数据库
|
||||
reader = csv.reader(file(fileName, 'r'))
|
||||
for d in reader:
|
||||
if len(d[0]) > 10:
|
||||
bar = CtaBarData()
|
||||
bar.vtSymbol = symbol
|
||||
bar.symbol = symbol
|
||||
|
||||
bar.datetime = datetime.strptime(d[0], '%Y/%m/%d %H:%M')
|
||||
bar.date = bar.datetime.date().strftime('%Y%m%d')
|
||||
bar.time = bar.datetime.time().strftime('%H:%M:%S')
|
||||
|
||||
bar.open = float(d[1])
|
||||
bar.high = float(d[2])
|
||||
bar.low = float(d[3])
|
||||
bar.close = float(d[4])
|
||||
|
||||
bar.volume = float(d[5])
|
||||
bar.openInterest = float(d[6])
|
||||
|
||||
flt = {'datetime': bar.datetime}
|
||||
collection.update_one(flt, {'$set':bar.__dict__}, upsert=True)
|
||||
print '%s \t %s' % (bar.date, bar.time)
|
||||
|
||||
print u'插入完毕,耗时:%s' % (time()-start)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
## 简单的测试脚本可以写在这里
|
||||
#from time import sleep
|
||||
|
@ -87,11 +87,11 @@ ASK_PRICE_3 = u'Ask Price 3'
|
||||
ASK_PRICE_4 = u'Ask Price 4'
|
||||
ASK_PRICE_5 = u'Ask Price 5'
|
||||
|
||||
BID_VOLUME_1 = u'Bid Price 1'
|
||||
BID_VOLUME_2 = u'Bid Price 2'
|
||||
BID_VOLUME_3 = u'Bid Price 3'
|
||||
BID_VOLUME_4 = u'Bid Price 4'
|
||||
BID_VOLUME_5 = u'Bid Price 5'
|
||||
BID_VOLUME_1 = u'Bid Volume 1'
|
||||
BID_VOLUME_2 = u'Bid Volume 2'
|
||||
BID_VOLUME_3 = u'Bid Volume 3'
|
||||
BID_VOLUME_4 = u'Bid Volume 4'
|
||||
BID_VOLUME_5 = u'Bid Volume 5'
|
||||
ASK_VOLUME_1 = u'Ask Volume 1'
|
||||
ASK_VOLUME_2 = u'Ask Volume 2'
|
||||
ASK_VOLUME_3 = u'Ask Volume 3'
|
||||
|
Loading…
Reference in New Issue
Block a user