增加将OKEX下载的数据导入到数据库
This commit is contained in:
parent
d3302c2a75
commit
67227beaa9
@ -208,5 +208,41 @@ def loadTdxCsv(fileName, dbName, symbol):
|
|||||||
print bar.date, bar.time
|
print bar.date, bar.time
|
||||||
|
|
||||||
print u'插入完毕,耗时:%s' % (time()-start)
|
print u'插入完毕,耗时:%s' % (time()-start)
|
||||||
|
def loadOKEXCsv(fileName, dbName, symbol):
|
||||||
|
"""将OKEX导出的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(open(fileName,"r"))
|
||||||
|
for d in reader:
|
||||||
|
if len(d[1]) > 10:
|
||||||
|
bar = VtBarData()
|
||||||
|
bar.vtSymbol = symbol
|
||||||
|
bar.symbol = symbol
|
||||||
|
|
||||||
|
bar.datetime = datetime.strptime(d[1], '%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[2])
|
||||||
|
bar.high = float(d[3])
|
||||||
|
bar.low = float(d[4])
|
||||||
|
bar.close = float(d[5])
|
||||||
|
|
||||||
|
bar.volume = float(d[6])
|
||||||
|
bar.tobtcvolume = float(d[7])
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user