因此,这个项目有一个分叉,将得到更积极的维护,
原生交易所开发详情丨原生交易所系统开发(成熟技术)丨原生交易所现成源码部署
交易所系统丨交易所系统开发(逻辑及功能)丨交易所开发源码交付
秒合约开发原理丨秒合约系统开发(详细规则)丨秒合约源码案例部署
永续合约/秒合约/合约交易所开发详情,永续合约/秒合约/合约交易所系统开发技术方案
深入分析代币合约流动性质押挖矿分红系统开发实现技术原理及源码部署
交易所系统开发如何开发?数字货币交易所系统开发成熟技术案例
去中心化交易所系统开发技术原理丨数字货币去中心化交易所系统开发(说明案例)
交易日历(trading_calendars
交易所日历的 Python 库,经常与 Zipline 一起使用。
安装
$ pip install trading-calendars
Quick Start
import trading_calendars as tc
import pandas as pd
import pytz
Get all registered calendars with get_calendar_names:
tc.get_calendar_names()[:5]
['XPHS', 'FWB', 'CFE', 'CMES', 'XSGO']
Get a calendar with get_calendar:xnys = tc.get_calendar("XNYS")
Working with sessions:xnys.is_session(pd.Timestamp("2020-01-01"))
Falsexnys.next_open(pd.Timestamp("2020-01-01"))
Timestamp('2020-01-02 14:31:00+0000', tz='UTC')pd.Timestamp("2020-01-01", tz=pytz.UTC)+xnys.day
Timestamp('2020-01-02 00:00:00+0000', tz='UTC')xnys.previous_close(pd.Timestamp("2020-01-01"))
Timestamp('2019-12-31 21:00:00+0000', tz='UTC')xnys.sessions_in_range(
pd.Timestamp("2020-01-01", tz=pytz.UTC), pd.Timestamp("2020-01-10", tz=pytz.UTC)
)
DatetimeIndex(['2020-01-02 00:00:00+00:00', '2020-01-03 00:00:00+00:00',
'2020-01-06 00:00:00+00:00', '2020-01-07 00:00:00+00:00',
'2020-01-08 00:00:00+00:00', '2020-01-09 00:00:00+00:00',
'2020-01-10 00:00:00+00:00'],
dtype='datetime64[ns, UTC]', freq='C')
xnys.sessions_window(
pd.Timestamp("2020-01-02", tz=pytz.UTC), 7
)
DatetimeIndex(['2020-01-02 00:00:00+00:00', '2020-01-03 00:00:00+00:00',
'2020-01-06 00:00:00+00:00', '2020-01-07 00:00:00+00:00',
'2020-01-08 00:00:00+00:00', '2020-01-09 00:00:00+00:00',
'2020-01-10 00:00:00+00:00', '2020-01-13 00:00:00+00:00'],
dtype='datetime64[ns, UTC]', freq='C')
NOTE: see the TradingCalendar class for more advanced usage.
Trading calendars also supports command line usage, printing a unix-cal like calendar indicating which days are trading sessions or holidays.
tcal XNYS 2020
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
[ 1] 2 3 [ 4] [ 1]
[ 5] 6 7 8 9 10 [11] [ 2] 3 4 5 6 7 [ 8] [ 1] 2 3 4 5 6 [ 7]
[12] 13 14 15 16 17 [18] [ 9] 10 11 12 13 14 [15] [ 8] 9 10 11 12 13 [14]
19 21 22 23 24 [25] 16 18 19 20 21 [22] [15] 16 17 18 19 20 [21]
[26] 27 28 29 30 31 [23] 24 25 26 27 28 [29] [22] 23 24 25 26 27 [28]
[29] 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 [ 4] 1 [ 2] 1 2 3 4 5 [ 6]
[ 5] 6 7 8 9 10 [ 3] 4 5 6 7 8 [ 9] [ 7] 8 9 10 11 12 [13]
[12] 13 14 15 16 17 [18] [10] 11 12 13 14 15 [16] [14] 15 16 17 18 19 [20]
[19] 20 21 22 23 24 [25] [17] 18 19 20 21 22 [23] [21] 22 23 24 25 26 [27]
[26] 27 28 29 30 24 26 27 28 29 [30] [28] 29 30
[31]
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 [ 3][ 4] [ 1] 1 2 3 4 [ 5]
[ 5] 6 7 8 9 10 [11] [ 2] 3 4 5 6 7 [ 8] 6 8 9 10 11 [12]
[12] 13 14 15 16 17 [18] [ 9] 10 11 12 13 14 [15] [13] 14 15 16 17 18 [19]
[19] 20 21 22 23 24 [25] [16] 17 18 19 20 21 [22] [20] 21 22 23 24 25 [26]
[26] 27 28 29 30 31 [23] 24 25 26 27 28 [29] [27] 28 29 30
[30] 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 [ 3] 1 2 3 4 [ 5]
[ 4] 5 6 7 8 9 [10] [ 1] 2 3 4 5 6 [ 7] [ 6] 7 8 9 10 11 [12]
[11] 12 13 14 15 16 [17] [ 8] 9 10 11 12 13 [14] [13] 14 15 16 17 18 [19]
[18] 19 20 21 22 23 [24] [15] 16 17 18 19 20 [21] [20] 21 22 23 24 25
[25] 26 27 28 29 30 [31] [22] 23 24 25 [26] 27 [28] [27] 28 29 30 31
[29] 30
tcal XNYS 1 2020
January 2020
Su Mo Tu We Th Fr Sa
[ 1] 2 3 [ 4]
[ 5] 6 7 8 9 10 [11]
[12] 13 14 15 16 17 [18]
19 21 22 23 24 [25]
[26] 27 28 29 30 31
常见问题
为什么开盘时间会晚一分钟?
由于其在Zipline回溯测试系统中的历史使用,trading_calendars只在一天中的第一个分钟条完成时显示市场开放。Zipline使用标有条形结束时间的分钟条,例如,9:31AM表示9:30-9:31AM。举例来说,在纽约证券交易所的正常交易日。
9:30:00被视为关闭。
9:30:01被视为关闭。
9:31:00是第一次被视为开盘。
16:00:00被视为开盘
16:00:01被视为关闭
这在将来可能会改变。