# cn_stock_holidays
![CI Status](https://github.com/rainx/cn_stock_holidays/actions/workflows/pytest.yml/badge.svg)
## 数据文件 (File Path)
沪深市场
```
cn_stock_holidays/data.txt
```
香港市场
```
cn_stock_holidays/data_hk.txt
```
Fetch Data via URL :
```
wget https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt
or
curl https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt
```
## 文件内容 ( File Content)
保存除了周六日休市之外,其它休市信息,换行分割
store all (even upcoming) holiday for china stock exchange (without regular market close date on Saturday Day and Sun Day ) , one date per line
## 格式(File Format)
```
YYYYMMDD
```
## Python version
```
pip install cn-stock-holidays
```
or
```
pip install git+https://github.com/rainx/cn_stock_holidays.git
```
### 导入
```python
# 针对沪深
import cn_stock_holidays.data as shsz
# 针对香港
import cn_stock_holidays.data_hk as hkex
```
### Functions
```python
Help on module cn_stock_holidays.data in cn_stock_holidays:
NAME
cn_stock_holidays.data - Help functions for python to get china stock exchange holidays
FILE
/Users/rainx/dev/cn_stock_holidays/cn_stock_holidays/data.py
FUNCTIONS
check_expired()
check if local or cached data need update
:return: true/false
date_to_int(da)
date_to_str(da)
get_cache_path()
get_cached()
get from cache version , if it is not exising , use txt file in package data
:return: a list contains all holiday data, element with datatime.date format
get_local()
read data from package data file
:return: a list contains all holiday data, element with datatime.date format
get_remote_and_cache()
get newest data file from network and cache on local machine
:return: a list contains all holiday data, element with datatime.date format
int_to_date(d)
str_to_int(s)
sync_data()
is_trading_day(dt)
param dt: datetime.datetime or datetime.date.
is a trading day or not
:returns: Bool
previous_trading_day(dt):
param dt: datetime.datetime or datetime.date.
get previous trading day
:returns: datetime.date
next_trading_day(dt):
param dt: datetime.datetime or datetime.date.
get next trading day
:returns: datetime.date
trading_days_between(start, end):
param start, end: start and end time , datetime.datetime or datetime.date
get calendar data range
:returns: a generator for available dates for chinese market included start and end date
```
### about function cache
from version 0.10 on, we used functools.lrucache on `get_cached` for getting more speech,
if needed you can used the following syntax to clear cache.
```python
get_cached.cache_clear()
```
### Keep it up-to-date
we had a script to check the expired of the data and fetch the data from web.
you could set it up on cron job
```crontab
0 0 * * * /usr/local/bin/cn-stock-holiday-sync > /tmp/cn_stock_holiday_sync.log
```
You could get the absolute path of cn-stock-holiday-sync by which command
沪深
```bash
which cn-stock-holiday-sync
```
香港
```bash
which cn-stock-holiday-sync-hk
```
Raw data
{
"_id": null,
"home_page": "https://github.com/rainx/cn_stock_holidays.git",
"name": "cn-stock-holidays",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "china stock holiday exchange shanghai, shenzhen and hongkong",
"author": "rainx",
"author_email": "i@rainx.cc",
"download_url": "https://files.pythonhosted.org/packages/62/17/e7fcdd40f93621eb07051037dda0481ec48e0dd9ad8496d30ebb98dbaa6e/cn_stock_holidays-1.12.tar.gz",
"platform": null,
"description": "# cn_stock_holidays\n\n![CI Status](https://github.com/rainx/cn_stock_holidays/actions/workflows/pytest.yml/badge.svg)\n\n## \u6570\u636e\u6587\u4ef6 (File Path)\n\n\u6caa\u6df1\u5e02\u573a\n\n```\ncn_stock_holidays/data.txt\n```\n\n\u9999\u6e2f\u5e02\u573a\n\n```\ncn_stock_holidays/data_hk.txt\n```\n\nFetch Data via URL :\n\n```\nwget https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt\n\nor\n\ncurl https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt\n```\n\n## \u6587\u4ef6\u5185\u5bb9 ( File Content)\n\n\u4fdd\u5b58\u9664\u4e86\u5468\u516d\u65e5\u4f11\u5e02\u4e4b\u5916\uff0c\u5176\u5b83\u4f11\u5e02\u4fe1\u606f\uff0c\u6362\u884c\u5206\u5272\n\nstore all (even upcoming) holiday for china stock exchange (without regular market close date on Saturday Day and Sun Day ) , one date per line\n\n## \u683c\u5f0f(File Format)\n\n```\nYYYYMMDD\n```\n\n## Python version\n\n```\npip install cn-stock-holidays\n```\n\nor\n\n```\npip install git+https://github.com/rainx/cn_stock_holidays.git\n```\n\n### \u5bfc\u5165\n\n```python\n\n# \u9488\u5bf9\u6caa\u6df1\nimport cn_stock_holidays.data as shsz\n\n# \u9488\u5bf9\u9999\u6e2f\nimport cn_stock_holidays.data_hk as hkex\n\n```\n\n### Functions\n\n```python\nHelp on module cn_stock_holidays.data in cn_stock_holidays:\n\nNAME\n cn_stock_holidays.data - Help functions for python to get china stock exchange holidays\n\nFILE\n /Users/rainx/dev/cn_stock_holidays/cn_stock_holidays/data.py\n\nFUNCTIONS\n check_expired()\n check if local or cached data need update\n :return: true/false\n\n date_to_int(da)\n\n date_to_str(da)\n\n get_cache_path()\n\n get_cached()\n get from cache version , if it is not exising , use txt file in package data\n :return: a list contains all holiday data, element with datatime.date format\n\n get_local()\n read data from package data file\n :return: a list contains all holiday data, element with datatime.date format\n\n get_remote_and_cache()\n get newest data file from network and cache on local machine\n :return: a list contains all holiday data, element with datatime.date format\n\n int_to_date(d)\n\n str_to_int(s)\n\n sync_data()\n\n\n is_trading_day(dt)\n param dt: datetime.datetime or datetime.date.\n is a trading day or not\n :returns: Bool\n\n previous_trading_day(dt):\n param dt: datetime.datetime or datetime.date.\n get previous trading day\n :returns: datetime.date\n\n next_trading_day(dt):\n param dt: datetime.datetime or datetime.date.\n get next trading day\n :returns: datetime.date\n\n trading_days_between(start, end):\n\n param start, end: start and end time , datetime.datetime or datetime.date\n get calendar data range\n :returns: a generator for available dates for chinese market included start and end date\n```\n\n### about function cache\n\nfrom version 0.10 on, we used functools.lrucache on `get_cached` for getting more speech,\nif needed you can used the following syntax to clear cache.\n\n```python\nget_cached.cache_clear() \n\n```\n\n### Keep it up-to-date\n\nwe had a script to check the expired of the data and fetch the data from web.\n\nyou could set it up on cron job\n\n```crontab\n0 0 * * * /usr/local/bin/cn-stock-holiday-sync > /tmp/cn_stock_holiday_sync.log\n```\n\nYou could get the absolute path of cn-stock-holiday-sync by which command\n\n\u6caa\u6df1\n\n```bash\nwhich cn-stock-holiday-sync\n```\n\n\u9999\u6e2f\n\n```bash\nwhich cn-stock-holiday-sync-hk\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A List of china stock exchange holidays",
"version": "1.12",
"project_urls": {
"Homepage": "https://github.com/rainx/cn_stock_holidays.git"
},
"split_keywords": [
"china stock holiday exchange shanghai",
" shenzhen and hongkong"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6217e7fcdd40f93621eb07051037dda0481ec48e0dd9ad8496d30ebb98dbaa6e",
"md5": "5657656263ce865ed18fd2984541b47f",
"sha256": "4774e2b07802477cac9dedc7ca5dbfca369408c0b29bd19c1a08bb4cb25be01a"
},
"downloads": -1,
"filename": "cn_stock_holidays-1.12.tar.gz",
"has_sig": false,
"md5_digest": "5657656263ce865ed18fd2984541b47f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12739,
"upload_time": "2024-12-03T06:11:11",
"upload_time_iso_8601": "2024-12-03T06:11:11.471669Z",
"url": "https://files.pythonhosted.org/packages/62/17/e7fcdd40f93621eb07051037dda0481ec48e0dd9ad8496d30ebb98dbaa6e/cn_stock_holidays-1.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-03 06:11:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "rainx",
"github_project": "cn_stock_holidays",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cn-stock-holidays"
}