Does anyone know how to get the hours for markets such as the NYSE on TD Ameritrade API?

497 Views Asked by At

I'm trying to request hour information from the TD Ameritrade API. Is there any way I could get the hours for the New York Stock Exchange?

Here is the link to the API: https://developer.tdameritrade.com/

2

There are 2 best solutions below

1
On BEST ANSWER

TD Ameritrade's API provides an endpoint for market hours however you can't specify which exchange to check, only which market (BOND, EQUITY, ETF etc..).

For some reason, it allows you to specify which date but it only accepts the current date. Providing an access token doesn't do anything so I won't be including a header with the token in my example.

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')

According to their site, most of NYSE is open 06:30 - 20:00 EST, it might be easier to just check if the current time is within that timeframe and if the current day is not a holiday.

0
On

There is a widget and JSON feed on https://www.isthemarketopen.com/ - It's an atomic clock for the U.S. Stock Market

Here is the code to simply embed their widget:

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

Here is their JSON feed

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