我正在尝试创建一个函数,它返回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)发布于 2020-07-24 07:56:04
这种奇怪行为背后的原因是,当我请求历史数据时,我将查询放在小写字母,只有我把它改为大写字母,它才能拉下我需要的数据。
https://stackoverflow.com/questions/63044602
复制相似问题