diff --git a/docs/API_REFERENCE.md b/docs/API_REFERENCE.md index 9fb0186..a64117d 100644 --- a/docs/API_REFERENCE.md +++ b/docs/API_REFERENCE.md @@ -6,7 +6,7 @@ | 指标 | 数量 | |---|---:| -| SDK 方法总数 | 244 | +| SDK 方法总数 | 248 | ## 专题分布 @@ -18,11 +18,11 @@ | 指数专题 | 15 | `ftshare.apis.index` | `ftshare.endpoints.index` | | ETF专题 | 17 | `ftshare.apis.etf` | `ftshare.endpoints.etf` | | 公募基金 | 18 | `ftshare.apis.fund` | `ftshare.endpoints.fund` | -| 期货数据 | 20 | `ftshare.apis.futures` | `ftshare.endpoints.futures` | +| 期货数据 | 21 | `ftshare.apis.futures` | `ftshare.endpoints.futures` | | 债券专题 | 9 | `ftshare.apis.bond` | `ftshare.endpoints.bond` | | 宏观经济 | 23 | `ftshare.apis.economic` | `ftshare.endpoints.economic` | -| 大模型语料 | 5 | `ftshare.apis.llm_corpus` | `ftshare.endpoints.llm_corpus` | -| 现货数据 | 1 | `ftshare.apis.spot` | `ftshare.endpoints.spot` | +| 大模型语料 | 7 | `ftshare.apis.llm_corpus` | `ftshare.endpoints.llm_corpus` | +| 现货数据 | 2 | `ftshare.apis.spot` | `ftshare.endpoints.spot` | | 外汇数据 | 0 | `ftshare.apis.forex` | `ftshare.endpoints.forex` | ## 接口索引 @@ -269,6 +269,7 @@ | [`futures_minutes_realtime`](#api-futures-minutes-realtime) | 期货实时分钟K线 | `GET` | `api/v4/market/data/futures_minutes/realtime` | `symbols` | `期货实时分钟K线.md` | | [`futures_realtime_day_kline`](#api-futures-realtime-day-kline) | 期货实时日K线 | `GET` | `api/v4/market/data/futures-realtime-day-kline` | `symbols` | `期货实时日K线.md` | | [`futures_nanhua_index_kline`](#api-futures-nanhua-index-kline) | 南华期货指数日K线 | `GET` | `api/v1/market/data/futures/nanhua-index-kline` | `code`, `trade_date`, `start_date`, `end_date`, `page`, `page_size` | `南华期货指数日K线.md` | +| [`index_fut_depth`](#api-index-fut-depth) | 股指期货与指数深度行情 | `GET` | `api/v1/market/data/index-fut/depth` | `trade_date`, `start_date`, `end_date`, `code_prefix` | `股指期货与指数深度行情.md` | | [`major_contract`](#api-major-contract) | 重大合同 | `GET` | `api/v1/market/data/corporate/contract` | `start_date`, `end_date` | `重大合同.md` | | [`major_contract_by_symbol`](#api-major-contract-by-symbol) | 重大合同按标的 | `GET` | `api/v1/market/data/corporate/contract/by-symbol` | `symbol`, `page`, `page_size` | `重大合同按标的.md` | | [`major_contract_summary`](#api-major-contract-summary) | 重大合同汇总 | `GET` | `api/v1/market/data/corporate/contract/summary` | `page`, `page_size` | `重大合同汇总.md` | @@ -319,6 +320,8 @@ | SDK 方法 | 接口名称 | HTTP | Path | 参数 | 来源文档 | |---|---|---|---|---|---| +| [`market_announcements`](#api-market-announcements) | 全市场公告列表 | `GET` | `api/v2/market/data/announcements/market-announcements` | `keyword`, `category`, `stock_code`, `start_date`, `end_date`, `plate`, `column_type`, `page`, `page_size` | `全市场公告列表.md` | +| [`periodic_reports`](#api-periodic-reports) | 定期报告列表 | `GET` | `api/v2/market/data/announcements/periodic-reports` | `stock_code`, `report_type`, `report_year`, `document_variant`, `page`, `page_size` | `定期报告列表.md` | | [`semantic_search_news`](#api-semantic-search-news) | 新闻语义搜索 | `GET` | `api/v3/market/data/semantic-search-news` | `query`, `limit`, `year`, `start_time`, `end_time` | `新闻语义搜索.md` | | [`shareholders_meeting`](#api-shareholders-meeting) | 股东大会 | `GET` | `api/v1/market/data/corporate/meeting` | `page`, `page_size` | `股东大会.md` | | [`stock_announcements`](#api-stock-announcements) | 公告列表 | `GET` | `api/v2/market/data/announcements/stock-announcements` | `stock_code`, `start_date`, `end_date`, `type`, `page`, `page_size` | `公告列表.md` | @@ -331,6 +334,7 @@ | SDK 方法 | 接口名称 | HTTP | Path | 参数 | 来源文档 | |---|---|---|---|---|---| | [`bullion_price`](#api-bullion-price) | 贵金属价格 | `GET` | `api/v1/market/data/bullion/price` | `symbol`, `start_date`, `end_date`, `page`, `page_size` | `贵金属价格.md` | +| [`sge_spot_description_all`](#api-sge-spot-description-all) | 上金所现货品种 | `GET` | `api/v1/market/data/sge-spot-description-all` | `category`, `active_only` | `上金所现货品种.md` | ## 接口详情 @@ -5312,6 +5316,40 @@ Returns: ``as_dataframe=False``, or raw JSON when ``raw=True``. ``` +

index_fut_depth

+ +- 接口名称:股指期货与指数深度行情 +- HTTP:`GET` +- Path:`api/v1/market/data/index-fut/depth` +- 参数:`trade_date`, `start_date`, `end_date`, `code_prefix` +- 来源文档:`股指期货与指数深度行情.md` +- 原始接口:`index_fut_depth` + +```text +股指期货与指数深度行情. + +Endpoint: ``api/v1/market/data/index-fut/depth``. +Method: ``GET``. +Documented endpoint: ``index_fut_depth``. + +Args: + trade_date: 单日查询日期 YYYYMMDD;不传日期参数时查询最新交易日,与 start_date、end_date 互斥 (type: string; required: N). + start_date: 历史区间起始交易日 YYYYMMDD;必须与 end_date 同时传入 (type: string; required: N). + end_date: 历史区间结束交易日 YYYYMMDD;必须与 start_date 同时传入,区间不能超过 3 年 (type: string; required: N). + code_prefix: 品种筛选,支持 ``IF`` / ``IC`` / ``IM`` / ``IH``,不区分大小写;不传返回全部品种 (type: string; required: N). + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + +Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, or raw JSON when ``raw=True``。服务端返回 + ``data`` 对象(``count`` / ``futures`` / ``index`` / ``instrument_map``), + SDK 直接返回该对象(``as_dataframe=True`` 时为单行 DataFrame, + 嵌套数组保留原样)。 +``` +

major_contract

- 接口名称:重大合同 @@ -6390,6 +6428,83 @@ Returns: ### 大模型语料 +

market_announcements

+ +- 接口名称:全市场公告列表 +- HTTP:`GET` +- Path:`api/v2/market/data/announcements/market-announcements` +- 参数:`keyword`, `category`, `stock_code`, `start_date`, `end_date`, `plate`, `column_type`, `page`, `page_size` +- 来源文档:`全市场公告列表.md` +- 原始接口:`market_v2_announcements_market_announcements` + +```text +全市场公告列表. + +Endpoint: ``api/v2/market/data/announcements/market-announcements``. +Method: ``GET``. +Documented endpoint: ``market_v2_announcements_market_announcements``. + +Args: + keyword: 公告标题关键字,子串匹配;去首尾空格后最长 60 字符 (type: string; required: N). + category: 公告分类,22 个允许值逗号分隔多选,任一命中即返回 (type: string; required: N). + stock_code: 股票代码;支持裸代码、短后缀、长后缀与冒号格式 (type: string; required: N). + start_date: 起始日期 YYYYMMDD;单独提供时查询该单日 (type: string; required: N). + end_date: 结束日期 YYYYMMDD;不能单独提供,须与 start_date 成对使用 (type: string; required: N). + plate: 板块,取值 ``sh`` / ``sz`` / ``sz_chi_next`` / ``sh_star`` / ``bj``,逗号分隔多选 (type: string; required: N). + column_type: 栏目,取值 ``stock`` / ``hke`` / ``fund`` / ``bond``,逗号分隔多选 (type: string; required: N). + page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set. + page_size: Rows per page. The SDK validates this against the endpoint-specific maximum. + limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit. + all_pages: Fetch and combine pages until the server reports the last page. + max_pages: Optional safety cap for ``all_pages``. + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + +Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, raw JSON when ``raw=True``, or raw page + payloads when multi-page fetching is used with ``raw=True``. +``` + +

periodic_reports

+ +- 接口名称:定期报告列表 +- HTTP:`GET` +- Path:`api/v2/market/data/announcements/periodic-reports` +- 参数:`stock_code`, `report_type`, `report_year`, `document_variant`, `page`, `page_size` +- 来源文档:`定期报告列表.md` +- 原始接口:`market_v2_announcements_periodic_reports` + +```text +定期报告列表. + +Endpoint: ``api/v2/market/data/announcements/periodic-reports``. +Method: ``GET``. +Documented endpoint: ``market_v2_announcements_periodic_reports``. + +Args: + stock_code: 股票代码;支持裸代码、短后缀与长后缀(不支持冒号格式) (type: string; required: N). + report_type: 报告类型:``annual`` / ``semi_annual`` / ``q1`` / ``q3`` (type: string; required: N). + report_year: 报告年份,如 2025 (type: integer; required: N). + document_variant: 文件版本类型:``full`` / ``summary`` / ``english`` (type: string; required: N). + page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set. + page_size: Rows per page. The SDK validates this against the endpoint-specific maximum. + limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit. + all_pages: Fetch and combine pages until the server reports the last page. + max_pages: Optional safety cap for ``all_pages``. + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + +Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, raw JSON when ``raw=True``, or raw page + payloads when multi-page fetching is used with ``raw=True``. +``` +

semantic_search_news

- 接口名称:新闻语义搜索 @@ -6631,6 +6746,35 @@ Returns: payloads when multi-page fetching is used with ``raw=True``. ``` +

sge_spot_description_all

+ +- 接口名称:上金所现货品种 +- HTTP:`GET` +- Path:`api/v1/market/data/sge-spot-description-all` +- 参数:`category`, `active_only` +- 来源文档:`上金所现货品种.md` +- 原始接口:`sge_spot_description_all` + +```text +上金所现货品种. + +Endpoint: ``api/v1/market/data/sge-spot-description-all``. +Method: ``GET``. +Documented endpoint: ``sge_spot_description_all``. + +Args: + category: 品种分类筛选:``spot_full`` 现货实盘 / ``spot_forward`` 现货即期 / ``spot_deferred`` 现货延期交收;不传返回全部分类 (type: string; required: N). + active_only: ``true`` 仅返回活跃品种(17 只);不传、``false`` 或空串返回全部(含已下架品种) (type: bool; required: N). + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + +Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, or raw JSON when ``raw=True``. +``` +

eastmoney_all_board_daily_kline

- Path:`api/v1/market/data/eastmoney-all-board-daily-ohlc` diff --git a/pyproject.toml b/pyproject.toml index 5a1892f..6e331c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "ftshare" -version = "1.0.11" +version = "1.0.12" description = "Python SDK for FTShare market data APIs." readme = "README.md" requires-python = ">=3.9" diff --git a/src/ftshare/apis/futures.py b/src/ftshare/apis/futures.py index a059bb9..81f5fd9 100644 --- a/src/ftshare/apis/futures.py +++ b/src/ftshare/apis/futures.py @@ -831,6 +831,58 @@ def futures_nanhua_index_kline( **request_params, ) + def index_fut_depth( + self, + trade_date: Any | None = None, + start_date: Any | None = None, + end_date: Any | None = None, + code_prefix: Any | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """股指期货与指数深度行情. + + Endpoint: ``api/v1/market/data/index-fut/depth``. + Method: ``GET``. + Documented endpoint: ``index_fut_depth``. + + Args: + trade_date: 单日查询日期 YYYYMMDD;不传日期参数时查询最新交易日,与 start_date、end_date 互斥 (type: string; required: N). + start_date: 历史区间起始交易日 YYYYMMDD;必须与 end_date 同时传入 (type: string; required: N). + end_date: 历史区间结束交易日 YYYYMMDD;必须与 start_date 同时传入,区间不能超过 3 年 (type: string; required: N). + code_prefix: 品种筛选,支持 ``IF`` / ``IC`` / ``IM`` / ``IH``,不区分大小写;不传返回全部品种 (type: string; required: N). + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + + Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, or raw JSON when ``raw=True``。服务端返回 + ``data`` 对象(``count`` / ``futures`` / ``index`` / ``instrument_map``), + SDK 直接返回该对象(``as_dataframe=True`` 时为单行 DataFrame, + 嵌套数组保留原样)。 + """ + request_params = { + 'trade_date': trade_date, + 'start_date': start_date, + 'end_date': end_date, + 'code_prefix': code_prefix, + } + request_params.update(kwargs) + path = ENDPOINTS['index_fut_depth'].path + return self.get( + path, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + unwrap_bare_data=True, + **request_params, + ) + def eastmoney_futures_strange(self, exchange: Any | None = None, variety: Any | None = None, contract: Any | None = None, trade_date: Any | None = None, *, raw: bool = False, fields: Sequence[str] | str | None = None, as_dataframe: bool = True, **kwargs: Any) -> Any: """东方财富期货龙虎榜.""" params = {'exchange': exchange, 'variety': variety, 'contract': contract, 'trade_date': trade_date} diff --git a/src/ftshare/apis/llm_corpus.py b/src/ftshare/apis/llm_corpus.py index 1a3c6c2..61dc4d0 100644 --- a/src/ftshare/apis/llm_corpus.py +++ b/src/ftshare/apis/llm_corpus.py @@ -12,6 +12,145 @@ class LlmCorpusApiMixin: """Endpoint methods for the llm_corpus ftshare-doc topic.""" + def market_announcements( + self, + keyword: Any | None = None, + category: Any | None = None, + stock_code: Any | None = None, + start_date: Any | None = None, + end_date: Any | None = None, + plate: Any | None = None, + column_type: Any | None = None, + page: int | None = None, + page_size: int | None = None, + limit: int | None = None, + all_pages: bool = False, + max_pages: int | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """全市场公告列表. + + Endpoint: ``api/v2/market/data/announcements/market-announcements``. + Method: ``GET``. + Documented endpoint: ``market_v2_announcements_market_announcements``. + + Args: + keyword: 公告标题关键字,子串匹配;去首尾空格后最长 60 字符 (type: string; required: N). + category: 公告分类,22 个允许值逗号分隔多选,任一命中即返回 (type: string; required: N). + stock_code: 股票代码;支持裸代码、短后缀、长后缀与冒号格式 (type: string; required: N). + start_date: 起始日期 YYYYMMDD;单独提供时查询该单日 (type: string; required: N). + end_date: 结束日期 YYYYMMDD;不能单独提供,须与 start_date 成对使用 (type: string; required: N). + plate: 板块,取值 ``sh`` / ``sz`` / ``sz_chi_next`` / ``sh_star`` / ``bj``,逗号分隔多选 (type: string; required: N). + column_type: 栏目,取值 ``stock`` / ``hke`` / ``fund`` / ``bond``,逗号分隔多选 (type: string; required: N). + page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set. + page_size: Rows per page. The SDK validates this against the endpoint-specific maximum. + limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit. + all_pages: Fetch and combine pages until the server reports the last page. + max_pages: Optional safety cap for ``all_pages``. + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + + Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, raw JSON when ``raw=True``, or raw page + payloads when multi-page fetching is used with ``raw=True``. + """ + request_params = { + 'keyword': keyword, + 'category': category, + 'stock_code': stock_code, + 'start_date': start_date, + 'end_date': end_date, + 'plate': plate, + 'column_type': column_type, + } + request_params.update(kwargs) + path = ENDPOINTS['market_announcements'].path + return self.get_paginated( + path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['market_announcements'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + + def periodic_reports( + self, + stock_code: Any | None = None, + report_type: Any | None = None, + report_year: Any | None = None, + document_variant: Any | None = None, + page: int | None = None, + page_size: int | None = None, + limit: int | None = None, + all_pages: bool = False, + max_pages: int | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """定期报告列表. + + Endpoint: ``api/v2/market/data/announcements/periodic-reports``. + Method: ``GET``. + Documented endpoint: ``market_v2_announcements_periodic_reports``. + + Args: + stock_code: 股票代码;支持裸代码、短后缀与长后缀(不支持冒号格式) (type: string; required: N). + report_type: 报告类型:``annual`` / ``semi_annual`` / ``q1`` / ``q3`` (type: string; required: N). + report_year: 报告年份,如 2025 (type: integer; required: N). + document_variant: 文件版本类型:``full`` / ``summary`` / ``english`` (type: string; required: N). + page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set. + page_size: Rows per page. The SDK validates this against the endpoint-specific maximum. + limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit. + all_pages: Fetch and combine pages until the server reports the last page. + max_pages: Optional safety cap for ``all_pages``. + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + + Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, raw JSON when ``raw=True``, or raw page + payloads when multi-page fetching is used with ``raw=True``. + """ + request_params = { + 'stock_code': stock_code, + 'report_type': report_type, + 'report_year': report_year, + 'document_variant': document_variant, + } + request_params.update(kwargs) + path = ENDPOINTS['periodic_reports'].path + return self.get_paginated( + path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['periodic_reports'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + def shareholders_meeting( self, page: int | None = None, diff --git a/src/ftshare/apis/spot.py b/src/ftshare/apis/spot.py index 0d8e537..2dcddfd 100644 --- a/src/ftshare/apis/spot.py +++ b/src/ftshare/apis/spot.py @@ -67,3 +67,41 @@ def bullion_price( as_dataframe=as_dataframe, **request_params, ) + + def sge_spot_description_all( + self, + category: Any | None = None, + active_only: Any | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """上金所现货品种. + + Endpoint: ``api/v1/market/data/sge-spot-description-all``. + Method: ``GET``. + Documented endpoint: ``sge_spot_description_all``. + + Args: + category: 品种分类筛选:``spot_full`` 现货实盘 / ``spot_forward`` 现货即期 / ``spot_deferred`` 现货延期交收;不传返回全部分类 (type: string; required: N). + active_only: ``true`` 仅返回活跃品种(17 只);不传、``false`` 或空串返回全部(含已下架品种) (type: bool; required: N). + raw: Return the decoded JSON payload without tabular extraction. + fields: Optional field list or comma-separated field string applied after extraction. + as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows. + **kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated. + + Returns: + A pandas ``DataFrame`` by default, Python rows when + ``as_dataframe=False``, or raw JSON when ``raw=True``. + """ + request_params = {'category': category, 'active_only': active_only} + request_params.update(kwargs) + return self._call_endpoint( + 'sge_spot_description_all', + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) diff --git a/src/ftshare/endpoints/futures.py b/src/ftshare/endpoints/futures.py index a851964..ff71497 100644 --- a/src/ftshare/endpoints/futures.py +++ b/src/ftshare/endpoints/futures.py @@ -125,6 +125,14 @@ 'params': ('code', 'trade_date', 'start_date', 'end_date', 'page', 'page_size'), }, + 'index_fut_depth': { + 'path': 'api/v1/market/data/index-fut/depth', + 'title': '股指期货与指数深度行情', + 'doc_file': '股指期货与指数深度行情.md', + 'original_api': 'index_fut_depth', + 'params': ('trade_date', 'start_date', 'end_date', 'code_prefix'), + }, + 'eastmoney_futures_strange': { 'path': 'api/v1/market/data/eastmoney-futures-strange', 'title': '东方财富期货龙虎榜', diff --git a/src/ftshare/endpoints/llm_corpus.py b/src/ftshare/endpoints/llm_corpus.py index ccdffdf..052d258 100644 --- a/src/ftshare/endpoints/llm_corpus.py +++ b/src/ftshare/endpoints/llm_corpus.py @@ -6,6 +6,22 @@ ENDPOINTS: dict[str, Endpoint] = build_endpoints({ + 'market_announcements': { + 'path': 'api/v2/market/data/announcements/market-announcements', + 'title': '全市场公告列表', + 'doc_file': '全市场公告列表.md', + 'original_api': 'market_v2_announcements_market_announcements', + 'params': ('keyword', 'category', 'stock_code', 'start_date', 'end_date', 'plate', 'column_type', 'page', 'page_size'), + 'max_page_size': 500, + }, + 'periodic_reports': { + 'path': 'api/v2/market/data/announcements/periodic-reports', + 'title': '定期报告列表', + 'doc_file': '定期报告列表.md', + 'original_api': 'market_v2_announcements_periodic_reports', + 'params': ('stock_code', 'report_type', 'report_year', 'document_variant', 'page', 'page_size'), + 'max_page_size': 500, + }, 'semantic_search_news': { 'path': 'api/v3/market/data/semantic-search-news', 'title': '新闻语义搜索', diff --git a/src/ftshare/endpoints/spot.py b/src/ftshare/endpoints/spot.py index 56f2cf6..ea64e36 100644 --- a/src/ftshare/endpoints/spot.py +++ b/src/ftshare/endpoints/spot.py @@ -13,4 +13,11 @@ 'original_api': 'get_bullion_price', 'params': ('symbol', 'start_date', 'end_date', 'page', 'page_size'), }, + 'sge_spot_description_all': { + 'path': 'api/v1/market/data/sge-spot-description-all', + 'title': '上金所现货品种', + 'doc_file': '上金所现货品种.md', + 'original_api': 'sge_spot_description_all', + 'params': ('category', 'active_only'), + }, }) diff --git a/tests/endpoint_cases.py b/tests/endpoint_cases.py index a07777c..4153107 100644 --- a/tests/endpoint_cases.py +++ b/tests/endpoint_cases.py @@ -5,6 +5,7 @@ SAMPLE_VALUES: dict[str, Any] = { + "active_only": True, "adjust": "Forward", "adjust_kind": "forward", "announcement_id": "announcement-1", @@ -28,6 +29,8 @@ "classify_std": "证监会行业分类", "client_type": "一般", "code": "000001.SZ", + "code_prefix": "IF", + "column_type": "stock", "compat": "v2", "con_code": "000001", "con_name": "平安银行", @@ -42,6 +45,7 @@ "date": "20260717", "days": 5, "direction": "forward", + "document_variant": "full", "end": "20260717", "end_date": "20260717", "end_week": "202630", @@ -69,6 +73,7 @@ "invest_type": "all", "is_inoffice": "1", "is_last": True, + "keyword": "年度报告", "level": "1", "list_type": "热股", "limit": 5, @@ -91,6 +96,7 @@ "page_size": 5, "pattern": "双重顶", "period": "2024", + "plate": "sh", "prd": "螺纹钢", "prediction_date": "20260717", "publish_date": "20260717", @@ -101,6 +107,7 @@ "refresh": False, "report_date": 20260331, "report_type": "annual", + "report_year": 2025, "rept_type": "annual", "request_id": "request-1", "scope": "ChinaStock", diff --git a/tests/test_client.py b/tests/test_client.py index 0954637..1454439 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1879,3 +1879,94 @@ def test_ths_board_constituents_allows_page_size_up_to_1000(): with pytest.raises(ValueError, match="page_size must be between 1 and 1000"): client.ths_board_constituents(board_code="300082", page_size=1001) + + +def test_sge_spot_description_all_forwards_filters(): + rows = [{"symbol": "AUTD.SGEX", "category": "spot_deferred"}] + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": rows})]) + client = FtshareClient(session=session) + + result = client.sge_spot_description_all(category="spot_deferred", active_only=True, as_dataframe=False) + + assert result == rows + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v1/market/data/sge-spot-description-all" + assert session.calls[0]["params"] == {"category": "spot_deferred", "active_only": "true"} + + +def test_market_announcements_forwards_filters_and_allows_page_size_500(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.market_announcements( + keyword="年度报告", + category="annual", + stock_code="000001.SZ", + start_date="20261001", + end_date="20261031", + plate="sh", + column_type="stock", + page=1, + page_size=500, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/announcements/market-announcements" + assert session.calls[0]["params"] == { + "keyword": "年度报告", + "category": "annual", + "stock_code": "000001.SZ", + "start_date": "20261001", + "end_date": "20261031", + "plate": "sh", + "column_type": "stock", + "page": 1, + "page_size": 500, + } + + with pytest.raises(ValueError, match="page_size must be between 1 and 500"): + client.market_announcements(page_size=501) + + +def test_periodic_reports_forwards_filters_and_allows_page_size_500(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.periodic_reports( + stock_code="000001.SZ", + report_type="annual", + report_year=2025, + document_variant="full", + page=1, + page_size=500, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/announcements/periodic-reports" + assert session.calls[0]["params"] == { + "stock_code": "000001.SZ", + "report_type": "annual", + "report_year": 2025, + "document_variant": "full", + "page": 1, + "page_size": 500, + } + + with pytest.raises(ValueError, match="page_size must be between 1 and 500"): + client.periodic_reports(page_size=501) + + +def test_index_fut_depth_unwraps_bare_object_data(): + data = { + "count": 1, + "futures": [{"trade_date": "20261030", "code_prefix": "IF"}], + "index": [{"trade_date": "20261030", "symbol_id": 300, "name": "沪深300"}], + "instrument_map": {"fut_info": [], "index_info": []}, + } + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": data})]) + client = FtshareClient(session=session) + + result = client.index_fut_depth(trade_date="20261030", code_prefix="IF", as_dataframe=False) + + assert result == data + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v1/market/data/index-fut/depth" + assert session.calls[0]["params"] == {"trade_date": "20261030", "code_prefix": "IF"}