Skip to content

Trading calendar

Find trading days, sessions and market hours for stock exchanges

Connector software
Free and open source
Service credentials
Not needed
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
Result
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.

setup.sql
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;

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

3. Run a query

query.sql
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
More example queries β†’
Technical details
Verified connector release
v0.6.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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'
);

Overview

Stock-exchange trading-calendar math for SQL: sessions, market hours, and schedules

Catalog

Everything tcal exposes once attached β€” read straight from the worker's released build.

tcal 1 schema
main 1 table Β· 10 functions

Stock-exchange trading-calendar math for SQL

Schema examples (16)
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;
Result
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;
Tables
exchanges 2 examples1 col

Discovery table of every supported stock-exchange trading-calendar MIC code.

Columns
codenot null VARCHAR
Exchange MIC code (e.g. 'XNYS' = NYSE, 'XLON' = London).
ConstraintsPRIMARY KEY (code)
Examples (2)

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';
Link
Scalar functions
add_trading_days (date DATE, n INTEGER, exchange VARCHAR) +1 overload 1 example

Advance a date by N trading sessions, skipping non-sessions (exchange 'XNYS')

Arguments
date DATE
Calendar day to advance from.
n INTEGER
Sessions to add (negative goes backwards).
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
add_trading_days(date DATE, n INTEGER) β†’ DATEadd_trading_days(date DATE, n INTEGER, exchange VARCHAR) β†’ DATE
ReturnsDATE
Example

Five London sessions after 2026-01-02

SELECT tcal.main.add_trading_days(DATE '2026-01-02', 5, 'XLON');
Link
is_early_close (date DATE, exchange VARCHAR) +1 overload 1 example

True if a date is a session that closes early (exchange 'XNYS')

Arguments
date DATE
Calendar day to evaluate.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
is_early_close(date DATE) β†’ BOOLEANis_early_close(date DATE, exchange VARCHAR) β†’ BOOLEAN
ReturnsBOOLEAN
Example

Christmas Eve is an early close on the LSE

SELECT tcal.main.is_early_close(DATE '2026-12-24', 'XLON');
Link
is_trading_day (date DATE, exchange VARCHAR) +1 overload 1 example

True if a date is a trading session (exchange defaults to 'XNYS')

Arguments
date DATE
Calendar day to evaluate.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
is_trading_day(date DATE) β†’ BOOLEANis_trading_day(date DATE, exchange VARCHAR) β†’ BOOLEAN
ReturnsBOOLEAN
Example

Is 2026-12-28 a London Stock Exchange session?

SELECT tcal.main.is_trading_day(DATE '2026-12-28', 'XLON');
Link
market_close (date DATE, exchange VARCHAR) +1 overload 1 example

UTC market-close instant for a date, NULL if not a session (exchange 'XNYS')

Arguments
date DATE
Calendar day of the trading session.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
market_close(date DATE) β†’ TIMESTAMP WITH TIME ZONEmarket_close(date DATE, exchange VARCHAR) β†’ TIMESTAMP WITH TIME ZONE
ReturnsTIMESTAMP WITH TIME ZONE
Example

London close on 2026-01-02

SELECT tcal.main.market_close(DATE '2026-01-02', 'XLON');
Link
market_open (date DATE, exchange VARCHAR) +1 overload 1 example

UTC market-open instant for a date, NULL if not a session (exchange 'XNYS')

Arguments
date DATE
Calendar day of the trading session.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
market_open(date DATE) β†’ TIMESTAMP WITH TIME ZONEmarket_open(date DATE, exchange VARCHAR) β†’ TIMESTAMP WITH TIME ZONE
ReturnsTIMESTAMP WITH TIME ZONE
Example

London open on 2026-01-02

SELECT tcal.main.market_open(DATE '2026-01-02', 'XLON');
Link
next_trading_day (date DATE, exchange VARCHAR) +1 overload 1 example

First trading session strictly after a date (exchange 'XNYS')

Arguments
date DATE
Calendar day to search relative to.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
next_trading_day(date DATE) β†’ DATEnext_trading_day(date DATE, exchange VARCHAR) β†’ DATE
ReturnsDATE
Example

Next Tokyo session after New Year's Day

SELECT tcal.main.next_trading_day(DATE '2026-01-01', 'XTKS');
Link
previous_trading_day (date DATE, exchange VARCHAR) +1 overload 1 example

Last trading session strictly before a date (exchange 'XNYS')

Arguments
date DATE
Calendar day to search relative to.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
previous_trading_day(date DATE) β†’ DATEprevious_trading_day(date DATE, exchange VARCHAR) β†’ DATE
ReturnsDATE
Example

Last London session before New Year's Day

SELECT tcal.main.previous_trading_day(DATE '2026-01-01', 'XLON');
Link
trading_days_between (start DATE, end DATE, exchange VARCHAR) +1 overload 1 example

Count trading sessions in [start, end), start inclusive (exchange 'XNYS')

Arguments
start DATE
Inclusive lower bound of the span to count over.
end DATE
Exclusive upper bound of the span to count over.
exchange VARCHAR
Exchange MIC code, e.g. 'XNYS', 'XNAS', 'XLON'. See tcal.exchanges.
Overloads
trading_days_between(start DATE, end DATE) β†’ INTEGERtrading_days_between(start DATE, end DATE, exchange VARCHAR) β†’ INTEGER
ReturnsINTEGER
Example

London sessions in January 2026

SELECT tcal.main.trading_days_between(DATE '2026-01-01', DATE '2026-02-01', 'XLON');
Link
Table functions
trading_schedule (start DATE, end DATE, exchange := VARCHAR) 3 examples

Per-session open/close/early-close schedule for a date range

Positional arguments
start DATE
Range start (inclusive).
end DATE
Range end (inclusive).
Named arguments
exchange := VARCHAR
Exchange MIC code (e.g. 'XNYS', 'XLON'). See tcal.exchanges. Β· default "XNYS"
Returns columns
session DATE
Trading session date.
market_open TIMESTAMPTZ
UTC market-open instant.
market_close TIMESTAMPTZ
UTC market-close instant.
is_early_close BOOLEAN
True if the session closes early.
Examples (3)

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;
Link
trading_sessions (start DATE, end DATE, exchange := VARCHAR) 4 examples

Every trading session in an inclusive [start, end] range

Positional arguments
start DATE
Range start (inclusive).
end DATE
Range end (inclusive).
Named arguments
exchange := VARCHAR
Exchange MIC code (e.g. 'XNYS', 'XLON'). See tcal.exchanges. Β· default "XNYS"
Returns columns
session DATE
A trading session date in the range.
Examples (4)

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;
Result
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
Link

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;

Uses trading_sessionsis_trading_day

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.