Get trading calendar
Method name: get_trading_calendar
Enter parameters
| Field | Type | Description | Is it required |
|---|---|---|---|
| start_date | Optional[str] | Start date in YYYYMMDD format | Optional |
| end_date | Optional[str] | End date in YYYYMMDD format | Optional |
| market | Optional[str] | Exchange code, default is “hk”, currently supports “hk” and “us” | Optional |
| is_trading_day | Optional[int] | Whether it is a trading day, 1=trading day, 0=non-trading day, None=all | Optional |
| fields | Optional[Union[str, List[str]]] | List of fields to be returned | Optional |
Response parameters
| Field | Type | Description |
|---|---|---|
| nature_date | int | Date in the format YYYYMMDD |
| exchange | str | exchange code |
| is_trade | int | Whether it is a trading day, 1 means a trading day, 0 means a non-trading day |
| pretrade_date | str | The trading day before the current date |
| next_trade_date | str | One trading day after the current date |
Usage examples
Obtain the Hong Kong stock trading calendar within a period of time
import tqx_data
result = tqx_data.get_trading_calendar(
start_date="20250101",
end_date="20250115",
market="hk",
is_trading_day=None,
fields=[]
)
print(result)
nature_date exchange is_trade next_trade_date pretrade_date
0 20250101 HK 0 20250102 20241230
1 20250102 HK 1 20250103 20241231
2 20250103 HK 1 20250106 20250102
3 20250104 HK 0 20250106 20250102
4 20250105 HK 0 20250106 20250102
5 20250106 HK 1 20250107 20250103
6 20250107 HK 1 20250108 20250106
7 20250108 HK 1 20250109 20250107
8 20250109 HK 1 20250110 20250108
9 20250110 HK 1 20250113 20250109
10 20250111 HK 0 20250113 20250109
11 20250112 HK 0 20250113 20250109
12 20250113 HK 1 20250114 20250110
13 20250114 HK 1 20250115 20250113
14 20250115 HK 1 20250116 20250114
Get US stock non-trading days within a period of time and use fields
import tqx_data
result = tqx_data.get_trading_calendar(
start_date="20241215",
end_date="20250110",
market="us",
is_trading_day=0,
fields=["nature_date", "is_trade", "next_trade_date", "pretrade_date"]
)
print(result)
nature_date is_trade next_trade_date pretrade_date
0 20241215 0 20241216 20241212
1 20241221 0 20241223 20241219
2 20241222 0 20241223 20241219
3 20241225 0 20241226 20241223
4 20241228 0 20241230 20241226
5 20241229 0 20241230 20241226
6 20250101 0 20250102 20241230
7 20250104 0 20250106 20250102
8 20250105 0 20250106 20250102
9 20250109 0 20250110 20250108
Get Hong Kong stock trading days within a period of time
import tqx_data
result = tqx_data.get_trading_calendar(
start_date="20250101",
end_date="20250120",
market="hk",
is_trading_day=1,
fields=[]
)
print(result)
nature_date exchange is_trade next_trade_date pretrade_date
0 20250102 HK 1 20250103 20241231
1 20250103 HK 1 20250106 20250102
2 20250106 HK 1 20250107 20250103
3 20250107 HK 1 20250108 20250106
4 20250108 HK 1 20250109 20250107
5 20250109 HK 1 20250110 20250108
6 20250110 HK 1 20250113 20250109
7 20250113 HK 1 20250114 20250110
8 20250114 HK 1 20250115 20250113
9 20250115 HK 1 20250116 20250114
10 20250116 HK 1 20250117 20250115
11 20250117 HK 1 20250120 20250116
12 20250120 HK 1 20250121 20250117

