Skip to content

Commit 506d8a7

Browse files
authored
Merge pull request #7 from FTShare-Lab/howe_dev
Howe dev
2 parents b9828d8 + d7be107 commit 506d8a7

11 files changed

Lines changed: 1131 additions & 65 deletions

File tree

‎docs/API_REFERENCE.md‎

Lines changed: 411 additions & 26 deletions
Large diffs are not rendered by default.

‎src/ftshare/apis/futures.py‎

Lines changed: 274 additions & 26 deletions
Large diffs are not rendered by default.

‎src/ftshare/apis/hk.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,74 @@ def hk_valuatnanalyd(
651651
**request_params,
652652
)
653653

654+
def hsi_daily_weight(
655+
self,
656+
trade_date: Any | None = None,
657+
start_date: Any | None = None,
658+
end_date: Any | None = None,
659+
index_slug: Any | None = None,
660+
stock_code: Any | None = None,
661+
page: int | None = None,
662+
page_size: int | None = None,
663+
limit: int | None = None,
664+
all_pages: bool = False,
665+
max_pages: int | None = None,
666+
*,
667+
raw: bool = False,
668+
fields: Sequence[str] | str | None = None,
669+
as_dataframe: bool = True,
670+
**kwargs: Any,
671+
) -> Any:
672+
"""恒生指数每日权重.
673+
674+
Endpoint: ``api/v1/market/data/hk/hsi-daily-weight``.
675+
Method: ``GET``.
676+
Documented endpoint: ``hsi_daily_weight``.
677+
678+
Args:
679+
trade_date: 交易日期 (type: string; required: N).
680+
start_date: 起始日期 (type: string; required: N).
681+
end_date: 结束日期 (type: string; required: N).
682+
index_slug: 指数代码 (type: string; required: N).
683+
stock_code: 成份股代码 (type: string; required: N).
684+
page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set.
685+
page_size: Rows per page. The SDK validates this against the endpoint-specific maximum.
686+
limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit.
687+
all_pages: Fetch and combine pages until the server reports the last page.
688+
max_pages: Optional safety cap for ``all_pages``.
689+
raw: Return the decoded JSON payload without tabular extraction.
690+
fields: Optional field list or comma-separated field string applied after extraction.
691+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
692+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
693+
694+
Returns:
695+
A pandas ``DataFrame`` by default, Python rows when
696+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
697+
payloads when multi-page fetching is used with ``raw=True``.
698+
"""
699+
request_params = {
700+
'trade_date': trade_date,
701+
'start_date': start_date,
702+
'end_date': end_date,
703+
'index_slug': index_slug,
704+
'stock_code': stock_code,
705+
}
706+
request_params.update(kwargs)
707+
path = ENDPOINTS['hsi_daily_weight'].path
708+
return self.get_paginated(
709+
path,
710+
page=page,
711+
page_size=page_size,
712+
limit=limit,
713+
all_pages=all_pages,
714+
max_pages=max_pages,
715+
raw=raw,
716+
fields=fields,
717+
as_dataframe=as_dataframe,
718+
max_page_size=ENDPOINTS['hsi_daily_weight'].max_page_size,
719+
**request_params,
720+
)
721+
654722
def market_cap_hk(
655723
self,
656724
trade_code: Any | None = None,

‎src/ftshare/apis/stock.py‎

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,69 @@ def cashflow(
131131
**request_params,
132132
)
133133

134+
def daec_ohlcs(
135+
self,
136+
symbol: Any | None = None,
137+
since: Any | None = None,
138+
until: Any | None = None,
139+
interval: Any | None = None,
140+
adjust: Any | None = None,
141+
compat: Any | None = None,
142+
span: Any | None = None,
143+
limit: Any | None = None,
144+
until_ts_ms: Any | None = None,
145+
*,
146+
raw: bool = False,
147+
fields: Sequence[str] | str | None = None,
148+
as_dataframe: bool = True,
149+
**kwargs: Any,
150+
) -> Any:
151+
"""DAEC历史OHLC.
152+
153+
Endpoint: ``api/v1/market/data/daec/history/ohlcs``.
154+
Method: ``GET``.
155+
Documented endpoint: ``daec_ohlcs``.
156+
157+
Args:
158+
symbol: 标的代码 (type: string; required: Y).
159+
since: 起始时间 (type: string; required: N).
160+
until: 截止时间 (type: string; required: N).
161+
interval: K 线周期 (type: string; required: N).
162+
adjust: 复权类型 (type: string; required: N).
163+
compat: 兼容模式 (type: string; required: N).
164+
span: 时间跨度 (type: string; required: N).
165+
limit: 返回条数 (type: int; required: N).
166+
until_ts_ms: 截止时间戳(毫秒) (type: int; required: N).
167+
raw: Return the decoded JSON payload without tabular extraction.
168+
fields: Optional field list or comma-separated field string applied after extraction.
169+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
170+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
171+
172+
Returns:
173+
A pandas ``DataFrame`` by default, Python rows when
174+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
175+
payloads when multi-page fetching is used with ``raw=True``.
176+
"""
177+
request_params = {
178+
'symbol': symbol,
179+
'since': since,
180+
'until': until,
181+
'interval': interval,
182+
'adjust': adjust,
183+
'compat': compat,
184+
'span': span,
185+
'limit': limit,
186+
'until_ts_ms': until_ts_ms,
187+
}
188+
request_params.update(kwargs)
189+
return self._call_endpoint(
190+
'daec_ohlcs',
191+
raw=raw,
192+
fields=fields,
193+
as_dataframe=as_dataframe,
194+
**request_params,
195+
)
196+
134197
def cashflow_stock_code(
135198
self,
136199
*,
@@ -1334,6 +1397,62 @@ def eastmoney_board_daily_kline(
13341397
**request_params,
13351398
)
13361399

1400+
def eastmoney_all_board_daily_kline(
1401+
self,
1402+
start_date: Any | None = None,
1403+
end_date: Any | None = None,
1404+
page: int | None = None,
1405+
page_size: int | None = None,
1406+
limit: int | None = None,
1407+
all_pages: bool = False,
1408+
max_pages: int | None = None,
1409+
*,
1410+
raw: bool = False,
1411+
fields: Sequence[str] | str | None = None,
1412+
as_dataframe: bool = True,
1413+
**kwargs: Any,
1414+
) -> Any:
1415+
"""东方财富全板块日线OHLC.
1416+
1417+
Endpoint: ``api/v1/market/data/eastmoney-all-board-daily-ohlc``.
1418+
Method: ``GET``.
1419+
Documented endpoint: ``eastmoney_all_board_daily_kline``.
1420+
1421+
Args:
1422+
start_date: 起始日期(含),YYYY-MM-DD 或 YYYYMMDD (type: string; required: N).
1423+
end_date: 截止日期(含),YYYY-MM-DD 或 YYYYMMDD (type: string; required: N).
1424+
page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set.
1425+
page_size: Rows per page. The SDK validates this against the endpoint-specific maximum.
1426+
limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit.
1427+
all_pages: Fetch and combine pages until the server reports the last page.
1428+
max_pages: Optional safety cap for ``all_pages``.
1429+
raw: Return the decoded JSON payload without tabular extraction.
1430+
fields: Optional field list or comma-separated field string applied after extraction.
1431+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
1432+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
1433+
1434+
Returns:
1435+
A pandas ``DataFrame`` by default, Python rows when
1436+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
1437+
payloads when multi-page fetching is used with ``raw=True``.
1438+
"""
1439+
request_params = {'start_date': start_date, 'end_date': end_date}
1440+
request_params.update(kwargs)
1441+
path = ENDPOINTS['eastmoney_all_board_daily_kline'].path
1442+
return self.get_paginated(
1443+
path,
1444+
page=page,
1445+
page_size=page_size,
1446+
limit=limit,
1447+
all_pages=all_pages,
1448+
max_pages=max_pages,
1449+
max_page_size=ENDPOINTS['eastmoney_all_board_daily_kline'].max_page_size,
1450+
raw=raw,
1451+
fields=fields,
1452+
as_dataframe=as_dataframe,
1453+
**request_params,
1454+
)
1455+
13371456
def eastmoney_board_latest_kline(
13381457
self,
13391458
board_code: Any | None = None,
@@ -1943,6 +2062,47 @@ def nth_trade_date(
19432062
**request_params,
19442063
)
19452064

2065+
def trading_calendar(
2066+
self,
2067+
market: Any | None = None,
2068+
start_date: Any | None = None,
2069+
end_date: Any | None = None,
2070+
*,
2071+
raw: bool = False,
2072+
fields: Sequence[str] | str | None = None,
2073+
as_dataframe: bool = True,
2074+
**kwargs: Any,
2075+
) -> Any:
2076+
"""交易日历.
2077+
2078+
Endpoint: ``api/v1/market/data/time/trading-calendar``.
2079+
Method: ``GET``.
2080+
Documented endpoint: ``trading_calendar``.
2081+
2082+
Args:
2083+
market: 市场标识 (type: string; required: N).
2084+
start_date: 起始日期 (type: string; required: N).
2085+
end_date: 截止日期 (type: string; required: N).
2086+
raw: Return the decoded JSON payload without tabular extraction.
2087+
fields: Optional field list or comma-separated field string applied after extraction.
2088+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
2089+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
2090+
2091+
Returns:
2092+
A pandas ``DataFrame`` by default, Python rows when
2093+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
2094+
payloads when multi-page fetching is used with ``raw=True``.
2095+
"""
2096+
request_params = {'market': market, 'start_date': start_date, 'end_date': end_date}
2097+
request_params.update(kwargs)
2098+
return self._call_endpoint(
2099+
'trading_calendar',
2100+
raw=raw,
2101+
fields=fields,
2102+
as_dataframe=as_dataframe,
2103+
**request_params,
2104+
)
2105+
19462106
def price_change(
19472107
self,
19482108
stock_code: Any | None = None,
@@ -3076,6 +3236,99 @@ def risk_warning_stocks(
30763236
**request_params,
30773237
)
30783238

3239+
def report_announcement_list(
3240+
self,
3241+
date: Any | None = None,
3242+
sec_code: Any | None = None,
3243+
page: int | None = None,
3244+
page_size: int | None = None,
3245+
limit: int | None = None,
3246+
all_pages: bool = False,
3247+
max_pages: int | None = None,
3248+
*,
3249+
raw: bool = False,
3250+
fields: Sequence[str] | str | None = None,
3251+
as_dataframe: bool = True,
3252+
**kwargs: Any,
3253+
) -> Any:
3254+
"""报告公告列表.
3255+
3256+
Endpoint: ``api/v1/market/data/report-announcements/list``.
3257+
Method: ``GET``.
3258+
Documented endpoint: ``report_announcement_list``.
3259+
3260+
Args:
3261+
date: 公告日期 (type: string; required: N).
3262+
sec_code: 证券代码 (type: string; required: N).
3263+
page: Page number, starting from 1. If omitted, the server default is used unless ``limit`` or ``all_pages`` is set.
3264+
page_size: Rows per page. The SDK validates this against the endpoint-specific maximum.
3265+
limit: Maximum number of rows to return. The SDK may fetch multiple pages to satisfy this limit.
3266+
all_pages: Fetch and combine pages until the server reports the last page.
3267+
max_pages: Optional safety cap for ``all_pages``.
3268+
raw: Return the decoded JSON payload without tabular extraction.
3269+
fields: Optional field list or comma-separated field string applied after extraction.
3270+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
3271+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
3272+
3273+
Returns:
3274+
A pandas ``DataFrame`` by default, Python rows when
3275+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
3276+
payloads when multi-page fetching is used with ``raw=True``.
3277+
"""
3278+
request_params = {'date': date, 'sec_code': sec_code}
3279+
request_params.update(kwargs)
3280+
path = ENDPOINTS['report_announcement_list'].path
3281+
return self.get_paginated(
3282+
path,
3283+
page=page,
3284+
page_size=page_size,
3285+
limit=limit,
3286+
all_pages=all_pages,
3287+
max_pages=max_pages,
3288+
max_page_size=ENDPOINTS['report_announcement_list'].max_page_size,
3289+
raw=raw,
3290+
fields=fields,
3291+
as_dataframe=as_dataframe,
3292+
**request_params,
3293+
)
3294+
3295+
def report_announcement_summary(
3296+
self,
3297+
announcement_id: Any | None = None,
3298+
*,
3299+
raw: bool = False,
3300+
fields: Sequence[str] | str | None = None,
3301+
as_dataframe: bool = True,
3302+
**kwargs: Any,
3303+
) -> Any:
3304+
"""报告公告摘要.
3305+
3306+
Endpoint: ``api/v1/market/data/report-announcements/summary``.
3307+
Method: ``GET``.
3308+
Documented endpoint: ``report_announcement_summary``.
3309+
3310+
Args:
3311+
announcement_id: 公告 ID (type: string; required: Y).
3312+
raw: Return the decoded JSON payload without tabular extraction.
3313+
fields: Optional field list or comma-separated field string applied after extraction.
3314+
as_dataframe: Return a pandas ``DataFrame`` by default; set to ``False`` for Python rows.
3315+
**kwargs: Extra request parameters forwarded unchanged. Useful when the service adds parameters before the SDK is regenerated.
3316+
3317+
Returns:
3318+
A pandas ``DataFrame`` by default, Python rows when
3319+
``as_dataframe=False``, raw JSON when ``raw=True``, or raw page
3320+
payloads when multi-page fetching is used with ``raw=True``.
3321+
"""
3322+
request_params = {'announcement_id': announcement_id}
3323+
request_params.update(kwargs)
3324+
return self._call_endpoint(
3325+
'report_announcement_summary',
3326+
raw=raw,
3327+
fields=fields,
3328+
as_dataframe=as_dataframe,
3329+
**request_params,
3330+
)
3331+
30793332
def stk_code_change(
30803333
self,
30813334
trade_code: Any | None = None,

‎src/ftshare/config.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import os
6+
57
DEFAULT_BASE_URL = "https://market.ft.tech/gateway/"
68
"""Default FTShare API base URL."""
79

@@ -47,3 +49,8 @@ def set_base_url(url: str) -> str:
4749
global _BASE_URL
4850
_BASE_URL = normalize_base_url(url)
4951
return _BASE_URL
52+
53+
54+
_env_base_url = os.environ.get("FTSHARE_BASE_URL")
55+
if _env_base_url:
56+
set_base_url(_env_base_url)

0 commit comments

Comments
 (0)