Trading calendar
Find trading days, sessions and market hours for stock exchanges
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available Β· $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/trading-calendar/index.md to help me query Trading calendar with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
Calculate settlement dates across market holidays
Example output Β· captured
- Connector release
- v0.6.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session
| trade_date | settles_t1 |
|---|---|
| 2026-11-23 | 2026-11-24 |
| 2026-11-24 | 2026-11-25 |
| 2026-11-25 | 2026-11-27 |
| 2026-11-27 | 2026-11-30 |
| 2026-11-30 | 2026-12-01 |
Quick start
Choose where to run Trading calendar, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'tcal' AS tcal (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-trading-calendar-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tcal' AS tcal (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-trading-calendar:0.6.0'
);
3. Run a query
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connectorβs deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'tcal' AS tcal
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session
Query Farm operates Trading calendar for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use tcal as the catalog alias for the query below.
4. Run a query
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session
Technical details
- Verified connector release
- v0.6.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until youβre ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'tcal' AS tcal (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-trading-calendar-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'tcal' AS tcal (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-trading-calendar:0.6.0'
);
Overview
Stock-exchange trading-calendar math for SQL: sessions, market hours, and schedules
tcal brings stock-exchange trading calendars directly into DuckDB SQL β no ETL, no Python glue, just SELECT. Ask whether a date is a trading session, advance or count trading days, find the next or previous session, or check market open/close hours (including early closes) for the NYSE and ~100 other exchanges, all as ordinary SQL expressions and table functions.
This VGI worker is for analysts, data engineers, and application developers who need correct market-calendar logic close to their data: trading-day filtering, settlement (T+N) date math, session alignment of fills and ticks, and market-hours analytics. It exposes a single tcal catalog (schema main) over Apache Arrow, so every function streams results back to DuckDB with native types β DATE, TIMESTAMP, and TIMESTAMPTZ round-trip cleanly. Coverage is global, not US-centric: roughly a hundred exchange calendars are supported, and 'XNYS' (NYSE) is merely the default argument, not a limit.
Trading calendars are provided by exchange-calendars (tutorials), the maintained successor to Quantopian's trading_calendars, covering roughly a hundred exchanges including early closes and holiday sessions. A session is a trading day; market_open / market_close are timezone-aware UTC instants. Coverage is the library's default window (roughly two decades back to about a year ahead β future exchange holidays are only defined so far); a date outside that window resolves to NULL / no rows rather than raising.
Per-row questions are answered by scalar functions you can drop straight into a projection or predicate; set-returning questions β a range of trading sessions, an expanded per-session schedule β are table functions. The exchange is an ordinary argument that defaults to 'XNYS'.
Catalog
Everything tcal exposes once attached β read straight from the worker's
released build.
main 1 table Β· 10 functions
Stock-exchange trading-calendar math for SQL
Schema examples (16)
Is New Year's Day 2026 an NYSE trading session? (No β it is a holiday.)
SELECT tcal.main.is_trading_day(DATE '2026-01-01') AS is_session;
Is 3 July 2026 (US Independence Day observed) a London Stock Exchange session?
SELECT tcal.main.is_trading_day(DATE '2026-07-03', 'XLON') AS is_session;
The first NYSE session strictly after New Year's Day 2026.
SELECT tcal.main.next_trading_day(DATE '2026-01-01') AS next_session;
The last NYSE session strictly before 2 January 2026.
SELECT tcal.main.previous_trading_day(DATE '2026-01-02') AS prev_session;
12 more examples
Advance a trade date by 10 NYSE sessions (settlement-style date math).
SELECT tcal.main.add_trading_days(DATE '2026-01-02', 10) AS settle_date;
Count NYSE sessions in January 2026 via the half-open [start, end) interval.
SELECT tcal.main.trading_days_between(DATE '2026-01-01', DATE '2026-02-01') AS n_sessions;
NYSE market-open instant (UTC) for 2 January 2026.
SELECT tcal.main.market_open(DATE '2026-01-02') AS open_utc;
NYSE early close (UTC) the day after US Thanksgiving 2026.
SELECT tcal.main.market_close(DATE '2026-11-27') AS close_utc;
Flag the day after US Thanksgiving 2026 as an early-close half-day.
SELECT tcal.main.is_early_close(DATE '2026-11-27') AS early_close;
Count the NYSE trading sessions in January 2026.
SELECT count(*) AS n_sessions
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-01-31');
Half-days in the NYSE Thanksgiving-week schedule, with their early close time.
SELECT session, market_close
FROM tcal.main.trading_schedule(DATE '2026-11-25', DATE '2026-11-30')
WHERE is_early_close;
The first five supported exchange MIC codes, alphabetically.
SELECT code FROM tcal.main.exchanges ORDER BY code LIMIT 5;
NYSE sessions in 2026 on which the London Stock Exchange is closed (UK bank holidays such as Easter Monday and the Boxing Day substitute) -- days a US/UK pairs desk trades only one leg.
SELECT s.session
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-12-31') AS s
WHERE NOT tcal.main.is_trading_day(s.session, 'XLON')
ORDER BY s.session;
T+1 settlement date for a trade on each NYSE session of Thanksgiving week 2026 -- the Wednesday trade settles on Friday because the Thanksgiving holiday is skipped.
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session;
| trade_date | settles_t1 |
|---|---|
| 2026-11-23 | 2026-11-24 |
| 2026-11-24 | 2026-11-25 |
| 2026-11-25 | 2026-11-27 |
| 2026-11-27 | 2026-11-30 |
| 2026-11-30 | 2026-12-01 |
Every NYSE early-close half-day in 2026 with its early close time (UTC) and when the market next opens -- how long positions sit over the holiday break.
SELECT sc.session, sc.market_close,
tcal.main.next_trading_day(sc.session) AS next_session,
tcal.main.market_open(tcal.main.next_trading_day(sc.session)) AS next_open
FROM tcal.main.trading_schedule(DATE '2026-01-01', DATE '2026-12-31') AS sc
WHERE sc.is_early_close
ORDER BY sc.session;
Minutes of overlap between NYSE and London trading hours on sessions both trade in March-April 2026: usually 2 hours, widening to 3 hours for the weeks when the US has moved to daylight saving time and the UK has not.
SELECT date_diff('minute', greatest(ny.market_open, ln.market_open), least(ny.market_close, ln.market_close)) AS overlap_minutes,
count(*) AS n_sessions, min(ny.session) AS first_session
FROM tcal.main.trading_schedule(DATE '2026-03-01', DATE '2026-04-30') AS ny
JOIN tcal.main.trading_schedule(DATE '2026-03-01', DATE '2026-04-30', exchange := 'XLON') AS ln USING (session)
GROUP BY overlap_minutes
ORDER BY first_session;
exchanges
Discovery table of every supported stock-exchange trading-calendar MIC code.
List all supported exchange MIC codes.
SELECT code FROM tcal.main.exchanges ORDER BY code;
Confirm the NYSE (XNYS) calendar is available.
SELECT count(*) AS n FROM tcal.main.exchanges WHERE code = 'XNYS';
add_trading_days (date DATE, n INTEGER, exchange VARCHAR) +1 overload
Advance a date by N trading sessions, skipping non-sessions (exchange 'XNYS')
add_trading_days(date DATE, n INTEGER) β DATEadd_trading_days(date DATE, n INTEGER, exchange VARCHAR) β DATE
Five London sessions after 2026-01-02
SELECT tcal.main.add_trading_days(DATE '2026-01-02', 5, 'XLON');
is_early_close (date DATE, exchange VARCHAR) +1 overload
True if a date is a session that closes early (exchange 'XNYS')
is_early_close(date DATE) β BOOLEANis_early_close(date DATE, exchange VARCHAR) β BOOLEAN
Christmas Eve is an early close on the LSE
SELECT tcal.main.is_early_close(DATE '2026-12-24', 'XLON');
is_trading_day (date DATE, exchange VARCHAR) +1 overload
True if a date is a trading session (exchange defaults to 'XNYS')
is_trading_day(date DATE) β BOOLEANis_trading_day(date DATE, exchange VARCHAR) β BOOLEAN
Is 2026-12-28 a London Stock Exchange session?
SELECT tcal.main.is_trading_day(DATE '2026-12-28', 'XLON');
market_close (date DATE, exchange VARCHAR) +1 overload
UTC market-close instant for a date, NULL if not a session (exchange 'XNYS')
market_close(date DATE) β TIMESTAMP WITH TIME ZONEmarket_close(date DATE, exchange VARCHAR) β TIMESTAMP WITH TIME ZONE
London close on 2026-01-02
SELECT tcal.main.market_close(DATE '2026-01-02', 'XLON');
market_open (date DATE, exchange VARCHAR) +1 overload
UTC market-open instant for a date, NULL if not a session (exchange 'XNYS')
market_open(date DATE) β TIMESTAMP WITH TIME ZONEmarket_open(date DATE, exchange VARCHAR) β TIMESTAMP WITH TIME ZONE
London open on 2026-01-02
SELECT tcal.main.market_open(DATE '2026-01-02', 'XLON');
next_trading_day (date DATE, exchange VARCHAR) +1 overload
First trading session strictly after a date (exchange 'XNYS')
next_trading_day(date DATE) β DATEnext_trading_day(date DATE, exchange VARCHAR) β DATE
Next Tokyo session after New Year's Day
SELECT tcal.main.next_trading_day(DATE '2026-01-01', 'XTKS');
previous_trading_day (date DATE, exchange VARCHAR) +1 overload
Last trading session strictly before a date (exchange 'XNYS')
previous_trading_day(date DATE) β DATEprevious_trading_day(date DATE, exchange VARCHAR) β DATE
Last London session before New Year's Day
SELECT tcal.main.previous_trading_day(DATE '2026-01-01', 'XLON');
trading_days_between (start DATE, end DATE, exchange VARCHAR) +1 overload
Count trading sessions in [start, end), start inclusive (exchange 'XNYS')
trading_days_between(start DATE, end DATE) β INTEGERtrading_days_between(start DATE, end DATE, exchange VARCHAR) β INTEGER
London sessions in January 2026
SELECT tcal.main.trading_days_between(DATE '2026-01-01', DATE '2026-02-01', 'XLON');
trading_schedule (start DATE, end DATE, exchange := VARCHAR)
Per-session open/close/early-close schedule for a date range
Half-days in the NYSE Thanksgiving-week schedule, with their early close time.
SELECT session, market_close
FROM tcal.main.trading_schedule(DATE '2026-11-25', DATE '2026-11-30')
WHERE is_early_close;
Every NYSE early-close half-day in 2026 with its early close time (UTC) and when the market next opens -- how long positions sit over the holiday break.
SELECT sc.session, sc.market_close,
tcal.main.next_trading_day(sc.session) AS next_session,
tcal.main.market_open(tcal.main.next_trading_day(sc.session)) AS next_open
FROM tcal.main.trading_schedule(DATE '2026-01-01', DATE '2026-12-31') AS sc
WHERE sc.is_early_close
ORDER BY sc.session;
Minutes of overlap between NYSE and London trading hours on sessions both trade in March-April 2026: usually 2 hours, widening to 3 hours for the weeks when the US has moved to daylight saving time and the UK has not.
SELECT date_diff('minute', greatest(ny.market_open, ln.market_open), least(ny.market_close, ln.market_close)) AS overlap_minutes,
count(*) AS n_sessions, min(ny.session) AS first_session
FROM tcal.main.trading_schedule(DATE '2026-03-01', DATE '2026-04-30') AS ny
JOIN tcal.main.trading_schedule(DATE '2026-03-01', DATE '2026-04-30', exchange := 'XLON') AS ln USING (session)
GROUP BY overlap_minutes
ORDER BY first_session;
trading_sessions (start DATE, end DATE, exchange := VARCHAR)
Every trading session in an inclusive [start, end] range
Count the NYSE trading sessions in January 2026.
SELECT count(*) AS n_sessions
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-01-31');
The last London Stock Exchange sessions of January 2026 (26th onward).
SELECT session
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-01-31', exchange := 'XLON')
WHERE session >= DATE '2026-01-26';
NYSE sessions in 2026 on which the London Stock Exchange is closed (UK bank holidays such as Easter Monday and the Boxing Day substitute) -- days a US/UK pairs desk trades only one leg.
SELECT s.session
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-12-31') AS s
WHERE NOT tcal.main.is_trading_day(s.session, 'XLON')
ORDER BY s.session;
1 more example
T+1 settlement date for a trade on each NYSE session of Thanksgiving week 2026 -- the Wednesday trade settles on Friday because the Thanksgiving holiday is skipped.
SELECT s.session AS trade_date,
tcal.main.add_trading_days(s.session, 1) AS settles_t1
FROM tcal.main.trading_sessions(DATE '2026-11-23', DATE '2026-11-30') AS s
ORDER BY s.session;
| trade_date | settles_t1 |
|---|---|
| 2026-11-23 | 2026-11-24 |
| 2026-11-24 | 2026-11-25 |
| 2026-11-25 | 2026-11-27 |
| 2026-11-27 | 2026-11-30 |
| 2026-11-30 | 2026-12-01 |
Try these queries
is-market-open β Whether a date is an NYSE trading session (New Year's Day is a holiday).
SELECT tcal.main.is_trading_day(DATE '2026-01-01') AS is_session;
Uses is_trading_day
next-nyse-session β The first NYSE session strictly after a given date.
SELECT tcal.main.next_trading_day(DATE '2026-01-01') AS next_session;
Uses next_trading_day
list-exchanges β A few of the supported exchange MIC codes.
SELECT code FROM tcal.main.exchanges ORDER BY code LIMIT 5;
Uses exchanges
nyse-open-london-closed β NYSE sessions in 2026 on which the London Stock Exchange is closed (UK bank holidays such as Easter Monday and the Boxing Day substitute) -- days a US/UK pairs desk trades only one leg.
SELECT s.session
FROM tcal.main.trading_sessions(DATE '2026-01-01', DATE '2026-12-31') AS s
WHERE NOT tcal.main.is_trading_day(s.session, 'XLON')
ORDER BY s.session;
The last NYSE session strictly before 2 January 2026.
SELECT tcal.main.previous_trading_day(DATE '2026-01-02') AS prev_session
Uses previous_trading_day
Advance a trade date by 10 NYSE sessions (settlement-style date math).
SELECT tcal.main.add_trading_days(DATE '2026-01-02', 10) AS settle_date
Uses add_trading_days
20 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- Using the tcal worker, what is the first New York Stock Exchange trading session strictly after 1 January 2026? Return a single date.
- Using the tcal worker, what is the last New York Stock Exchange trading session strictly before 2 January 2026? Return a single date.
- Using the tcal worker, at what UTC timestamp does the New York Stock Exchange open on 2 January 2026? Return a single timestamp.
- Using the tcal worker, in the New York Stock Exchange schedule for 27 November 2026, is that session flagged as an early close? Return a single boolean.
Trading calendar is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
CCXT
Markets & finance
Candles, quotes, order books, trades and perpetual funding from 100+ crypto exchanges
First Trust ETFs
Markets & finance
Screen First Trust US ETFs and see each fund's facts and current holdings
Global X ETFs
Markets & finance
Global X US ETF product facts and current fund holdings as SQL tables