From 70d0e30ad4ceda04f08a8125d9c45d4096542f4c Mon Sep 17 00:00:00 2001 From: shinny-pack Date: Mon, 13 Dec 2021 03:07:24 +0000 Subject: [PATCH] Update Version 3.0.3 --- PKG-INFO | 2 +- doc/conf.py | 4 ++-- doc/version.rst | 5 +++++ setup.py | 2 +- tqsdk/__version__.py | 2 +- tqsdk/api.py | 9 +++++---- tqsdk/calendar.py | 21 ++++++++++++++++----- tqsdk/multiaccount.py | 1 - 8 files changed, 31 insertions(+), 15 deletions(-) diff --git a/PKG-INFO b/PKG-INFO index e61b02ea..97fa8c3e 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: tqsdk -Version: 3.0.2 +Version: 3.0.3 Summary: TianQin SDK Home-page: https://www.shinnytech.com/tqsdk Author: TianQin diff --git a/doc/conf.py b/doc/conf.py index 05d0a0c7..0b015e1b 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -48,9 +48,9 @@ # built documents. # # The short X.Y version. -version = u'3.0.2' +version = u'3.0.3' # The full version, including alpha/beta/rc tags. -release = u'3.0.2' +release = u'3.0.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/version.rst b/doc/version.rst index 95dd2989..bbf9c21f 100644 --- a/doc/version.rst +++ b/doc/version.rst @@ -2,6 +2,11 @@ 版本变更 ============================= +3.0.3 (2021/12/10) + +* 修复:从服务器更新节假日表,修复 :py:meth:`~tqsdk.api.TqApi.get_trading_calendar` 接口文档及报错信息 + + 3.0.2 (2021/12/07) * 修复:调用 :py:meth:`~tqsdk.api.TqApi.get_kline_serial` 接口获取股票前复权 Kline 时,复权计算结果可能出错的问题 diff --git a/setup.py b/setup.py index 54d5f259..9f5e3d7b 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ def get_tag(self): setuptools.setup( name='tqsdk', - version="3.0.2", + version="3.0.3", description='TianQin SDK', author='TianQin', author_email='tianqincn@gmail.com', diff --git a/tqsdk/__version__.py b/tqsdk/__version__.py index da4039bc..d2983471 100644 --- a/tqsdk/__version__.py +++ b/tqsdk/__version__.py @@ -1 +1 @@ -__version__ = '3.0.2' +__version__ = '3.0.3' diff --git a/tqsdk/api.py b/tqsdk/api.py index bfa6683c..baeaf8c8 100644 --- a/tqsdk/api.py +++ b/tqsdk/api.py @@ -63,7 +63,7 @@ from tqsdk.backtest import TqBacktest, TqReplay from tqsdk.channel import TqChan from tqsdk.connect import TqConnect, MdReconnectHandler, ReconnectTimer -from tqsdk.calendar import _get_trading_calendar, TqContCalendar +from tqsdk.calendar import _get_trading_calendar, TqContCalendar, _init_chinese_rest_days from tqsdk.data_extension import DataExtension from tqsdk.data_series import DataSeries from tqsdk.datetime import _get_trading_day_start_time, _get_trading_day_end_time, _get_trading_day_from_timestamp @@ -982,7 +982,7 @@ def _get_data_series(self, call_func: str, symbol_list: Union[str, List[str]], d # ---------------------------------------------------------------------- def get_trading_calendar(self, start_dt: Union[date, datetime], end_dt: Union[date, datetime]): """ - 获取一段时间内的交易日历信息,交易日历可以处理的范围为 2003-01-01 ~ 2021-12-31。 + 获取一段时间内的交易日历信息,交易日历可以处理的范围为 2003-01-01 ~ 2022-12-31。 Args: start_dt (date/datetime): 起始时间,如果类型为 date 则指的是该日期;如果为 datetime 则指的是该时间点所在日期 @@ -1024,8 +1024,9 @@ def get_trading_calendar(self, start_dt: Union[date, datetime], end_dt: Union[da end_dt = date(year=end_dt.year, month=end_dt.month, day=end_dt.day) elif not isinstance(end_dt, date): raise Exception(f"end_dt 参数类型 {type(end_dt)} 错误, 只支持 datetime / date 类型,请检查是否正确") - if start_dt < date(2003, 1, 1) or end_dt > date(2021, 12, 31): - raise Exception(f"交易日历可以处理的范围为 2003-01-01 ~ 2021-12-31,请修改参数") + first_date, latest_date = _init_chinese_rest_days() + if start_dt < first_date or end_dt > latest_date: + raise Exception(f"交易日历可以处理的范围为 {first_date.strftime('%Y-%m-%d')} ~ {latest_date.strftime('%Y-%m-%d')},请修改参数") return _get_trading_calendar(start_dt, end_dt) # ---------------------------------------------------------------------- diff --git a/tqsdk/calendar.py b/tqsdk/calendar.py index 8b829fc8..fced1208 100644 --- a/tqsdk/calendar.py +++ b/tqsdk/calendar.py @@ -14,11 +14,21 @@ import pandas as pd -# 2003-01-01 ~ 2022-12-31 节假日,不包含周末 -CHINESE_REST_DAYS = ['2003-01-01', '2003-01-30', '2003-01-31', '2003-02-03', '2003-02-04', '2003-02-05', '2003-02-06', '2003-02-07', '2003-05-01', '2003-05-02', '2003-05-05', '2003-05-06', '2003-05-07', '2003-10-01', '2003-10-02', '2003-10-03', '2003-10-06', '2003-10-07', '2004-01-01', '2004-01-19', '2004-01-20', '2004-01-21', '2004-01-22', '2004-01-23', '2004-01-26', '2004-01-27', '2004-01-28', '2004-05-03', '2004-05-04', '2004-05-05', '2004-05-06', '2004-05-07', '2004-10-01', '2004-10-04', '2004-10-05', '2004-10-06', '2004-10-07', '2005-01-03', '2005-02-07', '2005-02-08', '2005-02-09', '2005-02-10', '2005-02-11', '2005-02-14', '2005-02-15', '2005-05-02', '2005-05-03', '2005-05-04', '2005-05-05', '2005-05-06', '2005-10-03', '2005-10-04', '2005-10-05', '2005-10-06', '2005-10-07', '2006-01-02', '2006-01-03', '2006-01-30', '2006-01-31', '2006-02-01', '2006-02-02', '2006-02-03', '2006-05-01', '2006-05-02', '2006-05-03', '2006-05-04', '2006-05-05', '2006-10-02', '2006-10-03', '2006-10-04', '2006-10-05', '2006-10-06', '2007-01-01', '2007-01-02', '2007-01-03', '2007-02-19', '2007-02-20', '2007-02-21', '2007-02-22', '2007-02-23', '2007-05-01', '2007-05-02', '2007-05-03', '2007-05-04', '2007-05-07', '2007-10-01', '2007-10-02', '2007-10-03', '2007-10-04', '2007-10-05', '2007-12-31', '2008-01-01', '2008-02-06', '2008-02-07', '2008-02-08', '2008-02-11', '2008-02-12', '2008-04-04', '2008-05-01', '2008-05-02', '2008-06-09', '2008-09-15', '2008-09-29', '2008-09-30', '2008-10-01', '2008-10-02', '2008-10-03', '2009-01-01', '2009-01-02', '2009-01-26', '2009-01-27', '2009-01-28', '2009-01-29', '2009-01-30', '2009-04-06', '2009-05-01', '2009-05-28', '2009-05-29', '2009-10-01', '2009-10-02', '2009-10-05', '2009-10-06', '2009-10-07', '2009-10-08', '2010-01-01', '2010-02-15', '2010-02-16', '2010-02-17', '2010-02-18', '2010-02-19', '2010-04-05', '2010-05-03', '2010-06-14', '2010-06-15', '2010-06-16', '2010-09-22', '2010-09-23', '2010-09-24', '2010-10-01', '2010-10-04', '2010-10-05', '2010-10-06', '2010-10-07', '2011-01-03', '2011-02-02', '2011-02-03', '2011-02-04', '2011-02-07', '2011-02-08', '2011-04-04', '2011-04-05', '2011-05-02', '2011-06-06', '2011-09-12', '2011-10-03', '2011-10-04', '2011-10-05', '2011-10-06', '2011-10-07', '2012-01-02', '2012-01-03', '2012-01-23', '2012-01-24', '2012-01-25', '2012-01-26', '2012-01-27', '2012-04-02', '2012-04-03', '2012-04-04', '2012-04-30', '2012-05-01', '2012-06-22', '2012-10-01', '2012-10-02', '2012-10-03', '2012-10-04', '2012-10-05', '2013-01-01', '2013-01-02', '2013-01-03', '2013-02-11', '2013-02-12', '2013-02-13', '2013-02-14', '2013-02-15', '2013-04-04', '2013-04-05', '2013-04-29', '2013-04-30', '2013-05-01', '2013-06-10', '2013-06-11', '2013-06-12', '2013-09-19', '2013-09-20', '2013-10-01', '2013-10-02', '2013-10-03', '2013-10-04', '2013-10-07', '2014-01-01', '2014-01-31', '2014-02-03', '2014-02-04', '2014-02-05', '2014-02-06', '2014-04-07', '2014-05-01', '2014-05-02', '2014-06-02', '2014-09-08', '2014-10-01', '2014-10-02', '2014-10-03', '2014-10-06', '2014-10-07', '2015-01-01', '2015-01-02', '2015-02-18', '2015-02-19', '2015-02-20', '2015-02-23', '2015-02-24', '2015-04-06', '2015-05-01', '2015-06-22', '2015-09-03', '2015-09-04', '2015-10-01', '2015-10-02', '2015-10-05', '2015-10-06', '2015-10-07', '2016-01-01', '2016-02-08', '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12', '2016-04-04', '2016-05-02', '2016-06-09', '2016-06-10', '2016-09-15', '2016-09-16', '2016-10-03', '2016-10-04', '2016-10-05', '2016-10-06', '2016-10-07', '2017-01-02', '2017-01-27', '2017-01-30', '2017-01-31', '2017-02-01', '2017-02-02', '2017-04-03', '2017-04-04', '2017-05-01', '2017-05-29', '2017-05-30', '2017-10-02', '2017-10-03', '2017-10-04', '2017-10-05', '2017-10-06', '2018-01-01', '2018-02-15', '2018-02-16', '2018-02-19', '2018-02-20', '2018-02-21', '2018-04-05', '2018-04-06', '2018-04-30', '2018-05-01', '2018-06-18', '2018-09-24', '2018-10-01', '2018-10-02', '2018-10-03', '2018-10-04', '2018-10-05', '2018-12-31', '2019-01-01', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-04-05', '2019-05-01', '2019-05-02', '2019-05-03', '2019-06-07', '2019-09-13', '2019-10-01', '2019-10-02', '2019-10-03', '2019-10-04', '2019-10-07', '2020-01-01', '2020-01-24', '2020-01-27', '2020-01-28', '2020-01-29', '2020-01-30', '2020-01-31', '2020-04-06', '2020-05-01', '2020-05-04', '2020-05-05', '2020-06-25', '2020-06-26', '2020-10-01', '2020-10-02', '2020-10-05', '2020-10-06', '2020-10-07', '2020-10-08', '2021-01-01', '2021-02-11', '2021-02-12', '2021-02-15', '2021-02-16', '2021-02-17', '2021-04-05', '2021-05-03', '2021-05-04', '2021-05-05', '2021-06-14', '2021-09-20', '2021-09-21', '2021-10-01', '2021-10-04', '2021-10-05', '2021-10-06', '2021-10-07', - "2022-01-03", "2022-01-31", "2022-02-01", "2022-02-02", "2022-02-03", "2022-02-04", "2022-04-04", "2022-04-05", "2022-05-02", "2022-05-03", "2022-05-04", "2022-06-03", "2022-09-12", "2022-10-03", "2022-10-04", "2022-10-05", "2022-10-06", "2022-10-07"] -rest_days_df = pd.DataFrame(data={'date': pd.Series(pd.to_datetime(CHINESE_REST_DAYS, format='%Y-%m-%d'))}) -rest_days_df['trading_restdays'] = False # 节假日为 False +rest_days_df = None +chinese_holidays_range = None + + +def _init_chinese_rest_days(): + global rest_days_df, chinese_holidays_range + if rest_days_df is None: + rsp = requests.get("https://files.shinnytech.com/shinny_chinese_holiday.json", timeout=30) + chinese_holidays = rsp.json() + _first_day = date(int(chinese_holidays[0].split('-')[0]), 1, 1) # 首个日期所在年份的第一天 + _last_day = date(int(chinese_holidays[-1].split('-')[0]), 12, 31) # 截止日期所在年份的最后一天 + chinese_holidays_range = (_first_day, _last_day) + rest_days_df = pd.DataFrame(data={'date': pd.Series(pd.to_datetime(chinese_holidays, format='%Y-%m-%d'))}) + rest_days_df['trading_restdays'] = False # 节假日为 False + return chinese_holidays_range def _get_trading_calendar(start_dt: date, end_dt: date): @@ -33,6 +43,7 @@ def _get_trading_calendar(start_dt: date, end_dt: date): 2019-12-08 False 2019-12-09 True """ + _init_chinese_rest_days() df = pd.DataFrame() df['date'] = pd.Series(pd.date_range(start=start_dt, end=end_dt, freq="D")) df['trading'] = df['date'].dt.dayofweek.lt(5) diff --git a/tqsdk/multiaccount.py b/tqsdk/multiaccount.py index ed1d8684..f24f4e8e 100644 --- a/tqsdk/multiaccount.py +++ b/tqsdk/multiaccount.py @@ -23,7 +23,6 @@ class TqMultiAccount(object): **注意** - - 多账户模式暂未支持 `webgui` - 多账户模式下, 对于 get_position,account,insert_order,set_target_volume 等函数必须指定 account 参数 - 多账户模式下, 实盘账户的数量受限于信易账户支持实盘账户数, 详见:`更多的实盘交易账户数 `_