[Add]RQData数据服务新增对日线级别数据的支持
This commit is contained in:
parent
23d6399818
commit
aaa4b80a7c
@ -9,7 +9,7 @@ from time import time, sleep
|
||||
from pymongo import MongoClient, ASCENDING
|
||||
|
||||
from vnpy.trader.vtObject import VtBarData
|
||||
from vnpy.trader.app.ctaStrategy.ctaBase import MINUTE_DB_NAME
|
||||
from vnpy.trader.app.ctaStrategy.ctaBase import MINUTE_DB_NAME, DAILY_DB_NAME
|
||||
|
||||
import rqdatac as rq
|
||||
|
||||
@ -23,6 +23,7 @@ SYMBOLS = setting['SYMBOLS']
|
||||
|
||||
mc = MongoClient(MONGO_HOST, MONGO_PORT) # Mongo连接
|
||||
db = mc[MINUTE_DB_NAME] # 数据库
|
||||
db2 = mc[DAILY_DB_NAME]
|
||||
|
||||
USERNAME = setting['USERNAME']
|
||||
PASSWORD = setting['PASSWORD']
|
||||
@ -49,7 +50,7 @@ def generateVtBar(row, symbol):
|
||||
return bar
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def downMinuteBarBySymbol(symbol):
|
||||
def downloadMinuteBarBySymbol(symbol):
|
||||
"""下载某一合约的分钟线数据"""
|
||||
start = time()
|
||||
|
||||
@ -69,7 +70,28 @@ def downMinuteBarBySymbol(symbol):
|
||||
|
||||
print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, df.index[0], df.index[-1], cost))
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def downloadDailyBarBySymbol(symbol):
|
||||
"""下载某一合约日线数据"""
|
||||
start = time()
|
||||
|
||||
cl = db2[symbol]
|
||||
cl.ensure_index([('datetime', ASCENDING)], unique=True) # 添加索引
|
||||
|
||||
df = rq.get_price(symbol, frequency='1d', fields=FIELDS, end_date=datetime.now().strftime('%Y%m%d'))
|
||||
|
||||
for ix, row in df.iterrows():
|
||||
bar = generateVtBar(row, symbol)
|
||||
d = bar.__dict__
|
||||
flt = {'datetime': bar.datetime}
|
||||
cl.replace_one(flt, d, True)
|
||||
|
||||
end = time()
|
||||
cost = (end - start) * 1000
|
||||
|
||||
print(u'合约%s数据下载完成%s - %s,耗时%s毫秒' %(symbol, df.index[0], df.index[-1], cost))
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def downloadAllMinuteBar():
|
||||
"""下载所有配置中的合约的分钟线数据"""
|
||||
@ -79,12 +101,24 @@ def downloadAllMinuteBar():
|
||||
|
||||
# 添加下载任务
|
||||
for symbol in SYMBOLS:
|
||||
downMinuteBarBySymbol(str(symbol))
|
||||
downloadMinuteBarBySymbol(str(symbol))
|
||||
|
||||
print('-' * 50)
|
||||
print(u'合约分钟线数据下载完成')
|
||||
print('-' * 50)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def downloadAllDailyBar():
|
||||
"""下载所有配置中的合约的日数据"""
|
||||
print('-' * 50)
|
||||
print(u'开始下载合约日线数据')
|
||||
print('-' * 50)
|
||||
|
||||
|
||||
|
||||
# 添加下载任务
|
||||
for symbol in SYMBOLS:
|
||||
downloadDailyBarBySymbol(str(symbol))
|
||||
|
||||
print('-' * 50)
|
||||
print(u'合约日线数据下载完成')
|
||||
print('-' * 50)
|
||||
|
@ -8,5 +8,10 @@ from dataService import *
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
downMinuteBarBySymbol('IF1812')
|
||||
#downloadAllMinuteBar()
|
||||
#downloadMinuteBarBySymbol('IF1812')
|
||||
#downloadAllMinuteBar()
|
||||
#downloadMinuteBarBySymbol('CU99')
|
||||
downloadDailyBarBySymbol('CU99')
|
||||
downloadDailyBarBySymbol('IF99')
|
||||
downloadDailyBarBySymbol('TA99')
|
||||
downloadDailyBarBySymbol('I99')
|
Loading…
Reference in New Issue
Block a user