From 5c1a981385c4b58baa0487254308732101e79e5f Mon Sep 17 00:00:00 2001 From: zhuhao Date: Fri, 4 Dec 2026 13:23:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E8=BF=9E?= =?UTF-8?q?=E6=9D=BF=E5=A4=A9=E6=A2=AF=E3=80=81=E5=B8=82=E5=9C=BA=E6=83=85?= =?UTF-8?q?=E7=BB=AA=E3=80=81=E6=B8=AF=E8=82=A1=E5=85=AC=E5=91=8A=E4=B8=8E?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=90=8E=E7=A0=94=E6=8A=A5=20SDK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 limit_ladder_daily / limit_ladder_summary / market_sentiment - 新增 hk_market_announcements / hk_periodic_announcements - 新增解析后个股/行业研报列表、预览与 ZIP 下载方法 - 同步端点注册、API_REFERENCE 与契约测试 Co-Authored-By: Claude Code --- CHANGELOG.md | 3 + docs/API_REFERENCE.md | 391 +++++++++++++++++++++++++++- src/ftshare/apis/hk.py | 138 ++++++++++ src/ftshare/apis/llm_corpus.py | 279 ++++++++++++++++++++ src/ftshare/apis/stock.py | 151 +++++++++++ src/ftshare/endpoints/hk.py | 16 ++ src/ftshare/endpoints/llm_corpus.py | 28 ++ src/ftshare/endpoints/stock.py | 24 ++ tests/endpoint_cases.py | 8 + tests/test_client.py | 218 ++++++++++++++++ 10 files changed, 1252 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f6f8d..461f5ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New sector knowledge endpoints: `sector_knowledge_facts` (板块事实检索) and `sector_knowledge_insights` (板块洞察检索) with keyword/expression, category, date, score and sort filters plus pagination; `sector_knowledge_sectors` (板块描述列表) and `sector_knowledge_search_options` (板块知识检索选项) for name and enum discovery. - New `futures_dominant_mapping` (期货主力合约映射) endpoint returning each exchange/variety's dominant contract for a trade date, with the `v1`–`v4` rule selection. +- New limit-up and sentiment endpoints: `limit_ladder_daily` (连板天梯明细), `limit_ladder_summary` (连板天梯汇总) and `market_sentiment` (市场情绪) for daily limit-up tiers, board distribution, promotion/break rates and previous-day limit-up performance. +- New Hong Kong announcement endpoints: `hk_market_announcements` (港股公告列表) and `hk_periodic_announcements` (港股定期公告列表) with category, date and pagination filters. +- New parsed research report endpoints: `parsed_stock_reports` / `parsed_industry_reports` list, `_preview` for content preview and `_download` for ZIP packages with `ETag` conditional download. ### Changed - `ashare_news_sentiment_factors` now accepts the documented single-day `date` parameter; `start_date`/`end_date` must be passed together and span no more than 31 days, and omitting all dates queries the current prediction day. diff --git a/docs/API_REFERENCE.md b/docs/API_REFERENCE.md index 27ab85b..5763734 100644 --- a/docs/API_REFERENCE.md +++ b/docs/API_REFERENCE.md @@ -6,14 +6,14 @@ | 指标 | 数量 | |---|---:| -| SDK 方法总数 | 255 | +| SDK 方法总数 | 266 | ## 专题分布 | ftshare-doc 专题 | SDK 方法数 | API mixin 模块 | Endpoint 模块 | |---|---:|---|---| -| 股票数据 | 135 | `ftshare.apis.stock` | `ftshare.endpoints.stock` | -| 港股数据 | 3 | `ftshare.apis.hk` | `ftshare.endpoints.hk` | +| 股票数据 | 138 | `ftshare.apis.stock` | `ftshare.endpoints.stock` | +| 港股数据 | 5 | `ftshare.apis.hk` | `ftshare.endpoints.hk` | | 美股数据 | 2 | `ftshare.apis.us` | `ftshare.endpoints.us` | | 指数专题 | 16 | `ftshare.apis.index` | `ftshare.endpoints.index` | | ETF专题 | 17 | `ftshare.apis.etf` | `ftshare.endpoints.etf` | @@ -21,7 +21,7 @@ | 期货数据 | 23 | `ftshare.apis.futures` | `ftshare.endpoints.futures` | | 债券专题 | 9 | `ftshare.apis.bond` | `ftshare.endpoints.bond` | | 宏观经济 | 23 | `ftshare.apis.economic` | `ftshare.endpoints.economic` | -| 大模型语料 | 7 | `ftshare.apis.llm_corpus` | `ftshare.endpoints.llm_corpus` | +| 大模型语料 | 13 | `ftshare.apis.llm_corpus` | `ftshare.endpoints.llm_corpus` | | 现货数据 | 2 | `ftshare.apis.spot` | `ftshare.endpoints.spot` | | 外汇数据 | 0 | `ftshare.apis.forex` | `ftshare.endpoints.forex` | @@ -74,10 +74,13 @@ | [`income`](#api-income) | A股利润表 | `GET` | `api/v1/market/data/finance/income` | `stock_code`, `year`, `report_type`, `page`, `page_size` | `A股利润表.md` | | [`kline_pattern_annotations`](#api-kline-pattern-annotations) | K线形态标注 | `GET` | `api/v3/market/data/kline-pattern-annotations` | `date`, `trade_code`, `pattern`, `page`, `page_size` | `K线形态标注.md` | | [`limit_event_timeline_3s`](#api-limit-event-timeline-3s) | 涨跌停事件时间线 | `GET` | `api/v2/market/data/limit-event-timeline-3s` | `symbol`, `trade_date`, `page`, `page_size` | `涨跌停事件时间线.md` | +| [`limit_ladder_daily`](#api-limit-ladder-daily) | 连板天梯明细 | `GET` | `api/v2/market/data/limit-ladder/daily` | `trade_date`, `stock_code`, `status`, `include_st`, `include_new`, `sort`, `page`, `page_size` | `连板天梯明细.md` | +| [`limit_ladder_summary`](#api-limit-ladder-summary) | 连板天梯汇总 | `GET` | `api/v2/market/data/limit-ladder/summary` | `start_date`, `end_date` | `连板天梯汇总.md` | | [`limit_list`](#api-limit-list) | 涨跌停池 | `GET` | `api/v1/market/data/limit-list` | `limit_type`, `trade_date` | `涨跌停池.md` | | [`limit_up_briefs`](#api-limit-up-briefs) | 涨停简报 | `GET` | `api/v3/market/data/limit-up-reports/briefs` | `date` | `涨停简报.md` | | [`limit_up_public_report`](#api-limit-up-public-report) | 涨停对外归因报告 | `GET` | `api/v3/market/data/limit-up-reports/public-report` | `date`, `security_code` | `涨停对外归因报告.md` | | [`margin_trading_details`](#api-margin-trading-details) | 融资融券明细 | `GET` | `api/v1/market/data/margin-trading-details` | `date`, `start_date`, `end_date`, `stock`, `page`, `page_size` | `融资融券明细.md` | +| [`market_sentiment`](#api-market-sentiment) | 市场情绪 | `GET` | `api/v2/market/data/market-sentiment` | `trade_date` | `市场情绪.md` | | [`namechange`](#api-namechange) | 股票曾用名 | `GET` | `api/v1/market/data/namechange` | `trade_code`, `start_date`, `end_date` | `股票曾用名.md` | | [`news_reaction_snapshot`](#api-news-reaction-snapshot) | 消息量价共振 | `GET` | `api/v3/market/data/news-reaction-snapshot` | `symbol`, `start_date`, `end_date`, `lookback_hours`, `page`, `page_size` | `消息量价共振.md` | | [`nth_trade_date`](#api-nth-trade-date) | 第N个交易日 | `GET` | `api/v1/market/data/time/get-nth-trade-date` | `n` | `第N个交易日.md` | @@ -176,6 +179,8 @@ | SDK 方法 | 接口名称 | HTTP | Path | 参数 | 来源文档 | |---|---|---|---|---|---| | [`hk_candlesticks`](#api-hk-candlesticks) | 港股K线 | `GET` | `api/v2/market/data/hk/hk-candlesticks` | `trade_code`, `interval_unit`, `until_date`, `since_date`, `interval_value`, `limit`, `adjust_kind` | `港股K线.md` | +| [`hk_market_announcements`](#api-hk-market-announcements) | 港股公告列表 | `GET` | `api/v2/market/data/announcements/hk-market-announcements` | `keyword`, `category`, `stock_code`, `start_date`, `end_date`, `page`, `page_size` | `港股公告列表.md` | +| [`hk_periodic_announcements`](#api-hk-periodic-announcements) | 港股定期公告列表 | `GET` | `api/v2/market/data/announcements/hk-periodic-announcements` | `keyword`, `report_type`, `stock_code`, `start_date`, `end_date`, `page`, `page_size` | `港股定期公告列表.md` | ### 美股数据 @@ -329,6 +334,12 @@ | 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` | +| [`parsed_industry_reports`](#api-parsed-industry-reports) | 解析后行业研报 | `GET` | `api/v3/market/data/industry-reports` | `start_date`, `end_date`, `sw_l1_code`, `sw_l2_code`, `page`, `page_size` | `解析后行业研报.md` | +| [`parsed_industry_reports_download`](#api-parsed-industry-reports-download) | 解析后行业研报下载 | `GET` | `api/v3/market/data/industry-reports/download` | `download_url`, `save_dir` | `解析后行业研报.md` | +| [`parsed_industry_reports_preview`](#api-parsed-industry-reports-preview) | 解析后行业研报预览 | `GET` | `api/v3/market/data/industry-reports/preview` | `download_url` | `解析后行业研报.md` | +| [`parsed_stock_reports`](#api-parsed-stock-reports) | 解析后个股研报 | `GET` | `api/v3/market/data/stock-reports` | `stock_code`, `start_date`, `end_date`, `report_type`, `download_url`, `page`, `page_size` | `解析后个股研报.md` | +| [`parsed_stock_reports_download`](#api-parsed-stock-reports-download) | 解析后个股研报下载 | `GET` | `api/v3/market/data/stock-reports/download` | `download_url`, `save_dir` | `解析后个股研报.md` | +| [`parsed_stock_reports_preview`](#api-parsed-stock-reports-preview) | 解析后个股研报预览 | `GET` | `api/v3/market/data/stock-reports/preview` | `download_url` | `解析后个股研报.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` | @@ -1312,6 +1323,76 @@ Returns: payloads when multi-page fetching is used with ``raw=True``. ``` +

limit_ladder_daily

+ +- 接口名称:连板天梯明细 +- HTTP:`GET` +- Path:`api/v2/market/data/limit-ladder/daily` +- 参数:`trade_date`, `stock_code`, `status`, `include_st`, `include_new`, `sort`, `page`, `page_size` +- 来源文档:`连板天梯明细.md` +- 原始接口:`limit_ladder_daily` + +```text +连板天梯明细. + +Endpoint: ``api/v2/market/data/limit-ladder/daily``. +Method: ``GET``. +Documented endpoint: ``limit_ladder_daily``. + +Args: + trade_date: 交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 20240102、不得晚于当前日期 (type: string; required: Y). + stock_code: 股票代码,六位代码加 ``.SH`` / ``.SZ`` 后缀;可省略后缀 (type: string; required: N). + status: 状态筛选:``limit_up``(收盘封板)、``broken``(盘中触板但收盘炸板)、``normal``(未触板);不传返回三态全量 (type: string; required: N). + include_st: 是否包含 ST 股票,默认 ``true``;传 ``false`` 剔除 ``st=true`` 的记录 (type: boolean; required: N). + include_new: 是否包含新股,默认 ``true``;传 ``false`` 剔除 ``is_new=true`` 的记录 (type: boolean; required: N). + sort: 排序:``boards_desc``(默认,连板数降序)、``seal_amount_desc``(封板金额降序)、``stock_code_asc``(代码升序) (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``。仅已 + 发布汇总的交易日可查询;无已发布结果或非交易日返回 404。 +``` + +

limit_ladder_summary

+ +- 接口名称:连板天梯汇总 +- HTTP:`GET` +- Path:`api/v2/market/data/limit-ladder/summary` +- 参数:`start_date`, `end_date` +- 来源文档:`连板天梯汇总.md` +- 原始接口:`limit_ladder_summary` + +```text +连板天梯汇总. + +Endpoint: ``api/v2/market/data/limit-ladder/summary``. +Method: ``GET``. +Documented endpoint: ``limit_ladder_summary``. + +Args: + start_date: 起始交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 20240102 (type: string; required: Y). + end_date: 结束交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 ``start_date``、不得晚于当前日期 (type: string; required: Y). + 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``。不分页,按 + 交易日升序返回区间内全部已发布汇总;未发布的日期不返回记录。 +``` +

limit_list

- 接口名称:涨跌停池 @@ -1388,6 +1469,38 @@ Returns: payloads when multi-page fetching is used with ``raw=True``. ``` +

market_sentiment

+ +- 接口名称:市场情绪 +- HTTP:`GET` +- Path:`api/v2/market/data/market-sentiment` +- 参数:`trade_date` +- 来源文档:`市场情绪.md` +- 原始接口:`market_sentiment` + +```text +市场情绪. + +Endpoint: ``api/v2/market/data/market-sentiment``. +Method: ``GET``. +Documented endpoint: ``market_sentiment``. + +Args: + trade_date: 交易日期 YYYYMMDD,最早 20240102 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象,``raw=True`` 时返回完整 JSON 信封。非交易日、未来日期、早于 + 20240102 或当日数据尚未生成时,服务端返回 ``200`` 且 ``data`` 为 + ``None``;此时 SDK 不做解包,``as_dataframe=False`` 返回完整信封 + (``code`` / ``message`` / ``data``),默认 ``DataFrame`` 含 + ``code`` / ``message`` / ``data`` 三列。 +``` +

namechange

- 接口名称:股票曾用名 @@ -3772,6 +3885,86 @@ Returns: payloads when multi-page fetching is used with ``raw=True``. ``` +

hk_market_announcements

+ +- 接口名称:港股公告列表 +- HTTP:`GET` +- Path:`api/v2/market/data/announcements/hk-market-announcements` +- 参数:`keyword`, `category`, `stock_code`, `start_date`, `end_date`, `page`, `page_size` +- 来源文档:`港股公告列表.md` +- 原始接口:`hk_market_announcements` + +```text +港股公告列表. + +Endpoint: ``api/v2/market/data/announcements/hk-market-announcements``. +Method: ``GET``. +Documented endpoint: ``hk_market_announcements``. + +Args: + keyword: 标题关键词,只匹配简体标题,最多 60 字符 (type: string; required: N). + category: 港交所分类:5 位码、完整简体名或短别名,逗号多选,最多 20 个 (type: string; required: N). + stock_code: 港股主代码,支持裸码、``.HK``、``.XHKG``、``HK:`` 前缀 (type: string; required: N). + start_date: 公告日期起点 YYYYMMDD;只传 start_date 时为单日查询 (type: string; required: N). + end_date: 公告日期终点 YYYYMMDD;只给 end_date 返回 400 (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``。不带 + ``stock_code`` 时未传日期默认近 1 年、显式日期跨度最长 1 年;带 + ``stock_code`` 时不限跨度。 +``` + +

hk_periodic_announcements

+ +- 接口名称:港股定期公告列表 +- HTTP:`GET` +- Path:`api/v2/market/data/announcements/hk-periodic-announcements` +- 参数:`keyword`, `report_type`, `stock_code`, `start_date`, `end_date`, `page`, `page_size` +- 来源文档:`港股定期公告列表.md` +- 原始接口:`hk_periodic_announcements` + +```text +港股定期公告列表. + +Endpoint: ``api/v2/market/data/announcements/hk-periodic-announcements``. +Method: ``GET``. +Documented endpoint: ``hk_periodic_announcements``. + +Args: + keyword: 标题关键词,只匹配简体标题,最多 60 字符 (type: string; required: N). + report_type: ``annual`` / ``semi_annual`` / ``quarterly``;不传为三类全部 (type: string; required: N). + stock_code: 港股主代码,支持裸码、``.HK``、``.XHKG``、``HK:`` 前缀 (type: string; required: N). + start_date: 公告日期起点 YYYYMMDD;只传 start_date 时为单日查询 (type: string; required: N). + end_date: 公告日期终点 YYYYMMDD;只给 end_date 返回 400 (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``。同一 + 公告涉及多个报告类型且未指定 ``report_type`` 时,按 + ``annual > semi_annual > quarterly`` 取第一个。 +``` +

eastmoney_us_stock_daily_ohlc

- 接口名称:东方财富美股日OHLC @@ -6763,6 +6956,196 @@ Returns: payloads when multi-page fetching is used with ``raw=True``. ``` +

parsed_stock_reports

+ +- 接口名称:解析后个股研报 +- HTTP:`GET` +- Path:`api/v3/market/data/stock-reports` +- 参数:`stock_code`, `start_date`, `end_date`, `report_type`, `download_url`, `page`, `page_size` +- 来源文档:`解析后个股研报.md` +- 原始接口:`stock_reports_v3` + +```text +解析后个股研报. + +Endpoint: ``api/v3/market/data/stock-reports``. +Method: ``GET``. +Documented endpoint: ``stock_reports_v3``. + +Args: + stock_code: 股票代码,支持裸六码、``.SH`` / ``.SZ`` / ``.BJ`` 或 ``.XSHG`` / ``.XSHE`` / ``.BJSE`` 后缀 (type: string; required: N). + start_date: 披露日期闭区间起点 YYYYMMDD (type: string; required: Y). + end_date: 披露日期闭区间终点 YYYYMMDD,与 ``start_date`` 跨度不超过一年 (type: string; required: Y). + report_type: 研报类型,当前只支持 ``stock`` (type: string; required: N). + download_url: 解析包地址,精确匹配 (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``。日期 + 严格使用 ``YYYYMMDD``;``rating_raw``、``rating_action`` 保留上游 + 原文,缺失时为 ``null``。 +``` + +

parsed_stock_reports_preview

+ +- 接口名称:解析后个股研报预览 +- HTTP:`GET` +- Path:`api/v3/market/data/stock-reports/preview` +- 参数:`download_url` +- 来源文档:`解析后个股研报.md` +- 原始接口:`stock_reports_preview` + +```text +解析后个股研报预览. + +Endpoint: ``api/v3/market/data/stock-reports/preview``. +Method: ``GET``. +Documented endpoint: ``stock_reports_preview``. + +Args: + download_url: 列表返回的解析包地址,原样传回即可;服务端接受 ``http`` / ``https`` URL 或列表返回的相对路径 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象(含摘要原文 ``snippet``、正文预览 ``content_preview``、解析包 + 大小 ``package_size_bytes`` 与素材数 ``asset_count``),``raw=True`` + 时返回完整 JSON 信封。 +``` + +

parsed_stock_reports_download

+ +- 接口名称:解析后个股研报下载 +- HTTP:`GET` +- Path:`api/v3/market/data/stock-reports/download` +- 参数:`download_url` +- 来源文档:`解析后个股研报.md` +- 说明:返回 ``application/zip`` 二进制流,非 JSON 信封;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``;支持 ``ETag`` / ``304`` 条件下载。 + +```text +下载解析后个股研报 ZIP 解析包. + +Endpoint: ``api/v3/market/data/stock-reports/download``. +Method: ``GET``. + +Args: + download_url: 列表返回的解析包地址 (type: string; required: Y). + save_dir: 保存目录(默认为当前目录),目录不存在时自动创建;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``。 + +Returns: + 落盘后的文件路径;服务端返回 2xx 但正文为空时返回空字符串。 + +Raises: + FtshareHTTPError: If the server returns a non-2xx HTTP status. +``` + +

parsed_industry_reports

+ +- 接口名称:解析后行业研报 +- HTTP:`GET` +- Path:`api/v3/market/data/industry-reports` +- 参数:`start_date`, `end_date`, `sw_l1_code`, `sw_l2_code`, `page`, `page_size` +- 来源文档:`解析后行业研报.md` +- 原始接口:`industry_reports` + +```text +解析后行业研报. + +Endpoint: ``api/v3/market/data/industry-reports``. +Method: ``GET``. +Documented endpoint: ``industry_reports``. + +Args: + start_date: 披露日期闭区间起点 YYYYMMDD (type: string; required: Y). + end_date: 披露日期闭区间终点 YYYYMMDD,与 ``start_date`` 跨度不超过一年 (type: string; required: Y). + sw_l1_code: 申万一级行业代码,六位数字;与 ``sw_l2_code`` 同时传入时按 AND 语义精确匹配 (type: string; required: N). + sw_l2_code: 申万二级行业代码,六位数字 (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``。行业 + 筛选只支持代码;``sw_l1_name``、``sw_l2_name`` 只出现在响应中。 +``` + +

parsed_industry_reports_preview

+ +- 接口名称:解析后行业研报预览 +- HTTP:`GET` +- Path:`api/v3/market/data/industry-reports/preview` +- 参数:`download_url` +- 来源文档:`解析后行业研报.md` +- 原始接口:`industry_reports_preview` + +```text +解析后行业研报预览. + +Endpoint: ``api/v3/market/data/industry-reports/preview``. +Method: ``GET``. +Documented endpoint: ``industry_reports_preview``. + +Args: + download_url: 列表返回的解析包地址,原样传回即可;服务端接受 ``http`` / ``https`` URL 或列表返回的相对路径 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象(含摘要原文 ``snippet``、正文预览 ``content_preview``、相关股票 + ``relevant_stocks`` 与解析包规模信息),``raw=True`` 时返回完整 JSON + 信封。 +``` + +

parsed_industry_reports_download

+ +- 接口名称:解析后行业研报下载 +- HTTP:`GET` +- Path:`api/v3/market/data/industry-reports/download` +- 参数:`download_url` +- 来源文档:`解析后行业研报.md` +- 说明:返回 ``application/zip`` 二进制流,非 JSON 信封;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``;支持 ``ETag`` / ``304`` 条件下载。 + +```text +下载解析后行业研报 ZIP 解析包. + +Endpoint: ``api/v3/market/data/industry-reports/download``. +Method: ``GET``. + +Args: + download_url: 列表返回的解析包地址 (type: string; required: Y). + save_dir: 保存目录(默认为当前目录),目录不存在时自动创建;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``。 + +Returns: + 落盘后的文件路径;服务端返回 2xx 但正文为空时返回空字符串。 + +Raises: + FtshareHTTPError: If the server returns a non-2xx HTTP status. +``` +

periodic_reports

- 接口名称:定期报告列表 diff --git a/src/ftshare/apis/hk.py b/src/ftshare/apis/hk.py index 6c8516a..52599b5 100644 --- a/src/ftshare/apis/hk.py +++ b/src/ftshare/apis/hk.py @@ -31,6 +31,144 @@ def hk_candlesticks( params.update(kwargs) return self._call_endpoint('hk_candlesticks', raw=raw, fields=fields, as_dataframe=as_dataframe, **params) + def hk_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, + 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/hk-market-announcements``. + Method: ``GET``. + Documented endpoint: ``hk_market_announcements``. + + Args: + keyword: 标题关键词,只匹配简体标题,最多 60 字符 (type: string; required: N). + category: 港交所分类:5 位码、完整简体名或短别名,逗号多选,最多 20 个 (type: string; required: N). + stock_code: 港股主代码,支持裸码、``.HK``、``.XHKG``、``HK:`` 前缀 (type: string; required: N). + start_date: 公告日期起点 YYYYMMDD;只传 start_date 时为单日查询 (type: string; required: N). + end_date: 公告日期终点 YYYYMMDD;只给 end_date 返回 400 (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``。不带 + ``stock_code`` 时未传日期默认近 1 年、显式日期跨度最长 1 年;带 + ``stock_code`` 时不限跨度。 + """ + request_params = { + 'keyword': keyword, + 'category': category, + 'stock_code': stock_code, + 'start_date': start_date, + 'end_date': end_date, + } + request_params.update(kwargs) + return self.get_paginated( + ENDPOINTS['hk_market_announcements'].path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['hk_market_announcements'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + + def hk_periodic_announcements( + self, + keyword: Any | None = None, + report_type: Any | None = None, + stock_code: Any | None = None, + start_date: Any | None = None, + end_date: 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/hk-periodic-announcements``. + Method: ``GET``. + Documented endpoint: ``hk_periodic_announcements``. + + Args: + keyword: 标题关键词,只匹配简体标题,最多 60 字符 (type: string; required: N). + report_type: ``annual`` / ``semi_annual`` / ``quarterly``;不传为三类全部 (type: string; required: N). + stock_code: 港股主代码,支持裸码、``.HK``、``.XHKG``、``HK:`` 前缀 (type: string; required: N). + start_date: 公告日期起点 YYYYMMDD;只传 start_date 时为单日查询 (type: string; required: N). + end_date: 公告日期终点 YYYYMMDD;只给 end_date 返回 400 (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``。同一 + 公告涉及多个报告类型且未指定 ``report_type`` 时,按 + ``annual > semi_annual > quarterly`` 取第一个。 + """ + request_params = { + 'keyword': keyword, + 'report_type': report_type, + 'stock_code': stock_code, + 'start_date': start_date, + 'end_date': end_date, + } + request_params.update(kwargs) + return self.get_paginated( + ENDPOINTS['hk_periodic_announcements'].path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['hk_periodic_announcements'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + def stk_ah_comparison(self, hk_code: Any | None = None, ts_code: Any | None = None, trade_date: Any | None = None, start_date: Any | None = None, end_date: 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: """AH股对比.""" params = {'hk_code': hk_code, 'ts_code': ts_code, 'trade_date': trade_date, 'start_date': start_date, 'end_date': end_date} diff --git a/src/ftshare/apis/llm_corpus.py b/src/ftshare/apis/llm_corpus.py index 61dc4d0..eb6a4ec 100644 --- a/src/ftshare/apis/llm_corpus.py +++ b/src/ftshare/apis/llm_corpus.py @@ -5,10 +5,25 @@ import os from collections.abc import Sequence from typing import Any +from urllib.parse import unquote, urlencode, urlparse from ..endpoints import ENDPOINTS +def _report_download_path(endpoint_name: str, download_url: Any) -> str: + """Build the ZIP download route with its documented ``download_url`` query.""" + return f"{ENDPOINTS[endpoint_name].path}/download?{urlencode({'download_url': download_url})}" + + +def _report_zip_filename(download_url: Any) -> str: + """Derive ``{report_id}.zip`` from a documented analysis-package URL.""" + parts = [part for part in unquote(urlparse(str(download_url)).path).split("/") if part] + if len(parts) >= 3 and parts[-1].lower().endswith(".zip") and parts[-3]: + return f"{parts[-3]}.zip" + name = parts[-1] if parts else "" + return name if name.lower().endswith(".zip") else "report.zip" + + class LlmCorpusApiMixin: """Endpoint methods for the llm_corpus ftshare-doc topic.""" @@ -445,3 +460,267 @@ def stock_prospectuses( as_dataframe=as_dataframe, **request_params, ) + + def parsed_stock_reports( + self, + stock_code: Any | None = None, + start_date: Any | None = None, + end_date: Any | None = None, + report_type: Any | None = None, + download_url: 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/v3/market/data/stock-reports``. + Method: ``GET``. + Documented endpoint: ``stock_reports_v3``. + + Args: + stock_code: 股票代码,支持裸六码、``.SH`` / ``.SZ`` / ``.BJ`` 或 ``.XSHG`` / ``.XSHE`` / ``.BJSE`` 后缀 (type: string; required: N). + start_date: 披露日期闭区间起点 YYYYMMDD (type: string; required: Y). + end_date: 披露日期闭区间终点 YYYYMMDD,与 ``start_date`` 跨度不超过一年 (type: string; required: Y). + report_type: 研报类型,当前只支持 ``stock`` (type: string; required: N). + download_url: 解析包地址,精确匹配 (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``。日期 + 严格使用 ``YYYYMMDD``;``rating_raw``、``rating_action`` 保留上游 + 原文,缺失时为 ``null``。 + """ + request_params = { + 'stock_code': stock_code, + 'start_date': start_date, + 'end_date': end_date, + 'report_type': report_type, + 'download_url': download_url, + } + request_params.update(kwargs) + return self.get_paginated( + ENDPOINTS['parsed_stock_reports'].path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['parsed_stock_reports'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + + def parsed_stock_reports_preview( + self, + download_url: Any, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """解析后个股研报预览. + + Endpoint: ``api/v3/market/data/stock-reports/preview``. + Method: ``GET``. + Documented endpoint: ``stock_reports_preview``. + + Args: + download_url: 列表返回的解析包地址,原样传回即可;服务端接受 ``http`` / ``https`` URL 或列表返回的相对路径 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象(含摘要原文 ``snippet``、正文预览 ``content_preview``、解析包 + 大小 ``package_size_bytes`` 与素材数 ``asset_count``),``raw=True`` + 时返回完整 JSON 信封。 + """ + params = {'download_url': download_url} + params.update(kwargs) + return self.get( + ENDPOINTS['parsed_stock_reports_preview'].path, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + unwrap_bare_data=True, + **params, + ) + + def parsed_stock_reports_download( + self, + download_url: Any, + save_dir: str | os.PathLike[str] = ".", + ) -> str: + """下载解析后个股研报 ZIP 解析包. + + Endpoint: ``api/v3/market/data/stock-reports/download``. + Method: ``GET``. + + Args: + download_url: 列表返回的解析包地址 (type: string; required: Y). + save_dir: 保存目录(默认为当前目录),目录不存在时自动创建;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``。 + + Returns: + 落盘后的文件路径;服务端返回 2xx 但正文为空时返回空字符串。 + + Raises: + FtshareHTTPError: If the server returns a non-2xx HTTP status. + """ + return self.download( + _report_download_path('parsed_stock_reports', download_url), + save_dir=save_dir, + filename=_report_zip_filename(download_url), + ) + + def parsed_industry_reports( + self, + start_date: Any | None = None, + end_date: Any | None = None, + sw_l1_code: Any | None = None, + sw_l2_code: 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/v3/market/data/industry-reports``. + Method: ``GET``. + Documented endpoint: ``industry_reports``. + + Args: + start_date: 披露日期闭区间起点 YYYYMMDD (type: string; required: Y). + end_date: 披露日期闭区间终点 YYYYMMDD,与 ``start_date`` 跨度不超过一年 (type: string; required: Y). + sw_l1_code: 申万一级行业代码,六位数字;与 ``sw_l2_code`` 同时传入时按 AND 语义精确匹配 (type: string; required: N). + sw_l2_code: 申万二级行业代码,六位数字 (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``。行业 + 筛选只支持代码;``sw_l1_name``、``sw_l2_name`` 只出现在响应中。 + """ + request_params = { + 'start_date': start_date, + 'end_date': end_date, + 'sw_l1_code': sw_l1_code, + 'sw_l2_code': sw_l2_code, + } + request_params.update(kwargs) + return self.get_paginated( + ENDPOINTS['parsed_industry_reports'].path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['parsed_industry_reports'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + + def parsed_industry_reports_preview( + self, + download_url: Any, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """解析后行业研报预览. + + Endpoint: ``api/v3/market/data/industry-reports/preview``. + Method: ``GET``. + Documented endpoint: ``industry_reports_preview``. + + Args: + download_url: 列表返回的解析包地址,原样传回即可;服务端接受 ``http`` / ``https`` URL 或列表返回的相对路径 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象(含摘要原文 ``snippet``、正文预览 ``content_preview``、相关股票 + ``relevant_stocks`` 与解析包规模信息),``raw=True`` 时返回完整 JSON + 信封。 + """ + params = {'download_url': download_url} + params.update(kwargs) + return self.get( + ENDPOINTS['parsed_industry_reports_preview'].path, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + unwrap_bare_data=True, + **params, + ) + + def parsed_industry_reports_download( + self, + download_url: Any, + save_dir: str | os.PathLike[str] = ".", + ) -> str: + """下载解析后行业研报 ZIP 解析包. + + Endpoint: ``api/v3/market/data/industry-reports/download``. + Method: ``GET``. + + Args: + download_url: 列表返回的解析包地址 (type: string; required: Y). + save_dir: 保存目录(默认为当前目录),目录不存在时自动创建;文件名取自解析包地址中的研报标识,形如 ``{report_id}.zip``。 + + Returns: + 落盘后的文件路径;服务端返回 2xx 但正文为空时返回空字符串。 + + Raises: + FtshareHTTPError: If the server returns a non-2xx HTTP status. + """ + return self.download( + _report_download_path('parsed_industry_reports', download_url), + save_dir=save_dir, + filename=_report_zip_filename(download_url), + ) diff --git a/src/ftshare/apis/stock.py b/src/ftshare/apis/stock.py index cbae022..6aba8ba 100644 --- a/src/ftshare/apis/stock.py +++ b/src/ftshare/apis/stock.py @@ -5106,3 +5106,154 @@ def sector_knowledge_search_options( unwrap_bare_data=True, **params, ) + + def limit_ladder_daily( + self, + trade_date: Any | None = None, + stock_code: Any | None = None, + status: Any | None = None, + include_st: Any | None = None, + include_new: Any | None = None, + sort: 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/limit-ladder/daily``. + Method: ``GET``. + Documented endpoint: ``limit_ladder_daily``. + + Args: + trade_date: 交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 20240102、不得晚于当前日期 (type: string; required: Y). + stock_code: 股票代码,六位代码加 ``.SH`` / ``.SZ`` 后缀;可省略后缀 (type: string; required: N). + status: 状态筛选:``limit_up``(收盘封板)、``broken``(盘中触板但收盘炸板)、``normal``(未触板);不传返回三态全量 (type: string; required: N). + include_st: 是否包含 ST 股票,默认 ``true``;传 ``false`` 剔除 ``st=true`` 的记录 (type: boolean; required: N). + include_new: 是否包含新股,默认 ``true``;传 ``false`` 剔除 ``is_new=true`` 的记录 (type: boolean; required: N). + sort: 排序:``boards_desc``(默认,连板数降序)、``seal_amount_desc``(封板金额降序)、``stock_code_asc``(代码升序) (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``。仅已 + 发布汇总的交易日可查询;无已发布结果或非交易日返回 404。 + """ + request_params = { + 'trade_date': trade_date, + 'stock_code': stock_code, + 'status': status, + 'include_st': include_st, + 'include_new': include_new, + 'sort': sort, + } + request_params.update(kwargs) + return self.get_paginated( + ENDPOINTS['limit_ladder_daily'].path, + page=page, + page_size=page_size, + limit=limit, + all_pages=all_pages, + max_pages=max_pages, + max_page_size=ENDPOINTS['limit_ladder_daily'].max_page_size, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **request_params, + ) + + def limit_ladder_summary( + self, + start_date: Any | None = None, + end_date: Any | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """连板天梯汇总. + + Endpoint: ``api/v2/market/data/limit-ladder/summary``. + Method: ``GET``. + Documented endpoint: ``limit_ladder_summary``. + + Args: + start_date: 起始交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 20240102 (type: string; required: Y). + end_date: 结束交易日期 YYYYMMDD,兼容 ``YYYY-MM-DD``;不得早于 ``start_date``、不得晚于当前日期 (type: string; required: Y). + 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``。不分页,按 + 交易日升序返回区间内全部已发布汇总;未发布的日期不返回记录。 + """ + params = {'start_date': start_date, 'end_date': end_date} + params.update(kwargs) + return self._call_endpoint( + 'limit_ladder_summary', + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + **params, + ) + + def market_sentiment( + self, + trade_date: Any | None = None, + *, + raw: bool = False, + fields: Sequence[str] | str | None = None, + as_dataframe: bool = True, + **kwargs: Any, + ) -> Any: + """市场情绪. + + Endpoint: ``api/v2/market/data/market-sentiment``. + Method: ``GET``. + Documented endpoint: ``market_sentiment``. + + Args: + trade_date: 交易日期 YYYYMMDD,最早 20240102 (type: string; required: Y). + 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: + 默认返回单行 pandas ``DataFrame``;``as_dataframe=False`` 时返回 ``data`` + 对象,``raw=True`` 时返回完整 JSON 信封。非交易日、未来日期、早于 + 20240102 或当日数据尚未生成时,服务端返回 ``200`` 且 ``data`` 为 + ``None``;此时 SDK 不做解包,``as_dataframe=False`` 返回完整信封 + (``code`` / ``message`` / ``data``),默认 ``DataFrame`` 含 + ``code`` / ``message`` / ``data`` 三列。 + """ + params = {'trade_date': trade_date} + params.update(kwargs) + return self.get( + ENDPOINTS['market_sentiment'].path, + raw=raw, + fields=fields, + as_dataframe=as_dataframe, + unwrap_bare_data=True, + **params, + ) diff --git a/src/ftshare/endpoints/hk.py b/src/ftshare/endpoints/hk.py index d1c99ba..f85d86b 100644 --- a/src/ftshare/endpoints/hk.py +++ b/src/ftshare/endpoints/hk.py @@ -13,6 +13,22 @@ 'original_api': 'get_hk_candlesticks', 'params': ('trade_code', 'interval_unit', 'until_date', 'since_date', 'interval_value', 'limit', 'adjust_kind'), }, + 'hk_market_announcements': { + 'path': 'api/v2/market/data/announcements/hk-market-announcements', + 'title': '港股公告列表', + 'doc_file': '港股公告列表.md', + 'original_api': 'hk_market_announcements', + 'params': ('keyword', 'category', 'stock_code', 'start_date', 'end_date', 'page', 'page_size'), + 'max_page_size': 500, + }, + 'hk_periodic_announcements': { + 'path': 'api/v2/market/data/announcements/hk-periodic-announcements', + 'title': '港股定期公告列表', + 'doc_file': '港股定期公告列表.md', + 'original_api': 'hk_periodic_announcements', + 'params': ('keyword', 'report_type', 'stock_code', 'start_date', 'end_date', 'page', 'page_size'), + 'max_page_size': 500, + }, 'hsi_daily_weight': { 'path': 'api/v1/market/data/hk/hsi-daily-weight', 'title': '恒生指数每日权重', diff --git a/src/ftshare/endpoints/llm_corpus.py b/src/ftshare/endpoints/llm_corpus.py index 052d258..3e84996 100644 --- a/src/ftshare/endpoints/llm_corpus.py +++ b/src/ftshare/endpoints/llm_corpus.py @@ -14,6 +14,34 @@ 'params': ('keyword', 'category', 'stock_code', 'start_date', 'end_date', 'plate', 'column_type', 'page', 'page_size'), 'max_page_size': 500, }, + 'parsed_industry_reports': { + 'path': 'api/v3/market/data/industry-reports', + 'title': '解析后行业研报', + 'doc_file': '解析后行业研报.md', + 'original_api': 'industry_reports', + 'params': ('start_date', 'end_date', 'sw_l1_code', 'sw_l2_code', 'page', 'page_size'), + }, + 'parsed_industry_reports_preview': { + 'path': 'api/v3/market/data/industry-reports/preview', + 'title': '解析后行业研报预览', + 'doc_file': '解析后行业研报.md', + 'original_api': 'industry_reports_preview', + 'params': ('download_url',), + }, + 'parsed_stock_reports': { + 'path': 'api/v3/market/data/stock-reports', + 'title': '解析后个股研报', + 'doc_file': '解析后个股研报.md', + 'original_api': 'stock_reports_v3', + 'params': ('stock_code', 'start_date', 'end_date', 'report_type', 'download_url', 'page', 'page_size'), + }, + 'parsed_stock_reports_preview': { + 'path': 'api/v3/market/data/stock-reports/preview', + 'title': '解析后个股研报预览', + 'doc_file': '解析后个股研报.md', + 'original_api': 'stock_reports_preview', + 'params': ('download_url',), + }, 'periodic_reports': { 'path': 'api/v2/market/data/announcements/periodic-reports', 'title': '定期报告列表', diff --git a/src/ftshare/endpoints/stock.py b/src/ftshare/endpoints/stock.py index 15ad718..24f1a12 100644 --- a/src/ftshare/endpoints/stock.py +++ b/src/ftshare/endpoints/stock.py @@ -1030,4 +1030,28 @@ 'original_api': 'sector_knowledge_search_options', }, + 'limit_ladder_daily': { + 'path': 'api/v2/market/data/limit-ladder/daily', + 'title': '连板天梯明细', + 'doc_file': '连板天梯明细.md', + 'original_api': 'limit_ladder_daily', + 'params': ('trade_date', 'stock_code', 'status', 'include_st', 'include_new', 'sort', 'page', 'page_size'), + }, + + 'limit_ladder_summary': { + 'path': 'api/v2/market/data/limit-ladder/summary', + 'title': '连板天梯汇总', + 'doc_file': '连板天梯汇总.md', + 'original_api': 'limit_ladder_summary', + 'params': ('start_date', 'end_date'), + }, + + 'market_sentiment': { + 'path': 'api/v2/market/data/market-sentiment', + 'title': '市场情绪', + 'doc_file': '市场情绪.md', + 'original_api': 'market_sentiment', + 'params': ('trade_date',), + }, + }) diff --git a/tests/endpoint_cases.py b/tests/endpoint_cases.py index a8c255f..8cb0a96 100644 --- a/tests/endpoint_cases.py +++ b/tests/endpoint_cases.py @@ -46,6 +46,7 @@ "days": 5, "direction": "forward", "document_variant": "full", + "download_url": "https://example.invalid/stock-reports/report-1/r1/package.zip", "end": "20260717", "end_date": "20260717", "end_week": "202630", @@ -59,6 +60,8 @@ "fund_type": "股票型", "history": True, "hk_code": "00700.HK", + "include_new": True, + "include_st": True, "index_code": "000300", "index_slug": "HSI", "industry_code": "801010", @@ -85,6 +88,7 @@ "market_id": 1, "member_name": "永安期货", "member_name_abbr": "永安期货", + "mode": "cumulative", "name": "平安银行", "n": 5, "n_code": "000001.SZ", @@ -119,6 +123,7 @@ "since_date": "20260701", "since_ts_millis": 1784048400000, "since_ts_ms": 1784048400000, + "sort": "boards_desc", "span": "DAY1", "start": "20260701", "start_date": "20260701", @@ -127,10 +132,13 @@ "st_type": "*ST", "stat_date": "20260717", "stati_perd": "日", + "status": "limit_up", "stock_code": "000001.SZ", "stock_name": "平安银行", "stock": "600000.SH", "subindustry_name": "动力电池", + "sw_l1_code": "110000", + "sw_l2_code": "110700", "symbol": "600000.SH", "symbol_code": "110070.SH", "symbol_id": "600000", diff --git a/tests/test_client.py b/tests/test_client.py index d4461f0..05e3284 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,5 +1,7 @@ from __future__ import annotations +from urllib.parse import urlencode + import pytest import pandas as pd @@ -2249,3 +2251,219 @@ def test_futures_dominant_mapping_forwards_rule_version(): assert session.calls[0]["params"] == {"trade_date": "20261123", "rule_version": "v4"} assert rows == data + + +def test_limit_ladder_daily_forwards_filters_and_paginates(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.limit_ladder_daily( + trade_date="20261125", + stock_code="002579.SZ", + status="limit_up", + include_st=False, + include_new=False, + sort="seal_amount_desc", + page=1, + page_size=200, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/limit-ladder/daily" + assert session.calls[0]["params"] == { + "trade_date": "20261125", + "stock_code": "002579.SZ", + "status": "limit_up", + "include_st": "false", + "include_new": "false", + "sort": "seal_amount_desc", + "page": 1, + "page_size": 200, + } + + with pytest.raises(ValueError, match="page_size must be between 1 and 200"): + client.limit_ladder_daily(trade_date="20261125", page_size=201) + + +def test_limit_ladder_summary_returns_trade_date_rows_without_pagination(): + rows = [{"trade_date": 20261125, "limit_up_count": 58, "max_board": 5}] + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": rows})]) + client = FtshareClient(session=session) + + result = client.limit_ladder_summary(start_date="20261119", end_date="20261125", as_dataframe=False) + + assert result == rows + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/limit-ladder/summary" + assert session.calls[0]["params"] == {"start_date": "20261119", "end_date": "20261125"} + + +def test_market_sentiment_unwraps_data_object(): + sentiment = {"trade_date": "2026-12-03", "limit_up_count": 88, "max_boards": 6} + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": sentiment})]) + client = FtshareClient(session=session) + + result = client.market_sentiment(trade_date="20261203", as_dataframe=False) + + assert result == sentiment + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/market-sentiment" + assert session.calls[0]["params"] == {"trade_date": "20261203"} + + +def test_hk_market_announcements_forwards_filters_and_allows_page_size_500(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.hk_market_announcements( + keyword="报告", + category="年报", + stock_code="00700.HK", + start_date="20260101", + end_date="20261231", + page=1, + page_size=500, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/announcements/hk-market-announcements" + assert session.calls[0]["params"] == { + "keyword": "报告", + "category": "年报", + "stock_code": "00700.HK", + "start_date": "20260101", + "end_date": "20261231", + "page": 1, + "page_size": 500, + } + + with pytest.raises(ValueError, match="page_size must be between 1 and 500"): + client.hk_market_announcements(page_size=501) + + +def test_hk_periodic_announcements_forwards_report_type(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.hk_periodic_announcements( + stock_code="00700.HK", + report_type="semi_annual", + page=1, + page_size=5, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v2/market/data/announcements/hk-periodic-announcements" + assert session.calls[0]["params"] == { + "stock_code": "00700.HK", + "report_type": "semi_annual", + "page": 1, + "page_size": 5, + } + + +def test_parsed_stock_reports_forwards_filters_and_paginates(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.parsed_stock_reports( + stock_code="000661.SZ", + start_date="20261101", + end_date="20261203", + report_type="stock", + page=1, + page_size=200, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v3/market/data/stock-reports" + assert session.calls[0]["params"] == { + "stock_code": "000661.SZ", + "start_date": "20261101", + "end_date": "20261203", + "report_type": "stock", + "page": 1, + "page_size": 200, + } + + with pytest.raises(ValueError, match="page_size must be between 1 and 200"): + client.parsed_stock_reports(start_date="20261101", end_date="20261203", page_size=201) + + +def test_parsed_stock_reports_preview_unwraps_data_object(): + preview = {"report_id": "report-1", "content_preview": "# 标题", "asset_count": 46} + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": preview})]) + client = FtshareClient(session=session) + + result = client.parsed_stock_reports_preview("https://example.invalid/stock-reports/report-1/r1/package.zip", as_dataframe=False) + + assert result == preview + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v3/market/data/stock-reports/preview" + assert session.calls[0]["params"] == {"download_url": "https://example.invalid/stock-reports/report-1/r1/package.zip"} + + +def test_parsed_stock_reports_download_requests_zip_and_derives_report_id(tmp_path): + archive = b"PK\x03\x04fake report package" + session = FakeSession([FakeResponse(payload={}, content=archive)]) + client = FtshareClient(session=session) + download_url = "http://files.invalid/ftshare-stock-reports/stock-reports/0c0e4fcd-7a1f/r2/abc.zip" + + saved = client.parsed_stock_reports_download(download_url, save_dir=tmp_path) + + expected = tmp_path / "0c0e4fcd-7a1f.zip" + assert saved == str(expected) + assert expected.read_bytes() == archive + assert session.calls[0]["url"] == ( + "https://market.ft.tech/gateway/api/v3/market/data/stock-reports/download?" + + urlencode({"download_url": download_url}) + ) + assert session.calls[0]["params"] is None + + +def test_parsed_industry_reports_forwards_sw_codes(): + session = FakeSession([FakeResponse(payload=paginated_records([]))]) + client = FtshareClient(session=session) + + client.parsed_industry_reports( + start_date="20261101", + end_date="20261203", + sw_l1_code="110000", + sw_l2_code="110700", + page=1, + page_size=5, + as_dataframe=False, + ) + + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v3/market/data/industry-reports" + assert session.calls[0]["params"] == { + "start_date": "20261101", + "end_date": "20261203", + "sw_l1_code": "110000", + "sw_l2_code": "110700", + "page": 1, + "page_size": 5, + } + + +def test_parsed_industry_reports_preview_unwraps_relevant_stocks(): + preview = {"report_id": "report-2", "relevant_stocks": {"000876": {"stock_name": "新希望"}}} + session = FakeSession([FakeResponse(payload={"code": 200, "message": "success", "data": preview})]) + client = FtshareClient(session=session) + + result = client.parsed_industry_reports_preview("http://files.invalid/industry-reports/report-2/r1/pkg.zip", as_dataframe=False) + + assert result == preview + assert session.calls[0]["url"] == "https://market.ft.tech/gateway/api/v3/market/data/industry-reports/preview" + assert session.calls[0]["params"] == {"download_url": "http://files.invalid/industry-reports/report-2/r1/pkg.zip"} + + +def test_parsed_industry_reports_download_falls_back_to_url_filename(tmp_path): + archive = b"PK\x03\x04industry report" + session = FakeSession([FakeResponse(payload={}, content=archive)]) + client = FtshareClient(session=session) + + saved = client.parsed_industry_reports_download("http://files.invalid/packages/report.zip", save_dir=tmp_path) + + assert saved == str(tmp_path / "report.zip") + assert (tmp_path / "report.zip").read_bytes() == archive + assert session.calls[0]["url"].startswith( + "https://market.ft.tech/gateway/api/v3/market/data/industry-reports/download?" + ) From cd0be0c476ff4a1b713b0c52844c6c12e67659cc Mon Sep 17 00:00:00 2001 From: zhuhao Date: Fri, 4 Dec 2026 13:31:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore=EF=BC=9A=E7=89=88=E6=9C=AC=E5=8D=87?= =?UTF-8?q?=E8=87=B3=201.0.15?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Code --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ccb3965..71f768d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "ftshare" -version = "1.0.14" +version = "1.0.15" description = "Python SDK for FTShare market data APIs." readme = "README.md" requires-python = ">=3.9"