一、調(diào)用tushare的ts.pro_bar方法時報錯
def fetch_data(start_date, end_date):
'''
調(diào)tushare獲取所有股票的歷史價格
:param start_date: 歷史開始日期,str類型,%Y%m%d格式,包含當(dāng)天
:param end_date: 歷史結(jié)束日期,str類型,%Y%m%d格式,包含當(dāng)天
:return:
'''
for symbol in ALL_STOCK_LIST:
df = ts.pro_bar( # 關(guān)于pro_bar函數(shù)的參數(shù)說明參見 https://tushare.pro/document/2?doc_id=109
adj='hfq', # 量化模型一般都使用后復(fù)權(quán)
ts_code=symbol, start_date=start_date, end_date=end_date)
df = df[['trade_date', 'open', 'high', 'low', 'close', 'vol']] # 只選取所需要的列
df.sort_values(by='trade_date', inplace=True) # 按日期升序排列(默認(rèn)是按日期降序排)
df.to_csv(os.path.join(OHLCV_DIR, symbol), index=False) # 價格數(shù)據(jù)寫入文件,文件名就是股票代碼

error.png
二、可能原因及解決方案:
1.未注冊
注冊地址: https://tushare.pro/register?reg=564135
2.積分不足
獲取積分方法:https://tushare.pro/document/1?doc_id=13