有人知道如何在TD Ameritrade API上获得纽约证交所等市场的营业时间吗



我正试图向德美利API索取工时信息。有什么办法可以让我得到纽约证券交易所的营业时间吗?

以下是API的链接:https://developer.tdameritrade.com/

TD Ameritrade的API提供了市场时间的终点,但您无法指定要检查的交易所,只能指定检查的市场(BOND、EQUITY、ETF等(。

出于某种原因,它允许您指定日期,但只接受当前日期。提供访问令牌没有任何作用,所以在我的示例中,我不会在令牌中包含标头。

import json
import urllib.request
api_key = 'PRIVATE'

def get_market_hours(market, date):
params = f'?apikey={api_key}&date={date}'
url = f'https://api.tdameritrade.com/v1/marketdata/{market}/hours' + params
with urllib.request.urlopen(url) as response:
text_bytes = response.read()
text_str = text_bytes.decode('utf-8')
text_json = json.loads(text_str)
print(text_json)

get_market_hours('EQUITY', '2020-12-23')

根据他们的网站,纽约证券交易所的大部分时间是美国东部时间06:30-20:00,只需检查当前时间是否在该时间范围内以及当天是否不是假期可能会更容易。

https://www.isthemarketopen.com/-这是美国股市的原子钟

以下是简单嵌入其小部件的代码:

<iframe src="https://www.isthemarketopen.com/widget/#/" width="565" height="200" frameBorder="0">Browser not compatible.</iframe>

这是他们的JSON提要

https://www.isthemarketopen.com/static/markets.json

最新更新