Skip to main content

cnfutures-session-timeline

离线计算中国期货交易区间历史,任意天和任意品种. 预期使用场景:

  • 从 CTP tick 重建分钟数据

我手工整理了所有期货 session 变动历史,如有新上线品种或交易时间调整,我会发布新版本.

节假日使用 chinese-calendar

Python API

from datetime import date, datetime
from cnfutures_session_timeline import SessionTimeline

st = SessionTimeline.load()

st.resolve(date(2020, 3, 4), 'CU')
# ResolvedSession(periods=(0900~1015,1030~1130,1330~1500), COVID19暂停夜盘 @ 2020-02-04)

st.resolve(20200508, 'CU')
# ResolvedSession(periods=(2100~0100,0900~1015,1030~1130,1330~1500), COVID19夜盘暂停恢复 @ 2020-05-07)

st.resolve(20260101, 'IC')
# ResolvedSession(periods=(), 调整交易时间 @ 2016-01-04,元旦 休市)

st.resolve(20240209, 'CU')
# ResolvedSession(periods=(), COVID19夜盘暂停恢复 @ 2020-05-07,除夕日额外休市 休市)

st.resolve(20200508, 'EC')
# KeyError: '品种 EC 在 2020-05-08 尚未上市'
st.resolve(20250908, 'EC')
# ResolvedSession(periods=(0900~1015,1030~1130,1330~1500), 上市 @ 2023-08-18)

st.trade_day_at(datetime.fromisoformat('2026-09-18T21:00:00+08:00'), 'AU')
# datetime.date(2026, 9, 21)

st.trade_day_at(datetime.fromisoformat('2026-09-19T10:00:00+08:00'), 'AU')
# None

Cli

查询 session 区间:

> uvx cnfutures-session-timeline 20260928 AU
2026-09-28 AU,`COVID19夜盘暂停恢复 @ 2020-05-07`,`中秋` 后首个工作日无夜盘
  09:00 → 10:15
  10:30 → 11:30
  13:30 → 15:00

> uvx cnfutures-session-timeline 20260928 AU --json
{"periods": [{"start": "09:00:00", "end": "10:15:00"}, {"start": "10:30:00", "end": "11:30:00"}, {"start": "13:30:00", "end": "15:00:00"}], "std_session_event": {"exchange": "SHFE", "product": "AU", "effective_trade_date": "2020-05-07", "session": "night-2100-0230", "reason": "COVID19夜盘暂停恢复", "source_url": ""}, "trims": [{"action": "remove_night", "cause": "Mid-autumn Festival"}]}

查询自然时间所属交易日:

uvx cnfutures-session-timeline --trade-day-at '2026-09-18T21:00:00+08:00' AU
# 2026-09-21

uvx cnfutures-session-timeline --trade-day-at '2026-09-19T10:00:00+08:00' AU --json
# {"trade_day": null}

安装

uv add cnfutures-session-timeline
# or use pip: 
# pip install -U cnfutures-session-timeline

数据维护

  • src/cnfutures_session_timeline/future_session_events.csv:上市、下架、时段调整事件及其公告链接
  • src/cnfutures_session_timeline/extra_closures.csv:节假日之外的单日休市,目前只有 2024-02-09 的额外除夕休市

发布历史

2026.11.12

添加葵花籽油

2026.10.09

  • 添加从 datetime 计算所在交易日功能
  • 调整部分输出格式

2026.09.20

初次发布,含至今所有品种

Metadata

Release files for cnfutures-session-timeline 2026.11.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cnfutures-session-timeline 2026.11.12
File Size Uploaded Provenance Actions
cnfutures_session_timeline-2026.11.12.tar.gz 10.3 kB Without provenance Details for cnfutures_session_timeline-2026.11.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cnfutures-session-timeline 2026.11.12
File Interpreter ABI Platform Actions
cnfutures_session_timeline-2026.11.12-py3-none-any.whl Python 3 none any Details for cnfutures_session_timeline-2026.11.12-py3-none-any.whl

Total release size: 24.2 kB

Release files / cnfutures_session_timeline-2026.11.12.tar.gz

Download URL cnfutures_session_timeline-2026.11.12.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
84d9a80e6210b8113641fea6132a5232cd5eebf876acca804c36e7644371db17
BLAKE2b-256 checksum
How to use checksums
4b431c9ace94d914c28da4729e46572a7f87c7152d87033fe99f39a077c9342d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / cnfutures_session_timeline-2026.11.12-py3-none-any.whl

Download URL cnfutures_session_timeline-2026.11.12-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5c12aec9f158665bb004e317f721401f5b52cd155cad059ae8eccfcbded2289
BLAKE2b-256 checksum
How to use checksums
4519e2b5300fc960effc84e2466b5c4975b1b3498bb899dff423483382c92d27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Manjaro Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for cnfutures-session-timeline 2026.11.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page