我正在尝试创建一个函数,该函数返回 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)