我正在尝试创建一个函数,该函数返回python中某个符号的日历史数据,并遇到一个错误,每当我调用此函数时,它都会返回给我:
[{'candles': [], 'symbol': 'snap', 'empty': True}, {'candles': [], 'symbol': 'fb', 'empty': True}]
我的预期输出将是其中蜡烛列表中填充有该特定库存数据的数据。到目前为止,这是我的代码:
def historical(symbols, key=TD_KEY, periodType="day", period=1, frequency="minute", needExtended=False):
# Gets historical data
return_list = []
for symbol in symbols:
url = f"/marketdata/{symbol}/pricehistory"
endpoint = f"{TD_URL}{url}"
payload = {"apikey":key,
"periodType": periodType,
"period": period,
"frequencyType": frequency,
"needExtendedHoursData": needExtended}
response = requests.get(url=endpoint, params=payload)
if str(response) == "<Response [200]>":
return_list.append(response.json())
else:
return f"Could not seccusfully connect http code {response}"
time.sleep(0.5)
答案 0 :(得分:0)
这种奇怪行为背后的原因是,当我请求历史数据时,我将查询小写,只有将其更改为大写,才能够提取所需的数据。