Skip to main content

TradingHours Library

Project description

TradingHours API Docs

TradingHours.com Python Library

TradingHours.com licenses Market Holidays and Trading Hours data for over 900 exchanges and trading venues around the world. This library allows clients to easily integrate our market holidays and trading hours data into existing applications. This packages downlods all available data from TradingHours.com and then allows you to work with the data locally.

A paid subscription is required to use this package

Learn more »

About the Data

Market coverage

We supports over 900 exchanges and trading venues, including all major currencies. See all supported markets.

Our comprehensive data covers:

  • Market holidays
  • Trading hours
  • Half-days / Irregular schedules
  • Non-settlement dates
  • Currency holidays
  • Detailed trading phases

How is data collected?

Our global research team collects and verifies trading hours and market holidays using exclusively primary sources. Manual and automated checks ensure the highest degree of accuracy and reliability.

Once data is collected, we then continually monitor for changes to ensure the data is always up-to-date. Data is updated daily.

Installation

pip install tradinghours

Basic Configuration

export TRADINGHOURS_TOKEN=<your-token-goes-here>

If you have an active subscription, click here to get your API key.

See advanced configuration options.

Usage

Importing Data

You just need to run the following command to download and import official data. Remember that you need to have a valid TRADINGHOURS_TOKEN environment variable.

$ tradinghours import
Downloading..... (0.824s)
Ingesting.......................... (12.066s)

You can then check current data status with the following subcommand:

$ tradinghours status --extended
Collecting timestamps.... (0.213s)
TradingHours Data Status:
  Remote Timestamp:   Thu Oct 26 02:08:17 2023
  Local Timestamp:    Thu Oct 26 03:12:40 2023

Reading local data.... (0.426s)
Extended Information:
  Currencies count:   30
  Markets count:      1012

List Markets

from tradinghours.market import Market

for market in Market.list_all():
    print(market)

Get Market

from tradinghours.market import Market

# Get by either FinID or MIC
market = Market.get('US.NYSE')
market = Market.get('XNYS')

If a market is marked "permanently closed" it may be replaced or superseded by another market. By default, the newer market will be returned automatically. You can still retrieve the older market object for historical analysis by using the follow=False parameter.

from tradinghours.market import Market

# AR.BCBA is permanently closed and replaced by AR.BYMA
market = Market.get('AR.BCBA')
original = Market.get('AR.BCBA', follow=False)

print(market.fin_id)  # AR.BYMA
print(original.fin_id)  # AR.BCBA

Market Holidays

from tradinghours.market import MarketHoliday

holidays = MarketHoliday.list_range('US.NYSE', "2024-01-01", "2024-12-31")
for holiday in holidays:
    print(holiday)

Trading Hours

from tradinghours.market import Market

market = Market.get('XNYS')
for concrete_phase in market.generate_schedules("2023-09-01", "2023-09-30"):
    print(concrete_phase)

List Currencies

from tradinghours.currency import Currency

for currency in Currency.list_all():
    print(currency)

Currency Holidays

from tradinghours.currency import Currency

currency = Currency.get('AUD')
for holiday in currency.list_holidays("2023-06-01", "2023-12-31"):
    print(currency)

Optional Advanced Configuration

By default, the library uses local file storage. Optionally you can configure the library to use an SQL store. You can adjust settings using a tradinghours.ini file on the current working directory.

Here is a sample configuration file using file system storage:

[api]
token = YOUR-TOKEN-HERE

[data]
use_db = False
local_dir = /srv/tradinghours/local
remote_dir = /srv/tradinghours/remote

And here you can see one using a local SQL Alchemy database. Note that you can use any valid Database URL:

[api]
token = YOUR-TOKEN-HERE

[data]
use_db = True
db_url = sqlite:///tradinghours.db

Database Schema

In case you would like to directly access the tables for the SQL mode, you can see that they all follow a very simple structure with keys for stored data and the data with actual JSON. The library uses this simple structure that should be compatible with nearly all database engines around.

Here is the DDL for the tables currently in use:

CREATE TABLE thstore_currencies (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_currency_holidays (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_holidays (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_markets (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_mic_mapping (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_schedules (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));
CREATE TABLE thstore_season_definitions (id INTEGER NOT NULL, slug VARCHAR, "key" VARCHAR, data JSON, PRIMARY KEY (id));

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradinghours-0.1.1.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

tradinghours-0.1.1-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file tradinghours-0.1.1.tar.gz.

File metadata

  • Download URL: tradinghours-0.1.1.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for tradinghours-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1c28b931980054302b16e2b77c9cad51a94f0c86e57c3d92cafb58c3fe856990
MD5 e3215f5fd68c206193914779f0f78211
BLAKE2b-256 ac1efb4301213998d6065985e955731d42385fb1c5ee10efba107960319b0f09

See more details on using hashes here.

File details

Details for the file tradinghours-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tradinghours-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e4d068cac06a19639331e530e16a99333285d4e9a8730097f24671c47ac9633
MD5 5b6188ccffdc2ea4f142d129bbd87f66
BLAKE2b-256 aadfa1df88f809411a2312e81880490843c8239774344b38e2126a9e411d94cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page