tradingcalendars-client 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tradingcalendars_client-0.1.0/LICENSE +21 -0
- tradingcalendars_client-0.1.0/PKG-INFO +117 -0
- tradingcalendars_client-0.1.0/README.md +92 -0
- tradingcalendars_client-0.1.0/pyproject.toml +44 -0
- tradingcalendars_client-0.1.0/setup.cfg +4 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars/__init__.py +23 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars/client.py +208 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars/errors.py +22 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars/py.typed +0 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars_client.egg-info/PKG-INFO +117 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars_client.egg-info/SOURCES.txt +12 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars_client.egg-info/dependency_links.txt +1 -0
- tradingcalendars_client-0.1.0/src/tradingcalendars_client.egg-info/top_level.txt +1 -0
- tradingcalendars_client-0.1.0/tests/test_client.py +122 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JDE Ventures
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tradingcalendars-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Business days, T+N settlement dates and holidays for FX, banks, payment systems and exchanges (TradingCalendars.com API client).
|
|
5
|
+
Author-email: "JDE Ventures (TradingCalendars.com)" <contact@tradingcalendars.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://tradingcalendars.com
|
|
8
|
+
Project-URL: Documentation, https://tradingcalendars.com/documentation
|
|
9
|
+
Project-URL: API key (free), https://tradingcalendars.com/signup?ref=pypi
|
|
10
|
+
Project-URL: Source, https://github.com/jdesaunay/tradingcalendars-python
|
|
11
|
+
Keywords: holidays,business days,settlement,trading calendar,market holidays,bank holidays,fx,value date,exchange calendar,TARGET2,NYSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
19
|
+
Classifier: Topic :: Office/Business :: Scheduling
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# tradingcalendars
|
|
27
|
+
|
|
28
|
+
Python client for the [TradingCalendars.com](https://tradingcalendars.com) API: **business days,
|
|
29
|
+
T+N settlement dates and holidays** for FX markets, currency clearing, bank holidays, payment
|
|
30
|
+
systems (TARGET2, Fedwire, CHAPS…) and stock exchanges, including half days and early closes.
|
|
31
|
+
|
|
32
|
+
- 50 currencies, 69 financial centres, 29 payment systems, 61 exchanges ([coverage](https://tradingcalendars.com/coverage))
|
|
33
|
+
- Maintained from official sources, past and future years
|
|
34
|
+
- Standard library only, Python 3.9+
|
|
35
|
+
- Installs as `tradingcalendars-client`, imports as `tradingcalendars`
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install tradingcalendars-client
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Get a free API key (a minute, no card): https://tradingcalendars.com/signup?ref=pypi
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from tradingcalendars import TradingCalendars
|
|
49
|
+
|
|
50
|
+
tc = TradingCalendars(api_key="YOUR_API_KEY") # or set TRADINGCALENDARS_API_KEY
|
|
51
|
+
|
|
52
|
+
# T+2 value date for a EUR/USD trade done on 23 December 2026
|
|
53
|
+
tc.add_business_days(["USD.FX", "EUR.FX"], "2026-12-23", 2)
|
|
54
|
+
# datetime.date(2026, 12, 28) -> skips Christmas and the weekend
|
|
55
|
+
|
|
56
|
+
# Is a date open in several calendars at once?
|
|
57
|
+
tc.is_business_day(["TARGET2.PAY", "FEDWIRE.PAY"], "2026-12-28") # True
|
|
58
|
+
|
|
59
|
+
# Business days between two dates (start counted, end not)
|
|
60
|
+
tc.business_days_between(["GBP.FX", "SGD.FX"], "2027-01-01", "2027-02-01") # 20
|
|
61
|
+
|
|
62
|
+
# Holidays, with half days and early closes
|
|
63
|
+
for h in tc.holidays("XLON.TRADE", start="2026-12-01", end="2026-12-31"):
|
|
64
|
+
print(h.date, h.event, h.early_close_time or "")
|
|
65
|
+
# 2026-12-24 Christmas Eve (half day) 12:30
|
|
66
|
+
# 2026-12-25 Christmas Day
|
|
67
|
+
# 2026-12-28 Boxing Day
|
|
68
|
+
# 2026-12-31 New Year's Eve (half day) 12:30
|
|
69
|
+
|
|
70
|
+
# Is the New York Stock Exchange open right now?
|
|
71
|
+
tc.market_status("XNYS")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Every `*_details` variant (`add_business_days_details`, `is_business_day_details`,
|
|
75
|
+
`business_days_between_details`) returns the full answer, including each skipped day and why.
|
|
76
|
+
|
|
77
|
+
## With pandas or numpy
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import pandas as pd
|
|
81
|
+
|
|
82
|
+
closures = tc.closure_dates("XNYS.TRADE", start="2026-01-01", end="2027-12-31")
|
|
83
|
+
nyse_day = pd.offsets.CustomBusinessDay(holidays=closures)
|
|
84
|
+
pd.Timestamp("2026-11-25") + 2 * nyse_day # skips Thanksgiving
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Calendar codes
|
|
88
|
+
|
|
89
|
+
| Family | Code | Example |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| FX market | `<ISO 4217>.FX` | `USD.FX`, `EUR.FX` |
|
|
92
|
+
| Currency non-clearing days | `<ISO 4217>.CLEAR` | `USD.CLEAR` |
|
|
93
|
+
| Bank holidays (financial centre) | `<UN/LOCODE>.BANK` | `GBLON.BANK`, `USNYC.BANK` |
|
|
94
|
+
| Payment systems | `<SYSTEM>.PAY` | `TARGET2.PAY`, `FEDWIRE.PAY` |
|
|
95
|
+
| Exchange trading | `<MIC>.TRADE` | `XNYS.TRADE`, `XLON.TRADE` |
|
|
96
|
+
| Exchange settlement | `<MIC>.SETTLE` | `XNYS.SETTLE` |
|
|
97
|
+
|
|
98
|
+
`tc.calendars()` lists every code your plan covers. Browse them at
|
|
99
|
+
[tradingcalendars.com/coverage](https://tradingcalendars.com/coverage).
|
|
100
|
+
|
|
101
|
+
## Errors
|
|
102
|
+
|
|
103
|
+
`AuthenticationError` (401/403), `NotFoundError` (404), `RateLimitError` (429, resets at
|
|
104
|
+
midnight UTC) and `TradingCalendarsError` for anything else. Messages come from the API and say
|
|
105
|
+
what to do next.
|
|
106
|
+
|
|
107
|
+
## Also available
|
|
108
|
+
|
|
109
|
+
- REST API reference: https://tradingcalendars.com/documentation
|
|
110
|
+
- MCP server for Claude, ChatGPT and Cursor: https://tradingcalendars.com/mcp
|
|
111
|
+
- Calendar subscriptions (Google Calendar, Outlook, Apple): a "Subscribe" box on every
|
|
112
|
+
calendar page, e.g. https://tradingcalendars.com/calendars/XNYS.TRADE
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT. The data itself is provided under the
|
|
117
|
+
[TradingCalendars.com terms](https://tradingcalendars.com/terms-and-conditions).
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# tradingcalendars
|
|
2
|
+
|
|
3
|
+
Python client for the [TradingCalendars.com](https://tradingcalendars.com) API: **business days,
|
|
4
|
+
T+N settlement dates and holidays** for FX markets, currency clearing, bank holidays, payment
|
|
5
|
+
systems (TARGET2, Fedwire, CHAPS…) and stock exchanges, including half days and early closes.
|
|
6
|
+
|
|
7
|
+
- 50 currencies, 69 financial centres, 29 payment systems, 61 exchanges ([coverage](https://tradingcalendars.com/coverage))
|
|
8
|
+
- Maintained from official sources, past and future years
|
|
9
|
+
- Standard library only, Python 3.9+
|
|
10
|
+
- Installs as `tradingcalendars-client`, imports as `tradingcalendars`
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install tradingcalendars-client
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Get a free API key (a minute, no card): https://tradingcalendars.com/signup?ref=pypi
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from tradingcalendars import TradingCalendars
|
|
24
|
+
|
|
25
|
+
tc = TradingCalendars(api_key="YOUR_API_KEY") # or set TRADINGCALENDARS_API_KEY
|
|
26
|
+
|
|
27
|
+
# T+2 value date for a EUR/USD trade done on 23 December 2026
|
|
28
|
+
tc.add_business_days(["USD.FX", "EUR.FX"], "2026-12-23", 2)
|
|
29
|
+
# datetime.date(2026, 12, 28) -> skips Christmas and the weekend
|
|
30
|
+
|
|
31
|
+
# Is a date open in several calendars at once?
|
|
32
|
+
tc.is_business_day(["TARGET2.PAY", "FEDWIRE.PAY"], "2026-12-28") # True
|
|
33
|
+
|
|
34
|
+
# Business days between two dates (start counted, end not)
|
|
35
|
+
tc.business_days_between(["GBP.FX", "SGD.FX"], "2027-01-01", "2027-02-01") # 20
|
|
36
|
+
|
|
37
|
+
# Holidays, with half days and early closes
|
|
38
|
+
for h in tc.holidays("XLON.TRADE", start="2026-12-01", end="2026-12-31"):
|
|
39
|
+
print(h.date, h.event, h.early_close_time or "")
|
|
40
|
+
# 2026-12-24 Christmas Eve (half day) 12:30
|
|
41
|
+
# 2026-12-25 Christmas Day
|
|
42
|
+
# 2026-12-28 Boxing Day
|
|
43
|
+
# 2026-12-31 New Year's Eve (half day) 12:30
|
|
44
|
+
|
|
45
|
+
# Is the New York Stock Exchange open right now?
|
|
46
|
+
tc.market_status("XNYS")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Every `*_details` variant (`add_business_days_details`, `is_business_day_details`,
|
|
50
|
+
`business_days_between_details`) returns the full answer, including each skipped day and why.
|
|
51
|
+
|
|
52
|
+
## With pandas or numpy
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import pandas as pd
|
|
56
|
+
|
|
57
|
+
closures = tc.closure_dates("XNYS.TRADE", start="2026-01-01", end="2027-12-31")
|
|
58
|
+
nyse_day = pd.offsets.CustomBusinessDay(holidays=closures)
|
|
59
|
+
pd.Timestamp("2026-11-25") + 2 * nyse_day # skips Thanksgiving
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Calendar codes
|
|
63
|
+
|
|
64
|
+
| Family | Code | Example |
|
|
65
|
+
| --- | --- | --- |
|
|
66
|
+
| FX market | `<ISO 4217>.FX` | `USD.FX`, `EUR.FX` |
|
|
67
|
+
| Currency non-clearing days | `<ISO 4217>.CLEAR` | `USD.CLEAR` |
|
|
68
|
+
| Bank holidays (financial centre) | `<UN/LOCODE>.BANK` | `GBLON.BANK`, `USNYC.BANK` |
|
|
69
|
+
| Payment systems | `<SYSTEM>.PAY` | `TARGET2.PAY`, `FEDWIRE.PAY` |
|
|
70
|
+
| Exchange trading | `<MIC>.TRADE` | `XNYS.TRADE`, `XLON.TRADE` |
|
|
71
|
+
| Exchange settlement | `<MIC>.SETTLE` | `XNYS.SETTLE` |
|
|
72
|
+
|
|
73
|
+
`tc.calendars()` lists every code your plan covers. Browse them at
|
|
74
|
+
[tradingcalendars.com/coverage](https://tradingcalendars.com/coverage).
|
|
75
|
+
|
|
76
|
+
## Errors
|
|
77
|
+
|
|
78
|
+
`AuthenticationError` (401/403), `NotFoundError` (404), `RateLimitError` (429, resets at
|
|
79
|
+
midnight UTC) and `TradingCalendarsError` for anything else. Messages come from the API and say
|
|
80
|
+
what to do next.
|
|
81
|
+
|
|
82
|
+
## Also available
|
|
83
|
+
|
|
84
|
+
- REST API reference: https://tradingcalendars.com/documentation
|
|
85
|
+
- MCP server for Claude, ChatGPT and Cursor: https://tradingcalendars.com/mcp
|
|
86
|
+
- Calendar subscriptions (Google Calendar, Outlook, Apple): a "Subscribe" box on every
|
|
87
|
+
calendar page, e.g. https://tradingcalendars.com/calendars/XNYS.TRADE
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT. The data itself is provided under the
|
|
92
|
+
[TradingCalendars.com terms](https://tradingcalendars.com/terms-and-conditions).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tradingcalendars-client"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Business days, T+N settlement dates and holidays for FX, banks, payment systems and exchanges (TradingCalendars.com API client)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "JDE Ventures (TradingCalendars.com)", email = "contact@tradingcalendars.com" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"holidays", "business days", "settlement", "trading calendar", "market holidays",
|
|
15
|
+
"bank holidays", "fx", "value date", "exchange calendar", "TARGET2", "NYSE",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Topic :: Office/Business :: Financial",
|
|
25
|
+
"Topic :: Office/Business :: Scheduling",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
dependencies = []
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://tradingcalendars.com"
|
|
32
|
+
Documentation = "https://tradingcalendars.com/documentation"
|
|
33
|
+
"API key (free)" = "https://tradingcalendars.com/signup?ref=pypi"
|
|
34
|
+
Source = "https://github.com/jdesaunay/tradingcalendars-python"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
where = ["src"]
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.package-data]
|
|
40
|
+
tradingcalendars = ["py.typed"]
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
pythonpath = ["src"]
|
|
44
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Python client for the TradingCalendars.com API.
|
|
2
|
+
|
|
3
|
+
Business days, settlement dates and holidays for FX, currency clearing,
|
|
4
|
+
banks, payment systems and exchanges. Docs: https://tradingcalendars.com/documentation
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from tradingcalendars.client import Holiday, TradingCalendars
|
|
8
|
+
from tradingcalendars.errors import (
|
|
9
|
+
AuthenticationError,
|
|
10
|
+
NotFoundError,
|
|
11
|
+
RateLimitError,
|
|
12
|
+
TradingCalendarsError,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"AuthenticationError",
|
|
17
|
+
"Holiday",
|
|
18
|
+
"NotFoundError",
|
|
19
|
+
"RateLimitError",
|
|
20
|
+
"TradingCalendars",
|
|
21
|
+
"TradingCalendarsError",
|
|
22
|
+
]
|
|
23
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""HTTP client (standard library only)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import urllib.error
|
|
8
|
+
import urllib.parse
|
|
9
|
+
import urllib.request
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from datetime import date
|
|
12
|
+
from typing import Any, Optional, Sequence, Union
|
|
13
|
+
|
|
14
|
+
from tradingcalendars.errors import (
|
|
15
|
+
AuthenticationError,
|
|
16
|
+
NotFoundError,
|
|
17
|
+
RateLimitError,
|
|
18
|
+
TradingCalendarsError,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
DEFAULT_BASE_URL = "https://api.tradingcalendars.com/v1"
|
|
22
|
+
USER_AGENT = "tradingcalendars-python/0.1.0"
|
|
23
|
+
|
|
24
|
+
DateLike = Union[date, str]
|
|
25
|
+
Calendars = Union[str, Sequence[str]]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _iso(value: Optional[DateLike]) -> Optional[str]:
|
|
29
|
+
if value is None:
|
|
30
|
+
return None
|
|
31
|
+
return value.isoformat() if isinstance(value, date) else str(value)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _codes(calendars: Calendars) -> str:
|
|
35
|
+
if isinstance(calendars, str):
|
|
36
|
+
return calendars
|
|
37
|
+
return ",".join(calendars)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _parse_date(value: Optional[str]) -> Optional[date]:
|
|
41
|
+
return date.fromisoformat(value) if value else None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class Holiday:
|
|
46
|
+
"""One holiday row. ``is_half_day`` rows are shortened business days, not closures."""
|
|
47
|
+
|
|
48
|
+
date: date
|
|
49
|
+
event: str
|
|
50
|
+
is_half_day: bool = False
|
|
51
|
+
half_day: str = "NONE"
|
|
52
|
+
early_close_time: Optional[str] = None
|
|
53
|
+
is_observed: bool = False
|
|
54
|
+
original_date: Optional[date] = None
|
|
55
|
+
is_estimated: bool = False
|
|
56
|
+
is_bridge: bool = False
|
|
57
|
+
name_local: Optional[str] = None
|
|
58
|
+
source: Optional[str] = None
|
|
59
|
+
notes: Optional[str] = None
|
|
60
|
+
raw: dict = field(default_factory=dict, repr=False, compare=False)
|
|
61
|
+
|
|
62
|
+
@classmethod
|
|
63
|
+
def from_api(cls, row: dict) -> "Holiday":
|
|
64
|
+
return cls(
|
|
65
|
+
date=date.fromisoformat(row["date"]),
|
|
66
|
+
event=row.get("event", ""),
|
|
67
|
+
is_half_day=bool(row.get("is_half_day")),
|
|
68
|
+
half_day=row.get("half_day") or "NONE",
|
|
69
|
+
early_close_time=row.get("early_close_time"),
|
|
70
|
+
is_observed=bool(row.get("is_observed")),
|
|
71
|
+
original_date=_parse_date(row.get("original_date")),
|
|
72
|
+
is_estimated=bool(row.get("is_estimated")),
|
|
73
|
+
is_bridge=bool(row.get("is_bridge")),
|
|
74
|
+
name_local=row.get("name_local"),
|
|
75
|
+
source=row.get("source"),
|
|
76
|
+
notes=row.get("notes"),
|
|
77
|
+
raw=row,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class TradingCalendars:
|
|
82
|
+
"""Client for https://api.tradingcalendars.com/v1.
|
|
83
|
+
|
|
84
|
+
>>> tc = TradingCalendars(api_key="YOUR_API_KEY") # or set TRADINGCALENDARS_API_KEY
|
|
85
|
+
>>> tc.add_business_days(["USD.FX", "EUR.FX"], "2026-12-23", 2)
|
|
86
|
+
datetime.date(2026, 12, 28)
|
|
87
|
+
|
|
88
|
+
Get a free key at https://tradingcalendars.com/signup?ref=pypi
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
api_key: Optional[str] = None,
|
|
94
|
+
*,
|
|
95
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
96
|
+
timeout: float = 30.0,
|
|
97
|
+
):
|
|
98
|
+
self.api_key = api_key or os.environ.get("TRADINGCALENDARS_API_KEY")
|
|
99
|
+
if not self.api_key:
|
|
100
|
+
raise AuthenticationError(
|
|
101
|
+
401,
|
|
102
|
+
"No API key. Pass api_key=... or set TRADINGCALENDARS_API_KEY. "
|
|
103
|
+
"A free key takes a minute: https://tradingcalendars.com/signup?ref=pypi",
|
|
104
|
+
)
|
|
105
|
+
self.base_url = base_url.rstrip("/")
|
|
106
|
+
self.timeout = timeout
|
|
107
|
+
|
|
108
|
+
# ---- transport -------------------------------------------------------
|
|
109
|
+
def _get(self, path: str, params: Optional[dict] = None) -> Any:
|
|
110
|
+
query = {k: v for k, v in (params or {}).items() if v is not None}
|
|
111
|
+
url = f"{self.base_url}{path}"
|
|
112
|
+
if query:
|
|
113
|
+
url += "?" + urllib.parse.urlencode(query)
|
|
114
|
+
request = urllib.request.Request(
|
|
115
|
+
url,
|
|
116
|
+
headers={
|
|
117
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
118
|
+
"Accept": "application/json",
|
|
119
|
+
"User-Agent": USER_AGENT,
|
|
120
|
+
},
|
|
121
|
+
)
|
|
122
|
+
try:
|
|
123
|
+
with urllib.request.urlopen(request, timeout=self.timeout) as response:
|
|
124
|
+
return json.loads(response.read().decode("utf-8"))
|
|
125
|
+
except urllib.error.HTTPError as exc:
|
|
126
|
+
raise _error_from(exc) from None
|
|
127
|
+
|
|
128
|
+
# ---- business days ---------------------------------------------------
|
|
129
|
+
def is_business_day(self, calendars: Calendars, day: Optional[DateLike] = None) -> bool:
|
|
130
|
+
"""True when ``day`` (default today) is open in every calendar given."""
|
|
131
|
+
return bool(self.is_business_day_details(calendars, day)["is_business_day"])
|
|
132
|
+
|
|
133
|
+
def is_business_day_details(self, calendars: Calendars, day: Optional[DateLike] = None) -> dict:
|
|
134
|
+
"""Full answer, including why each calendar is closed (holiday name, weekend)."""
|
|
135
|
+
return self._get("/is-business-day", {"calendars": _codes(calendars), "date": _iso(day)})
|
|
136
|
+
|
|
137
|
+
def add_business_days(self, calendars: Calendars, day: Optional[DateLike], days: int) -> date:
|
|
138
|
+
"""Date ``days`` business days after ``day`` (negative goes back). T+2 = 2."""
|
|
139
|
+
return date.fromisoformat(self.add_business_days_details(calendars, day, days)["result"])
|
|
140
|
+
|
|
141
|
+
def add_business_days_details(self, calendars: Calendars, day: Optional[DateLike], days: int) -> dict:
|
|
142
|
+
"""Full answer, including every skipped day and why."""
|
|
143
|
+
return self._get(
|
|
144
|
+
"/add-business-days",
|
|
145
|
+
{"calendars": _codes(calendars), "date": _iso(day), "days": days},
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
def business_days_between(self, calendars: Calendars, start: DateLike, end: DateLike) -> int:
|
|
149
|
+
"""Business days from ``start`` (counted) to ``end`` (not counted)."""
|
|
150
|
+
return int(self.business_days_between_details(calendars, start, end)["business_days"])
|
|
151
|
+
|
|
152
|
+
def business_days_between_details(self, calendars: Calendars, start: DateLike, end: DateLike) -> dict:
|
|
153
|
+
return self._get(
|
|
154
|
+
"/business-days-between",
|
|
155
|
+
{"calendars": _codes(calendars), "start": _iso(start), "end": _iso(end)},
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# ---- holidays --------------------------------------------------------
|
|
159
|
+
def holidays(
|
|
160
|
+
self,
|
|
161
|
+
calendar: str,
|
|
162
|
+
start: Optional[DateLike] = None,
|
|
163
|
+
end: Optional[DateLike] = None,
|
|
164
|
+
) -> list:
|
|
165
|
+
"""Holidays for one calendar code (e.g. ``XNYS.TRADE``), from ``start`` (default today)."""
|
|
166
|
+
payload = self._get("/holidays", {"calendar": calendar, "start": _iso(start), "end": _iso(end)})
|
|
167
|
+
return [Holiday.from_api(row) for row in payload.get("data", [])]
|
|
168
|
+
|
|
169
|
+
def closure_dates(
|
|
170
|
+
self,
|
|
171
|
+
calendar: str,
|
|
172
|
+
start: Optional[DateLike] = None,
|
|
173
|
+
end: Optional[DateLike] = None,
|
|
174
|
+
) -> list:
|
|
175
|
+
"""Full-closure dates only (half days excluded), ready for numpy/pandas business-day
|
|
176
|
+
helpers, e.g. ``pandas.offsets.CustomBusinessDay(holidays=...)``."""
|
|
177
|
+
return [h.date for h in self.holidays(calendar, start, end) if not h.is_half_day]
|
|
178
|
+
|
|
179
|
+
def weekends(self, calendar: str) -> dict:
|
|
180
|
+
"""Weekend definition in force (ISO weekdays) and its history."""
|
|
181
|
+
return self._get("/weekends", {"calendar": calendar})
|
|
182
|
+
|
|
183
|
+
# ---- reference & live ------------------------------------------------
|
|
184
|
+
def calendars(self, calendar_type: Optional[str] = None) -> list:
|
|
185
|
+
"""Published calendars your plan covers (``calendar_type`` e.g. ``CURRENCY_FX``)."""
|
|
186
|
+
return self._get("/calendars", {"calendar_type": calendar_type}).get("data", [])
|
|
187
|
+
|
|
188
|
+
def market_status(self, market: Optional[str] = None) -> list:
|
|
189
|
+
"""Live open / half day / closed status, with next open and close (MIC, e.g. ``XNYS``)."""
|
|
190
|
+
return self._get("/market-status", {"market": market}).get("data", [])
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _error_from(exc: urllib.error.HTTPError) -> TradingCalendarsError:
|
|
194
|
+
try:
|
|
195
|
+
body = json.loads(exc.read().decode("utf-8"))
|
|
196
|
+
message = body.get("detail") if isinstance(body, dict) else str(body)
|
|
197
|
+
except Exception:
|
|
198
|
+
message = exc.reason
|
|
199
|
+
message = str(message or exc.reason)
|
|
200
|
+
if exc.code in (401, 403):
|
|
201
|
+
return AuthenticationError(exc.code, message)
|
|
202
|
+
if exc.code == 404:
|
|
203
|
+
return NotFoundError(exc.code, message)
|
|
204
|
+
if exc.code == 429:
|
|
205
|
+
return RateLimitError(exc.code, message)
|
|
206
|
+
return TradingCalendarsError(exc.code, message)
|
|
207
|
+
|
|
208
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Errors raised by the client. Messages come from the API and say what to do next."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TradingCalendarsError(Exception):
|
|
5
|
+
"""Any error answer from the API (status code and message)."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, status: int, message: str):
|
|
8
|
+
super().__init__(f"{status}: {message}")
|
|
9
|
+
self.status = status
|
|
10
|
+
self.message = message
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuthenticationError(TradingCalendarsError):
|
|
14
|
+
"""401 missing or invalid API key, or 403 (unconfirmed email, plan does not cover it)."""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class NotFoundError(TradingCalendarsError):
|
|
18
|
+
"""404 unknown calendar, currency, exchange or centre."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RateLimitError(TradingCalendarsError):
|
|
22
|
+
"""429 daily call limit reached; it resets at midnight UTC."""
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tradingcalendars-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Business days, T+N settlement dates and holidays for FX, banks, payment systems and exchanges (TradingCalendars.com API client).
|
|
5
|
+
Author-email: "JDE Ventures (TradingCalendars.com)" <contact@tradingcalendars.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://tradingcalendars.com
|
|
8
|
+
Project-URL: Documentation, https://tradingcalendars.com/documentation
|
|
9
|
+
Project-URL: API key (free), https://tradingcalendars.com/signup?ref=pypi
|
|
10
|
+
Project-URL: Source, https://github.com/jdesaunay/tradingcalendars-python
|
|
11
|
+
Keywords: holidays,business days,settlement,trading calendar,market holidays,bank holidays,fx,value date,exchange calendar,TARGET2,NYSE
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
19
|
+
Classifier: Topic :: Office/Business :: Scheduling
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# tradingcalendars
|
|
27
|
+
|
|
28
|
+
Python client for the [TradingCalendars.com](https://tradingcalendars.com) API: **business days,
|
|
29
|
+
T+N settlement dates and holidays** for FX markets, currency clearing, bank holidays, payment
|
|
30
|
+
systems (TARGET2, Fedwire, CHAPS…) and stock exchanges, including half days and early closes.
|
|
31
|
+
|
|
32
|
+
- 50 currencies, 69 financial centres, 29 payment systems, 61 exchanges ([coverage](https://tradingcalendars.com/coverage))
|
|
33
|
+
- Maintained from official sources, past and future years
|
|
34
|
+
- Standard library only, Python 3.9+
|
|
35
|
+
- Installs as `tradingcalendars-client`, imports as `tradingcalendars`
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install tradingcalendars-client
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Get a free API key (a minute, no card): https://tradingcalendars.com/signup?ref=pypi
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from tradingcalendars import TradingCalendars
|
|
49
|
+
|
|
50
|
+
tc = TradingCalendars(api_key="YOUR_API_KEY") # or set TRADINGCALENDARS_API_KEY
|
|
51
|
+
|
|
52
|
+
# T+2 value date for a EUR/USD trade done on 23 December 2026
|
|
53
|
+
tc.add_business_days(["USD.FX", "EUR.FX"], "2026-12-23", 2)
|
|
54
|
+
# datetime.date(2026, 12, 28) -> skips Christmas and the weekend
|
|
55
|
+
|
|
56
|
+
# Is a date open in several calendars at once?
|
|
57
|
+
tc.is_business_day(["TARGET2.PAY", "FEDWIRE.PAY"], "2026-12-28") # True
|
|
58
|
+
|
|
59
|
+
# Business days between two dates (start counted, end not)
|
|
60
|
+
tc.business_days_between(["GBP.FX", "SGD.FX"], "2027-01-01", "2027-02-01") # 20
|
|
61
|
+
|
|
62
|
+
# Holidays, with half days and early closes
|
|
63
|
+
for h in tc.holidays("XLON.TRADE", start="2026-12-01", end="2026-12-31"):
|
|
64
|
+
print(h.date, h.event, h.early_close_time or "")
|
|
65
|
+
# 2026-12-24 Christmas Eve (half day) 12:30
|
|
66
|
+
# 2026-12-25 Christmas Day
|
|
67
|
+
# 2026-12-28 Boxing Day
|
|
68
|
+
# 2026-12-31 New Year's Eve (half day) 12:30
|
|
69
|
+
|
|
70
|
+
# Is the New York Stock Exchange open right now?
|
|
71
|
+
tc.market_status("XNYS")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Every `*_details` variant (`add_business_days_details`, `is_business_day_details`,
|
|
75
|
+
`business_days_between_details`) returns the full answer, including each skipped day and why.
|
|
76
|
+
|
|
77
|
+
## With pandas or numpy
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import pandas as pd
|
|
81
|
+
|
|
82
|
+
closures = tc.closure_dates("XNYS.TRADE", start="2026-01-01", end="2027-12-31")
|
|
83
|
+
nyse_day = pd.offsets.CustomBusinessDay(holidays=closures)
|
|
84
|
+
pd.Timestamp("2026-11-25") + 2 * nyse_day # skips Thanksgiving
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Calendar codes
|
|
88
|
+
|
|
89
|
+
| Family | Code | Example |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| FX market | `<ISO 4217>.FX` | `USD.FX`, `EUR.FX` |
|
|
92
|
+
| Currency non-clearing days | `<ISO 4217>.CLEAR` | `USD.CLEAR` |
|
|
93
|
+
| Bank holidays (financial centre) | `<UN/LOCODE>.BANK` | `GBLON.BANK`, `USNYC.BANK` |
|
|
94
|
+
| Payment systems | `<SYSTEM>.PAY` | `TARGET2.PAY`, `FEDWIRE.PAY` |
|
|
95
|
+
| Exchange trading | `<MIC>.TRADE` | `XNYS.TRADE`, `XLON.TRADE` |
|
|
96
|
+
| Exchange settlement | `<MIC>.SETTLE` | `XNYS.SETTLE` |
|
|
97
|
+
|
|
98
|
+
`tc.calendars()` lists every code your plan covers. Browse them at
|
|
99
|
+
[tradingcalendars.com/coverage](https://tradingcalendars.com/coverage).
|
|
100
|
+
|
|
101
|
+
## Errors
|
|
102
|
+
|
|
103
|
+
`AuthenticationError` (401/403), `NotFoundError` (404), `RateLimitError` (429, resets at
|
|
104
|
+
midnight UTC) and `TradingCalendarsError` for anything else. Messages come from the API and say
|
|
105
|
+
what to do next.
|
|
106
|
+
|
|
107
|
+
## Also available
|
|
108
|
+
|
|
109
|
+
- REST API reference: https://tradingcalendars.com/documentation
|
|
110
|
+
- MCP server for Claude, ChatGPT and Cursor: https://tradingcalendars.com/mcp
|
|
111
|
+
- Calendar subscriptions (Google Calendar, Outlook, Apple): a "Subscribe" box on every
|
|
112
|
+
calendar page, e.g. https://tradingcalendars.com/calendars/XNYS.TRADE
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT. The data itself is provided under the
|
|
117
|
+
[TradingCalendars.com terms](https://tradingcalendars.com/terms-and-conditions).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/tradingcalendars/__init__.py
|
|
5
|
+
src/tradingcalendars/client.py
|
|
6
|
+
src/tradingcalendars/errors.py
|
|
7
|
+
src/tradingcalendars/py.typed
|
|
8
|
+
src/tradingcalendars_client.egg-info/PKG-INFO
|
|
9
|
+
src/tradingcalendars_client.egg-info/SOURCES.txt
|
|
10
|
+
src/tradingcalendars_client.egg-info/dependency_links.txt
|
|
11
|
+
src/tradingcalendars_client.egg-info/top_level.txt
|
|
12
|
+
tests/test_client.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tradingcalendars
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Client tests with the HTTP layer mocked (no network)."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import urllib.error
|
|
6
|
+
import urllib.parse
|
|
7
|
+
from datetime import date
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
|
|
11
|
+
import tradingcalendars.client as client_module
|
|
12
|
+
from tradingcalendars import (
|
|
13
|
+
AuthenticationError,
|
|
14
|
+
NotFoundError,
|
|
15
|
+
RateLimitError,
|
|
16
|
+
TradingCalendars,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _Response(io.BytesIO):
|
|
21
|
+
def __enter__(self):
|
|
22
|
+
return self
|
|
23
|
+
|
|
24
|
+
def __exit__(self, *exc):
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def calls(monkeypatch):
|
|
30
|
+
seen = []
|
|
31
|
+
replies = {}
|
|
32
|
+
|
|
33
|
+
def fake_urlopen(request, timeout=None):
|
|
34
|
+
url = urllib.parse.urlparse(request.full_url)
|
|
35
|
+
seen.append(
|
|
36
|
+
{
|
|
37
|
+
"path": url.path,
|
|
38
|
+
"query": dict(urllib.parse.parse_qsl(url.query)),
|
|
39
|
+
"auth": request.get_header("Authorization"),
|
|
40
|
+
"agent": request.get_header("User-agent"),
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
status, body = replies[url.path]
|
|
44
|
+
if status != 200:
|
|
45
|
+
raise urllib.error.HTTPError(
|
|
46
|
+
request.full_url, status, "error", {}, io.BytesIO(json.dumps(body).encode())
|
|
47
|
+
)
|
|
48
|
+
return _Response(json.dumps(body).encode())
|
|
49
|
+
|
|
50
|
+
monkeypatch.setattr(client_module.urllib.request, "urlopen", fake_urlopen)
|
|
51
|
+
return seen, replies
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_requires_a_key(monkeypatch):
|
|
55
|
+
monkeypatch.delenv("TRADINGCALENDARS_API_KEY", raising=False)
|
|
56
|
+
with pytest.raises(AuthenticationError, match="signup"):
|
|
57
|
+
TradingCalendars()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_key_from_environment(monkeypatch):
|
|
61
|
+
monkeypatch.setenv("TRADINGCALENDARS_API_KEY", "tc_env")
|
|
62
|
+
assert TradingCalendars().api_key == "tc_env"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_add_business_days(calls):
|
|
66
|
+
seen, replies = calls
|
|
67
|
+
replies["/v1/add-business-days"] = (200, {"result": "2026-12-28", "skipped": []})
|
|
68
|
+
tc = TradingCalendars(api_key="tc_test")
|
|
69
|
+
assert tc.add_business_days(["USD.FX", "EUR.FX"], date(2026, 12, 23), 2) == date(2026, 12, 28)
|
|
70
|
+
assert seen[0]["query"] == {"calendars": "USD.FX,EUR.FX", "date": "2026-12-23", "days": "2"}
|
|
71
|
+
assert seen[0]["auth"] == "Bearer tc_test"
|
|
72
|
+
assert seen[0]["agent"].startswith("tradingcalendars-python/")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_is_business_day_and_between(calls):
|
|
76
|
+
_, replies = calls
|
|
77
|
+
replies["/v1/is-business-day"] = (200, {"is_business_day": False})
|
|
78
|
+
replies["/v1/business-days-between"] = (200, {"business_days": 20})
|
|
79
|
+
tc = TradingCalendars(api_key="k")
|
|
80
|
+
assert tc.is_business_day("TARGET2.PAY", "2026-12-25") is False
|
|
81
|
+
assert tc.business_days_between(["GBP.FX", "SGD.FX"], "2027-01-01", "2027-02-01") == 20
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_holidays_and_closure_dates(calls):
|
|
85
|
+
seen, replies = calls
|
|
86
|
+
replies["/v1/holidays"] = (
|
|
87
|
+
200,
|
|
88
|
+
{
|
|
89
|
+
"meta": {"calendar_code": "XLON.TRADE"},
|
|
90
|
+
"data": [
|
|
91
|
+
{"date": "2026-12-24", "event": "Christmas Eve (half day)", "is_half_day": True,
|
|
92
|
+
"half_day": "EARLY_CLOSE", "early_close_time": "12:30", "original_date": None},
|
|
93
|
+
{"date": "2026-12-28", "event": "Boxing Day", "is_half_day": False,
|
|
94
|
+
"is_observed": True, "original_date": "2026-12-26"},
|
|
95
|
+
],
|
|
96
|
+
"count": 2,
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
tc = TradingCalendars(api_key="k")
|
|
100
|
+
rows = tc.holidays("XLON.TRADE", start="2026-12-01", end=date(2026, 12, 31))
|
|
101
|
+
assert seen[0]["query"] == {"calendar": "XLON.TRADE", "start": "2026-12-01", "end": "2026-12-31"}
|
|
102
|
+
assert rows[0].early_close_time == "12:30" and rows[0].is_half_day
|
|
103
|
+
assert rows[1].original_date == date(2026, 12, 26)
|
|
104
|
+
assert tc.closure_dates("XLON.TRADE") == [date(2026, 12, 28)]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def test_none_params_are_not_sent(calls):
|
|
108
|
+
seen, replies = calls
|
|
109
|
+
replies["/v1/market-status"] = (200, {"data": [{"market": "XNYS"}], "count": 1})
|
|
110
|
+
TradingCalendars(api_key="k").market_status()
|
|
111
|
+
assert seen[0]["query"] == {}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@pytest.mark.parametrize(
|
|
115
|
+
"status,error",
|
|
116
|
+
[(401, AuthenticationError), (403, AuthenticationError), (404, NotFoundError), (429, RateLimitError)],
|
|
117
|
+
)
|
|
118
|
+
def test_errors_carry_the_api_message(calls, status, error):
|
|
119
|
+
_, replies = calls
|
|
120
|
+
replies["/v1/calendars"] = (status, {"detail": "Explained by the API."})
|
|
121
|
+
with pytest.raises(error, match="Explained by the API"):
|
|
122
|
+
TradingCalendars(api_key="k").calendars()
|