20190124 I1905.DCE 527.0 527.0 527.5 536.0 527.5 535.5 532.5 8.5 5.5 1251538.0 6670517.06 954964.0 63844.0
20190125 I1905.DCE 535.5 532.5 536.0 539.5 532.5 534.0 535.5 1.5 3.0 908006.0 4863058.50 970134.0 15170.0
20190128 I1905.DCE 534.0 535.5 534.0 567.5 533.0 550.5 553.5 15.0 18.0 1943090.0 10757050.83 937960.0 -32174.0
20190129 I1905.DCE 550.5 553.5 551.0 562.5 549.0 560.5 556.0 7.0 2.5 1325602.0 7373675.66 1016024.0 78064.0
20190130 I1905.DCE 560.5 556.0 562.5 589.0 562.0 587.0 578.0 31.0 22.0 1947148.0 11260593.93 1103674.0 87650.0
[177 rows x 14 columns]
Traceback (most recent call last):
File "C:/Users/Administrator.SKY-20150629PPO/Desktop/vnpy-1.9.2/examples/DataService/TushareDataService/downloadData.py", line 13, in <module>
downloadAllDailyBar()
File "C:\Users\Administrator.SKY-20150629PPO\Desktop\vnpy-1.9.2\examples\DataService\TushareDataService\futuredataService.py", line 118, in downloadAllDailyBar
downDailyBarBySymbol(str(symbol))
File "C:\Users\Administrator.SKY-20150629PPO\Desktop\vnpy-1.9.2\examples\DataService\TushareDataService\futuredataService.py", line 98, in downDailyBarBySymbol
bar = generateVtBar(row, symbol)
File "C:\Users\Administrator.SKY-20150629PPO\Desktop\vnpy-1.9.2\examples\DataService\TushareDataService\futuredataService.py", line 75, in generateVtBar
bar.date = bar.datetime.strftime("%Y%m%d")
AttributeError: 'unicode' object has no attribute 'strftime'
Process finished with exit code 1
----------------------------------------------------------------------
def generateVtBar(row, symbol):
"""生成K线"""
bar = VtBarData()
bar.symbol = symbol
bar.exchange = generateExchange(bar.symbol)
bar.vtSymbol = row['ts_code']
bar.open = row['open']
bar.high = row['high']
bar.low = row['low']
bar.close = row['close']
bar.volume = row['vol']
bar.datetime = row.name
bar.date = bar.datetime.strftime("%Y%m%d")
bar.time = bar.datetime.strftime("%H:%M:%S")
return bar
----------------------------------------------------------------------
def downDailyBarBySymbol(symbol):
"""下载某一合约的日线数据"""
start = time()
exchange = generateExchange(symbol)
symbol_code = str(symbol) + '.' + exchange
cl = db[symbol]
cl.ensure_index([('datetime', ASCENDING)], unique=True) # 添加索引
df = pro.fut_daily(ts_code=symbol_code, end_date=time1.strftime("%Y%m%d"))
pd.set_option('expand_frame_repr', False) # 当列太多时不换行
df.set_index(["trade_date"], inplace=True)
df = df.sort_index()
print(df)
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))