Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions docs/API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

| 指标 | 数量 |
|---|---:|
| SDK 方法总数 | 179 |
| SDK 方法总数 | 180 |

## 专题分布

接口分组、`src/ftshare/apis/` 方法模块和 `src/ftshare/endpoints/` 注册表模块均按 `ftshare-doc/api-doc` 顶层专题对齐。

| ftshare-doc 专题 | SDK 方法数 | API mixin 模块 | Endpoint 模块 |
|---|---:|---|---|
| 股票数据 | 95 | `ftshare.apis.stock` | `ftshare.endpoints.stock` |
| 股票数据 | 96 | `ftshare.apis.stock` | `ftshare.endpoints.stock` |
| 港股数据 | 14 | `ftshare.apis.hk` | `ftshare.endpoints.hk` |
| 美股数据 | 9 | `ftshare.apis.us` | `ftshare.endpoints.us` |
| 指数专题 | 8 | `ftshare.apis.index` | `ftshare.endpoints.index` |
Expand Down Expand Up @@ -126,7 +126,8 @@ df = market.baidu_financial_calendar(
| [`stock_pledge_detail`](#api-stock-pledge-detail) | 股权质押明细 | `GET` | `api/v1/market/data/pledge/pledge-detail` | `stock_code`, `is_last`, `page`, `page_size` | `股权质押明细.md` |
| [`stock_pledge_summary`](#api-stock-pledge-summary) | 股权质押汇总 | `GET` | `api/v1/market/data/pledge/pledge-summary` | `page`, `page_size` | `股权质押汇总.md` |
| [`stock_prev_close`](#api-stock-prev-close) | 标的昨收价 | `GET` | `api/v1/market/data/daec/history/prev-closes` | `symbol`, `since`, `until` | `标的昨收价.md` |
| [`stock_intraday_prices`](#api-stock-intraday-prices) | 标的分时数据 | `GET` | `api/v1/market/data/daec/history/prices` | `symbol`, `range`, `days`, `ts_ms` | `标得分时数据.md` |
| [`stock_intraday_prices`](#api-stock-intraday-prices) | 标的分时数据 | `GET` | `api/v1/market/data/daec/history/prices` | `symbol`, `range`, `days`, `ts_ms`, `compat`, `since`, `since_ts_ms` | `标得分时数据.md` |
| [`stock_ohlcs`](#api-stock-ohlcs) | 标的K线数据 | `GET` | `api/v1/market/data/daec/history/ohlcs` | `symbol`, `since`, `until`, `interval`, `adjust`, `compat`, `span`, `limit`, `until_ts_ms` | `标的K线数据.md` |
| [`stock_rating_top5`](#api-stock-rating-top5) | 飞兔股票评级Top5 | `GET` | `api/v1/market/data/feitu/stock-rating-top5` | `date`, `variant`, `type` | `飞兔股票评级Top5.md` |
| [`stock_share`](#api-stock-share) | 股本 | `GET` | `api/v1/market/data/share/get-stock-share` | `stock_code`, `date` | `股本.md` |
| [`stock_share_chg`](#api-stock-share-chg) | 股东增减持 | `GET` | `api/v1/market/data/holder/stock-share-chg` | `stock_code`, `is_last`, `page`, `page_size` | `股东增减持.md` |
Expand Down Expand Up @@ -185,7 +186,7 @@ df = market.baidu_financial_calendar(
| [`index_description_all`](#api-index-description-all) | 指数基础信息 | `GET` | `api/v1/market/data/index-description-all` | - | `指数基础信息.md` |
| [`index_description_list`](#api-index-description-list) | 中证指数描述列表 | `GET` | `api/v1/market/data/index/index_description` | `page`, `page_size` | `中证指数描述列表.md` |
| [`index_weight_list`](#api-index-weight-list) | 指数权重列表 | `GET` | `api/v1/market/data/index/index_weight` | `index_code`, `date`, `page`, `page_size` | `指数权重列表.md` |
| [`index_weight_summary`](#api-index-weight-summary) | 指数权重汇总 | `GET` | `api/v1/market/data/index/index_weight_summary` | `page`, `page_size` | `指数权重汇总.md` |
| [`index_weight_summary`](#api-index-weight-summary) | 指数权重汇总 | `GET` | `api/v1/market/data/index/index_weight_summary` | `index_code`, `page`, `page_size` | `指数权重汇总.md` |
| [`sw_industry_constituent_history`](#api-sw-industry-constituent-history) | 申万行业成份股历史 | `GET` | `api/v1/market/data/sw-industry/constituent-history` | `industry_code` | `申万行业成份股历史.md` |
| [`sw_industry_daily_metrics`](#api-sw-industry-daily-metrics) | 申万行业日度指标 | `GET` | `api/v1/market/data/sw-industry/daily-metrics` | `level`, `start_date`, `end_date`, `industry_code`, `page`, `page_size` | `申万行业日度指标.md` |
| [`sw_industry_overview`](#api-sw-industry-overview) | 申万行业总览 | `GET` | `api/v1/market/data/sw-industry/overview` | `date`, `level`, `page`, `page_size` | `申万行业总览.md` |
Expand Down Expand Up @@ -1983,7 +1984,7 @@ Returns:
- 接口名称:千股千评
- HTTP:`GET`
- Path:`api/v1/market/data/stock-comment/index`
- 参数:`page`, `page_size`
- 参数:`index_code`, `page`, `page_size`
- 来源文档:`千股千评.md`
- 原始接口:`stock_comment_em`

Expand All @@ -1995,6 +1996,7 @@ Method: ``GET``.
Documented endpoint: ``stock_comment_em``.

Args:
index_code: 指数代码,如 `000300` (type: string; required: Y).
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.
Expand Down Expand Up @@ -2844,7 +2846,7 @@ Returns:
- 接口名称:标的分时数据
- HTTP:`GET`
- Path:`api/v1/market/data/daec/history/prices`
- 参数:`symbol`, `range`, `days`, `ts_ms`
- 参数:`symbol`, `range`, `days`, `ts_ms`, `compat`, `since`, `since_ts_ms`
- 来源文档:`标得分时数据.md`
- 原始接口:`stock_intraday_prices`

Expand All @@ -2860,6 +2862,9 @@ Args:
range: 预置时间区间:Today / FiveDays (type: string; required: N).
days: 近 N 个交易日至今 (type: uint32; required: N).
ts_ms: 起始毫秒时间戳 (type: int64; required: N).
compat: 兼容模式。传 v2 时启用旧 v2 响应结构 (type: string; required: N).
since: v2 兼容模式参数。可选 TODAY / FIVE_DAYS_AGO / TRADE_DAYS_AGO(n) (type: string; required: N).
since_ts_ms: v2 兼容模式参数。按起始毫秒时间戳取数,优先级高于 since (type: int64; 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.
Expand All @@ -2869,6 +2874,49 @@ 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``.

Raises:
ValueError: If original-mode and ``compat='v2'`` time controls are mixed.
```

<h4 id="api-stock-ohlcs"><code>stock_ohlcs</code></h4>

- 接口名称:标的K线数据
- HTTP:`GET`
- Path:`api/v1/market/data/daec/history/ohlcs`
- 参数:`symbol`, `since`, `until`, `interval`, `adjust`, `compat`, `span`, `limit`, `until_ts_ms`
- 来源文档:`标的K线数据.md`
- 原始接口:`stock_ohlcs`

```text
标的K线数据.

Endpoint: ``api/v1/market/data/daec/history/ohlcs``.
Method: ``GET``.
Documented endpoint: ``stock_ohlcs``.

Args:
symbol: 标的代码,如 600000.XSHG (type: string; required: Y).
since: 起始日期,格式 YYYYMMDD;v2 兼容模式不传时会根据 limit 估算回溯窗口 (type: string; required: 原始模式 Y / v2 兼容模式 N).
until: 结束日期,格式 YYYYMMDD;v2 兼容模式不传时默认当天 (type: string; required: 原始模式 Y / v2 兼容模式 N).
interval: 原始模式参数。周期:Minute / Day / Week / Month,默认 Day (type: string; required: N).
adjust: 复权方式:None / Forward / Backward;v2 兼容模式默认 Forward (type: string; required: N).
compat: 兼容模式。传 v2 时启用旧 v2 响应结构 (type: string; required: N).
span: v2 兼容模式参数。周期:DAY1 / WEEK1 / MONTH1;不支持 YEAR1 (type: string; required: N).
limit: v2 兼容模式参数。返回最近 N 根 K 线 (type: int; required: N).
until_ts_ms: v2 兼容模式参数。旧 v2 风格结束毫秒时间戳,会按北京时间转换为 until 日期 (type: int64; 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``, raw JSON when ``raw=True``, or raw page
payloads when multi-page fetching is used with ``raw=True``.

Raises:
ValueError: If original-mode and ``compat='v2'`` controls are mixed.
```

<h4 id="api-stock-rating-top5"><code>stock_rating_top5</code></h4>
Expand Down
4 changes: 3 additions & 1 deletion src/ftshare/apis/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def index_weight_list(

def index_weight_summary(
self,
index_code: Any | None = None,
page: int | None = None,
page_size: int | None = None,
limit: int | None = None,
Expand All @@ -180,6 +181,7 @@ def index_weight_summary(
Documented endpoint: ``index_weight_summary_handler``.

Args:
index_code: 指数代码,如 `000300` (type: string; required: Y).
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.
Expand All @@ -195,7 +197,7 @@ def index_weight_summary(
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
payloads when multi-page fetching is used with ``raw=True``.
"""
request_params = {}
request_params = {'index_code': index_code}
request_params.update(kwargs)
path = ENDPOINTS['index_weight_summary'].path
return self.get_paginated(
Expand Down
124 changes: 123 additions & 1 deletion src/ftshare/apis/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from ..endpoints import ENDPOINTS


def _present_params(params: dict[str, Any]) -> list[str]:
return [name for name, value in params.items() if value is not None]


class StockApiMixin:
"""Endpoint methods for the stock ftshare-doc topic."""

Expand Down Expand Up @@ -4238,6 +4242,9 @@ def stock_intraday_prices(
range: Any | None = None,
days: Any | None = None,
ts_ms: Any | None = None,
compat: Any | None = None,
since: Any | None = None,
since_ts_ms: Any | None = None,
*,
raw: bool = False,
fields: Sequence[str] | str | None = None,
Expand All @@ -4255,6 +4262,9 @@ def stock_intraday_prices(
range: 预置时间区间:Today / FiveDays (type: string; required: N).
days: 近 N 个交易日至今 (type: uint32; required: N).
ts_ms: 起始毫秒时间戳 (type: int64; required: N).
compat: 兼容模式。传 v2 时启用旧 v2 响应结构 (type: string; required: N).
since: v2 兼容模式参数。可选 TODAY / FIVE_DAYS_AGO / TRADE_DAYS_AGO(n) (type: string; required: N).
since_ts_ms: v2 兼容模式参数。按起始毫秒时间戳取数,优先级高于 since (type: int64; 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.
Expand All @@ -4264,8 +4274,45 @@ def stock_intraday_prices(
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``.

Raises:
ValueError: If original-mode and ``compat='v2'`` time controls are mixed.
"""
request_params = {'symbol': symbol, 'range': range, 'days': days, 'ts_ms': ts_ms}
if compat is not None and compat != 'v2':
raise ValueError("compat must be 'v2' when provided")
raw_time_params = _present_params({'range': range, 'days': days, 'ts_ms': ts_ms})
v2_time_params = _present_params({'since': since, 'since_ts_ms': since_ts_ms})
if compat == 'v2':
if raw_time_params:
raise ValueError(
"stock_intraday_prices compat='v2' cannot be combined with raw time parameters: "
+ ', '.join(raw_time_params)
)
if len(v2_time_params) > 1:
raise ValueError(
"stock_intraday_prices v2 time parameters are mutually exclusive: "
+ ', '.join(v2_time_params)
)
elif v2_time_params:
raise ValueError(
"stock_intraday_prices v2 time parameters require compat='v2': "
+ ', '.join(v2_time_params)
)
elif len(raw_time_params) > 1:
raise ValueError(
"stock_intraday_prices raw time parameters are mutually exclusive: "
+ ', '.join(raw_time_params)
)

request_params = {
'symbol': symbol,
'range': range,
'days': days,
'ts_ms': ts_ms,
'compat': compat,
'since': since,
'since_ts_ms': since_ts_ms,
}
request_params.update(kwargs)
return self._call_endpoint(
'stock_intraday_prices',
Expand All @@ -4275,6 +4322,81 @@ def stock_intraday_prices(
**request_params,
)

def stock_ohlcs(
self,
symbol: Any | None = None,
since: Any | None = None,
until: Any | None = None,
interval: Any | None = None,
adjust: Any | None = None,
compat: Any | None = None,
span: Any | None = None,
limit: Any | None = None,
until_ts_ms: Any | None = None,
*,
raw: bool = False,
fields: Sequence[str] | str | None = None,
as_dataframe: bool = True,
**kwargs: Any,
) -> Any:
"""标的K线数据.

Endpoint: ``api/v1/market/data/daec/history/ohlcs``.
Method: ``GET``.
Documented endpoint: ``stock_ohlcs``.

Args:
symbol: 标的代码,如 600000.XSHG (type: string; required: Y).
since: 起始日期,格式 YYYYMMDD;v2 兼容模式不传时会根据 limit 估算回溯窗口 (type: string; required: 原始模式 Y / v2 兼容模式 N).
until: 结束日期,格式 YYYYMMDD;v2 兼容模式不传时默认当天 (type: string; required: 原始模式 Y / v2 兼容模式 N).
interval: 原始模式参数。周期:Minute / Day / Week / Month,默认 Day (type: string; required: N).
adjust: 复权方式:None / Forward / Backward;v2 兼容模式默认 Forward (type: string; required: N).
compat: 兼容模式。传 v2 时启用旧 v2 响应结构 (type: string; required: N).
span: v2 兼容模式参数。周期:DAY1 / WEEK1 / MONTH1;不支持 YEAR1 (type: string; required: N).
limit: v2 兼容模式参数。返回最近 N 根 K 线 (type: int; required: N).
until_ts_ms: v2 兼容模式参数。旧 v2 风格结束毫秒时间戳,会按北京时间转换为 until 日期 (type: int64; 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``, raw JSON when ``raw=True``, or raw page
payloads when multi-page fetching is used with ``raw=True``.

Raises:
ValueError: If original-mode and ``compat='v2'`` controls are mixed.
"""
if compat is not None and compat != 'v2':
raise ValueError("compat must be 'v2' when provided")
v2_params = _present_params({'span': span, 'limit': limit, 'until_ts_ms': until_ts_ms})
if compat == 'v2':
if interval is not None:
raise ValueError("stock_ohlcs compat='v2' uses span instead of interval")
elif v2_params:
raise ValueError("stock_ohlcs v2 parameters require compat='v2': " + ', '.join(v2_params))

request_params = {
'symbol': symbol,
'since': since,
'until': until,
'interval': interval,
'adjust': adjust,
'compat': compat,
'span': span,
'limit': limit,
'until_ts_ms': until_ts_ms,
}
request_params.update(kwargs)
return self._call_endpoint(
'stock_ohlcs',
raw=raw,
fields=fields,
as_dataframe=as_dataframe,
**request_params,
)

def stock_rating_top5(
self,
date: Any | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ftshare/endpoints/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'title': '指数权重汇总',
'doc_file': '指数权重汇总.md',
'original_api': 'index_weight_summary_handler',
'params': ('page', 'page_size'),
'params': ('index_code', 'page', 'page_size'),
'max_page_size': 100,
},
'sw_industry_constituent_history': {
Expand Down
9 changes: 8 additions & 1 deletion src/ftshare/endpoints/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,14 @@
'title': '标的分时数据',
'doc_file': '标得分时数据.md',
'original_api': 'stock_intraday_prices',
'params': ('symbol', 'range', 'days', 'ts_ms'),
'params': ('symbol', 'range', 'days', 'ts_ms', 'compat', 'since', 'since_ts_ms'),
},
'stock_ohlcs': {
'path': 'api/v1/market/data/daec/history/ohlcs',
'title': '标的K线数据',
'doc_file': '标的K线数据.md',
'original_api': 'stock_ohlcs',
'params': ('symbol', 'since', 'until', 'interval', 'adjust', 'compat', 'span', 'limit', 'until_ts_ms'),
},
'stock_rating_top5': {
'path': 'api/v1/market/data/feitu/stock-rating-top5',
Expand Down
Loading
Loading