历史数据查询获取失败
问题描述
按API开发文档进行测试,但获取股票的历史数据一直失败,不知问题在哪儿?
代码例子
def get_historical_data(symbol): try: from datetime import datetime resp = quote_ctx.history_candlesticks_by_offset( symbol=symbol, period=Period.Week, # 周线数据 adjust_type=AdjustType.NoAdjust, # 不调整 is_forward=False, # 向后查询 start_time=datetime.now(), # 从当前时间向后查询 count=200 # 获取 200 周数据 ) print(f"{symbol}: 原始API响应={resp}") logging.info(f"{symbol}: 原始API响应={resp}") if not resp or not resp.candlesticks: print(f"{symbol}: 无数据返回,可能股票代码或网络问题") logging.error(f"{symbol}: 无数据返回,可能股票代码或网络问题") return pd.DataFrame() # 返回空 DataFrame df = pd.DataFrame([{ 'time': c.timestamp, 'open': float(c.open), 'high': float(c.high), 'low': float(c.low), 'close': float(c.close), 'volume': c.volume, 'turnover': float(c.turnover) if c.turnover else 0.0 } for c in resp.candlesticks]) df['time'] = pd.to_datetime(df['time'], unit='s') return df except Exception as e: logging.error(f"获取 {symbol} 历史数据失败:{e}") print(f"获取 {symbol} 历史数据失败:{e}") return pd.DataFrame() # 返回空 DataFrame
你的环境信息
- 操作系统: macOS
- 开发语言: Python
- SDK 版本号:2.1.12
报什么错?
报什么错?
QuoteContext.history_candlesticks_by_offset() got an unexpected keyword argument 'is_forward'
由于没有活动,此问题已关闭。如果您仍遇到此问题,请打开一个新问题并附上此问题的链接。 This issue was closed due to inactivity. If you still encounter this issue, please open a new issue and link to this issue. Thank you.