Td Ameritrade Api 返回空 json 对历史 API 调用的响应
Td Ameritrade Api returning empty json reponse for historical API call
我正在尝试创建一个函数,该函数 return 为 python 中的某个交易品种提供一天的历史数据,并且 运行 遇到错误,每当我调用此函数时 return 对我来说:
[{'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)
这种奇怪行为背后的原因是,当我请求历史数据时,我将查询设置为小写,只有我将其更改为大写,它才能提取我需要的数据。
我正在尝试创建一个函数,该函数 return 为 python 中的某个交易品种提供一天的历史数据,并且 运行 遇到错误,每当我调用此函数时 return 对我来说:
[{'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)
这种奇怪行为背后的原因是,当我请求历史数据时,我将查询设置为小写,只有我将其更改为大写,它才能提取我需要的数据。