Skip to content

Commit 54f19d8

Browse files
authored
Merge pull request #14 from zwldarren/dev
feat(server): add financial metrics tool and more indicator support
2 parents e6a6191 + 77dd607 commit 54f19d8

File tree

5 files changed

+462
-145
lines changed

5 files changed

+462
-145
lines changed

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ An MCP server based on [akshare-one](https://github.com/zwldarren/akshare-one),
1717

1818
### `get_hist_data`
1919

20-
Get historical stock market data.
20+
Get historical stock market data. 'eastmoney_direct' supports all A, B, H shares.
2121

2222
- symbol (string): Stock code (e.g. '000001')
2323
- interval (string): Time interval ('minute','hour','day','week','month','year') (default: 'day')
@@ -26,49 +26,57 @@ Get historical stock market data.
2626
- end_date (string, optional): End date in YYYY-MM-DD format (default: '2030-12-31')
2727
- adjust (string, optional): Adjustment type ('none', 'qfq', 'hfq') (default: 'none')
2828
- source (string, optional): Data source ('eastmoney', 'eastmoney_direct', 'sina') (default: 'eastmoney')
29-
- indicators_list (list, optional): Technical indicators to add (e.g. ['SMA', 'EMA', 'RSI', 'MACD', 'BOLL', 'STOCH', 'ATR', 'CCI', 'ADX'])
29+
- indicators_list (list, optional): Technical indicators to add (e.g. ['SMA', 'EMA', 'RSI', 'MACD', 'BOLL', 'STOCH', 'ATR', 'CCI', 'ADX', 'WILLR', 'AD', 'ADOSC', 'OBV', 'MOM', 'SAR', 'TSF', 'APO', 'AROON', 'AROONOSC', 'BOP', 'CMO', 'DX', 'MFI', 'MINUS_DI', 'MINUS_DM', 'PLUS_DI', 'PLUS_DM', 'PPO', 'ROC', 'ROCP', 'ROCR', 'ROCR100', 'TRIX', 'ULTOSC'])
3030
- recent_n (number, optional): Number of most recent records to return (default: 100)
3131

3232
### `get_realtime_data`
3333

34-
Get real-time stock data
34+
Get real-time stock market data. 'eastmoney_direct' supports all A, B, H shares.
3535

3636
- symbol (string, optional): Stock code
37-
- source (string, optional): Data source ('xueqiu', 'eastmoney_direct') (default: 'xueqiu')
37+
- source (string, optional): Data source ('xueqiu', 'eastmoney', 'eastmoney_direct') (default: 'eastmoney_direct')
3838

3939
### `get_news_data`
4040

41-
Get stock-related news data
41+
Get stock-related news data.
4242

4343
- symbol (string): Stock code
44-
- recent_n (number, optional): Number of most recent records to return (optional)
44+
- recent_n (number, optional): Number of most recent records to return (default: 10)
4545

4646
### `get_balance_sheet`
4747

48-
Get company balance sheet data
48+
Get company balance sheet data.
4949

5050
- symbol (string): Stock code
51-
- recent_n (number, optional): Number of most recent records to return (optional)
51+
- recent_n (number, optional): Number of most recent records to return (default: 10)
5252

5353
### `get_income_statement`
5454

55-
Get company income statement data
55+
Get company income statement data.
5656

5757
- symbol (string): Stock code
58-
- recent_n (number, optional): Number of most recent records to return (optional)
58+
- recent_n (number, optional): Number of most recent records to return (default: 10)
5959

6060
### `get_cash_flow`
6161

62-
Get company cash flow statement data
62+
Get company cash flow statement data.
6363

6464
- symbol (string): Stock code
6565
- source (string, optional): Data source (default: 'sina')
66+
- recent_n (number, optional): Number of most recent records to return (default: 10)
6667

6768
### `get_inner_trade_data`
6869

69-
Get company insider trading data
70+
Get company insider trading data.
7071

71-
- symbol (string, optional): Stock code
72+
- symbol (string): Stock code
73+
74+
### `get_financial_metrics`
75+
76+
Get key financial metrics from the three major financial statements.
77+
78+
- symbol (string): Stock code
79+
- recent_n (number, optional): Number of most recent records to return (default: 10)
7280

7381
### `get_time_info`
7482

README_zh.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,66 @@
1717

1818
### `get_hist_data`
1919

20-
获取历史股票市场数据。
20+
获取历史股票市场数据。'eastmoney_direct' 支持所有 A、B、H 股
2121

2222
- symbol (字符串): 股票代码 (例如 '000001')
2323
- interval (字符串): 时间间隔 ('minute','hour','day','week','month','year') (默认: 'day')
24-
- interval_multiplier (数字, 可选): 间隔倍数 (默认: 1)
25-
- start_date (字符串, 可选): 开始日期 YYYY-MM-DD 格式 (默认: '1970-01-01')
26-
- end_date (字符串, 可选): 结束日期 YYYY-MM-DD 格式 (默认: '2030-12-31')
27-
- adjust (字符串, 可选): 调整类型 ('none', 'qfq', 'hfq') (默认: 'none')
28-
- source (字符串, 可选): 数据源 ('eastmoney', 'eastmoney_direct', 'sina') (默认: 'eastmoney')
29-
- indicators_list (列表, 可选): 技术指标 (例如 ['SMA', 'EMA', 'RSI', 'MACD', 'BOLL', 'STOCH', 'ATR', 'CCI', 'ADX'])
24+
- interval_multiplier (数字): 间隔倍数 (默认: 1)
25+
- start_date (字符串): 开始日期 YYYY-MM-DD 格式 (默认: '1970-01-01')
26+
- end_date (字符串): 结束日期 YYYY-MM-DD 格式 (默认: '2030-12-31')
27+
- adjust (字符串): 调整类型 ('none', 'qfq', 'hfq') (默认: 'none')
28+
- source (字符串): 数据源 ('eastmoney', 'eastmoney_direct', 'sina') (默认: 'eastmoney')
29+
- indicators_list (列表, 可选): 技术指标 (例如 ['SMA', 'EMA', 'RSI', 'MACD', 'BOLL', 'STOCH', 'ATR', 'CCI', 'ADX', 'WILLR', 'AD', 'ADOSC', 'OBV', 'MOM', 'SAR', 'TSF', 'APO', 'AROON', 'AROONOSC', 'BOP', 'CMO', 'DX', 'MFI', 'MINUS_DI', 'MINUS_DM', 'PLUS_DI', 'PLUS_DM', 'PPO', 'ROC', 'ROCP', 'ROCR', 'ROCR100', 'TRIX', 'ULTOSC'])
3030
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 100)
3131

3232
### `get_realtime_data`
3333

34-
获取实时股票数据
34+
获取实时股票市场数据。'eastmoney_direct' 支持所有 A、B、H 股
3535

3636
- symbol (字符串, 可选): 股票代码
37-
- source (字符串, 可选): 数据源 ('xueqiu', 'eastmoney_direct') (默认: 'xueqiu')
37+
- source (字符串): 数据源 ('xueqiu', 'eastmoney', 'eastmoney_direct') (默认: 'eastmoney_direct')
3838

3939
### `get_news_data`
4040

41-
获取股票相关新闻数据
41+
获取股票相关新闻数据
4242

4343
- symbol (字符串): 股票代码
44-
- recent_n (数字, 可选): 返回最近记录的数量 (可选)
44+
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 10)
4545

4646
### `get_balance_sheet`
4747

48-
获取公司资产负债表数据
48+
获取公司资产负债表数据
4949

5050
- symbol (字符串): 股票代码
51-
- recent_n (数字, 可选): 返回最近记录的数量 (可选)
51+
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 10)
5252

5353
### `get_income_statement`
5454

55-
获取公司利润表数据
55+
获取公司利润表数据
5656

5757
- symbol (字符串): 股票代码
58-
- recent_n (数字, 可选): 返回最近记录的数量 (可选)
58+
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 10)
5959

6060
### `get_cash_flow`
6161

62-
获取公司现金流量表数据
62+
获取公司现金流量表数据
6363

6464
- symbol (字符串): 股票代码
65-
- source (字符串, 可选): 数据源 (默认: 'sina')
65+
- source (字符串): 数据源 (默认: 'sina')
66+
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 10)
6667

6768
### `get_inner_trade_data`
6869

69-
获取公司内部交易数据
70+
获取公司内部交易数据
7071

71-
- symbol (字符串, 可选): 股票代码
72+
- symbol (字符串): 股票代码
73+
74+
### `get_financial_metrics`
75+
76+
获取三大财务报表的关键财务指标。
77+
78+
- symbol (字符串): 股票代码
79+
- recent_n (数字, 可选): 返回最近记录的数量 (默认: 10)
7280

7381
### `get_time_info`
7482

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[project]
22
name = "akshare-one-mcp"
3-
version = "0.2.3"
3+
version = "0.3.0"
44
description = "MCP server that provides access to Chinese stock market data using akshare-one"
55
readme = "README.md"
66
license = { text = "MIT" }
77
authors = [{ name = "zwldarren", email = "zwldarren@gmail.com" }]
88
requires-python = ">=3.12"
99
dependencies = [
10-
"akshare-one>=0.3.6",
10+
"akshare-one>=0.3.7",
1111
"fastmcp>=2.9.2",
1212
]
1313
keywords = ["akshare", "stock", "mcp", "mcp-server"]

src/akshare_one_mcp/server.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ def get_hist_data(
4646
"ATR",
4747
"CCI",
4848
"ADX",
49+
"WILLR",
50+
"AD",
51+
"ADOSC",
52+
"OBV",
53+
"MOM",
54+
"SAR",
55+
"TSF",
56+
"APO",
57+
"AROON",
58+
"AROONOSC",
59+
"BOP",
60+
"CMO",
61+
"DX",
62+
"MFI",
63+
"MINUS_DI",
64+
"MINUS_DM",
65+
"PLUS_DI",
66+
"PLUS_DM",
67+
"PPO",
68+
"ROC",
69+
"ROCP",
70+
"ROCR",
71+
"ROCR100",
72+
"TRIX",
73+
"ULTOSC",
4974
]
5075
]
5176
| None,
@@ -79,6 +104,40 @@ def get_hist_data(
79104
"ATR": (indicators.get_atr, {"window": 14}),
80105
"CCI": (indicators.get_cci, {"window": 14}),
81106
"ADX": (indicators.get_adx, {"window": 14}),
107+
"WILLR": (indicators.get_willr, {"window": 14}),
108+
"AD": (indicators.get_ad, {}),
109+
"ADOSC": (indicators.get_adosc, {"fast_period": 3, "slow_period": 10}),
110+
"OBV": (indicators.get_obv, {}),
111+
"MOM": (indicators.get_mom, {"window": 10}),
112+
"SAR": (indicators.get_sar, {"acceleration": 0.02, "maximum": 0.2}),
113+
"TSF": (indicators.get_tsf, {"window": 14}),
114+
"APO": (
115+
indicators.get_apo,
116+
{"fast_period": 12, "slow_period": 26, "ma_type": 0},
117+
),
118+
"AROON": (indicators.get_aroon, {"window": 14}),
119+
"AROONOSC": (indicators.get_aroonosc, {"window": 14}),
120+
"BOP": (indicators.get_bop, {}),
121+
"CMO": (indicators.get_cmo, {"window": 14}),
122+
"DX": (indicators.get_dx, {"window": 14}),
123+
"MFI": (indicators.get_mfi, {"window": 14}),
124+
"MINUS_DI": (indicators.get_minus_di, {"window": 14}),
125+
"MINUS_DM": (indicators.get_minus_dm, {"window": 14}),
126+
"PLUS_DI": (indicators.get_plus_di, {"window": 14}),
127+
"PLUS_DM": (indicators.get_plus_dm, {"window": 14}),
128+
"PPO": (
129+
indicators.get_ppo,
130+
{"fast_period": 12, "slow_period": 26, "ma_type": 0},
131+
),
132+
"ROC": (indicators.get_roc, {"window": 10}),
133+
"ROCP": (indicators.get_rocp, {"window": 10}),
134+
"ROCR": (indicators.get_rocr, {"window": 10}),
135+
"ROCR100": (indicators.get_rocr100, {"window": 10}),
136+
"TRIX": (indicators.get_trix, {"window": 30}),
137+
"ULTOSC": (
138+
indicators.get_ultosc,
139+
{"window1": 7, "window2": 14, "window3": 28},
140+
),
82141
}
83142
temp = []
84143
for indicator in indicators_list:
@@ -174,6 +233,22 @@ def get_inner_trade_data(
174233
return df.to_json(orient="records")
175234

176235

236+
@mcp.tool
237+
def get_financial_metrics(
238+
symbol: Annotated[str, Field(description="Stock symbol/ticker (e.g. '000001')")],
239+
recent_n: Annotated[
240+
int | None, Field(description="Number of most recent records to return", ge=1)
241+
] = 10,
242+
) -> str:
243+
"""
244+
Get key financial metrics from the three major financial statements.
245+
"""
246+
df = ako.get_financial_metrics(symbol)
247+
if recent_n is not None:
248+
df = df.head(recent_n)
249+
return df.to_json(orient="records")
250+
251+
177252
@mcp.tool
178253
def get_time_info() -> dict:
179254
"""Get current time with ISO format, timestamp, and the last trading day."""

0 commit comments

Comments
 (0)