from tqsdk import TqApi, TqAuth # 初始化天勤API api = TqApi(auth=TqAuth("快期账户", "账户密码")) # 定义合约代码 symbols = ["CZCE.SPD FG501&FG505"] # 获取日K线数据 duration_seconds = 24 * 60 * 60 # 日K线数据 klines = {} for symbol in symbols: klines[symbol] = api.get_kline_serial(symbol, duration_seconds) # 等待数据更新完成 while True: api.wait_update() if all(api.is_changing(klines[symbol].iloc[-1], "datetime") for symbol in symbols): break # 打印日K线数据 for symbol in symbols: print(f"合约: {symbol}") print(klines[symbol][["datetime", "open", "high", "low", "close", "volume"]]) # 关闭API api.close()
其中的帐户,密码已修改为自己的信息
但实际运行时,,,发现会卡信,获得不到想要的信息