webull-openapi-mcp 1.2.6__tar.gz → 1.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/PKG-INFO +19 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/README.md +18 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/pyproject.toml +1 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/server.json +2 -2
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_fundamental_screener_registration.py +19 -13
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_fundamental_tools.py +6 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_instrument_tools.py +18 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_market_data_tools.py +43 -55
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_screener_tools.py +40 -47
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/__init__.py +1 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/formatters.py +44 -30
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/community.py +0 -2
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/crypto.py +14 -2
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/event.py +11 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/fundamental.py +6 -7
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/futures.py +11 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/option.py +13 -1
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/screener.py +17 -44
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/stock.py +2 -2
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/instrument.py +19 -23
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/.env.example +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/.github/workflows/pypi-ci.yml +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/.gitignore +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/DISCLAIMER.md +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/LICENSE +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/mcpb/.mcpbignore +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/mcpb/build.sh +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/mcpb/build_manifest.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/mcpb/src/server.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/__init__.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_account_tools.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_audit.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_cli.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_community_tools.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_config.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_errors.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_formatters.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_guards.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_news_tools.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_order_history_tool.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_audit.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_config.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_formatters.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_guards.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_sdk.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_property_server.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_sdk_client.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/tests/test_stock_order_tools.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/__main__.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/audit.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/cli.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/config.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/constants.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/errors.py +3 -3
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/guards.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/region_config.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/sdk_client.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/server.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/__init__.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/__init__.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/financial.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/news.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/market_data/watchlist.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/__init__.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/account.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/assets.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/crypto_order.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/event_order.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/futures_order.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/option_order.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/order.py +0 -0
- {webull_openapi_mcp-1.2.6 → webull_openapi_mcp-1.2.7}/webull_openapi_mcp/tools/trading/stock_order.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: webull-openapi-mcp
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.7
|
|
4
4
|
Summary: MCP Server for Webull OpenAPI - enables AI assistants to securely access Webull trading and market data
|
|
5
5
|
Project-URL: Homepage, https://github.com/webull-inc/webull-openapi-mcp
|
|
6
6
|
Project-URL: Repository, https://github.com/webull-inc/webull-openapi-mcp
|
|
@@ -434,6 +434,24 @@ All commands accept `--env-file PATH` to specify a custom `.env` file location (
|
|
|
434
434
|
|
|
435
435
|
---
|
|
436
436
|
|
|
437
|
+
## Migration Notes (1.2.7)
|
|
438
|
+
|
|
439
|
+
This release moves the tool calls to the latest API paths and removes the old paging parameters without a compatibility layer. Clients that still send a removed parameter get a validation error (unexpected argument).
|
|
440
|
+
|
|
441
|
+
| Tool | Removed parameters | Use instead |
|
|
442
|
+
|------|--------------------|-------------|
|
|
443
|
+
| `get_instruments`, `get_crypto_instruments`, `get_event_instruments` | `page_size`, `last_instrument_id` | `pagination_key` |
|
|
444
|
+
| `get_event_series` | `page_size`, `last_series_id` | `pagination_key` |
|
|
445
|
+
| `get_market_sectors`, `get_market_sectors_detail`, `get_fund_dividends` | `page_size`, `page_index` | `pagination_key` |
|
|
446
|
+
| `get_gainers_losers`, `get_most_active`, `get_high_dividend`, `get_52_week_high_low` | `page_size`, `page_index` | None. These endpoints return a single result set without paging |
|
|
447
|
+
|
|
448
|
+
Paged tools print `Next pagination_key: ...` when more data is available. Pass that value as `pagination_key` to get the next page; the last page has no key.
|
|
449
|
+
|
|
450
|
+
Other changes:
|
|
451
|
+
|
|
452
|
+
- `get_option_bars`, `get_futures_bars`, `get_crypto_bars` and `get_event_bars` accept optional `start_time` and `end_time` (milliseconds).
|
|
453
|
+
- `get_stock_bars_single` now calls the batch bars endpoint, and the output groups rows under a `--- SYMBOL ---` header.
|
|
454
|
+
|
|
437
455
|
## Security
|
|
438
456
|
|
|
439
457
|
- **Never share your AK/SK with AI models** — Do not paste your App Key or App Secret into chat prompts, AI assistants, or any LLM conversation. These credentials should only be configured via environment variables or `.env` files, never exposed in plain text to the model.
|
|
@@ -404,6 +404,24 @@ All commands accept `--env-file PATH` to specify a custom `.env` file location (
|
|
|
404
404
|
|
|
405
405
|
---
|
|
406
406
|
|
|
407
|
+
## Migration Notes (1.2.7)
|
|
408
|
+
|
|
409
|
+
This release moves the tool calls to the latest API paths and removes the old paging parameters without a compatibility layer. Clients that still send a removed parameter get a validation error (unexpected argument).
|
|
410
|
+
|
|
411
|
+
| Tool | Removed parameters | Use instead |
|
|
412
|
+
|------|--------------------|-------------|
|
|
413
|
+
| `get_instruments`, `get_crypto_instruments`, `get_event_instruments` | `page_size`, `last_instrument_id` | `pagination_key` |
|
|
414
|
+
| `get_event_series` | `page_size`, `last_series_id` | `pagination_key` |
|
|
415
|
+
| `get_market_sectors`, `get_market_sectors_detail`, `get_fund_dividends` | `page_size`, `page_index` | `pagination_key` |
|
|
416
|
+
| `get_gainers_losers`, `get_most_active`, `get_high_dividend`, `get_52_week_high_low` | `page_size`, `page_index` | None. These endpoints return a single result set without paging |
|
|
417
|
+
|
|
418
|
+
Paged tools print `Next pagination_key: ...` when more data is available. Pass that value as `pagination_key` to get the next page; the last page has no key.
|
|
419
|
+
|
|
420
|
+
Other changes:
|
|
421
|
+
|
|
422
|
+
- `get_option_bars`, `get_futures_bars`, `get_crypto_bars` and `get_event_bars` accept optional `start_time` and `end_time` (milliseconds).
|
|
423
|
+
- `get_stock_bars_single` now calls the batch bars endpoint, and the output groups rows under a `--- SYMBOL ---` header.
|
|
424
|
+
|
|
407
425
|
## Security
|
|
408
426
|
|
|
409
427
|
- **Never share your AK/SK with AI models** — Do not paste your App Key or App Secret into chat prompts, AI assistants, or any LLM conversation. These credentials should only be configured via environment variables or `.env` files, never exposed in plain text to the model.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "webull-openapi-mcp"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.7"
|
|
8
8
|
description = "MCP Server for Webull OpenAPI - enables AI assistants to securely access Webull trading and market data"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "io.github.webull-inc/webull-openapi-mcp",
|
|
4
4
|
"title": "Webull OpenAPI",
|
|
5
5
|
"description": "MCP server for Webull OpenAPI: trading and market data access for AI assistants",
|
|
6
|
-
"version": "1.2.
|
|
6
|
+
"version": "1.2.7",
|
|
7
7
|
"repository": {
|
|
8
8
|
"url": "https://github.com/webull-inc/webull-openapi-mcp",
|
|
9
9
|
"source": "github"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"registryType": "pypi",
|
|
14
14
|
"registryBaseUrl": "https://pypi.org",
|
|
15
15
|
"identifier": "webull-openapi-mcp",
|
|
16
|
-
"version": "1.2.
|
|
16
|
+
"version": "1.2.7",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -127,35 +127,41 @@ def test_income_statement_passes_type_and_count():
|
|
|
127
127
|
|
|
128
128
|
def test_high_dividend_invokes_screener():
|
|
129
129
|
mcp, sdk = _build_mcp()
|
|
130
|
-
sdk.data.screener.
|
|
131
|
-
"
|
|
132
|
-
|
|
133
|
-
}
|
|
130
|
+
sdk.data.screener.list_high_dividend.return_value = [
|
|
131
|
+
{"symbol": "T", "name": "AT&T", "yield": "0.06"},
|
|
132
|
+
]
|
|
134
133
|
text = _call(mcp, "get_high_dividend", {})
|
|
135
|
-
sdk.data.screener.
|
|
134
|
+
sdk.data.screener.list_high_dividend.assert_called_once()
|
|
135
|
+
_, kwargs = sdk.data.screener.list_high_dividend.call_args
|
|
136
|
+
assert "page_index" not in kwargs and "page_size" not in kwargs
|
|
136
137
|
assert "High Dividend" in text
|
|
137
138
|
|
|
138
139
|
|
|
139
140
|
def test_52_week_high_low_invokes_screener():
|
|
140
141
|
mcp, sdk = _build_mcp()
|
|
141
|
-
sdk.data.screener.
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
}
|
|
142
|
+
sdk.data.screener.list_52whl.return_value = [
|
|
143
|
+
{"symbol": "AAPL", "name": "Apple", "price": "300"},
|
|
144
|
+
]
|
|
145
145
|
text = _call(mcp, "get_52_week_high_low", {"rank_type": "NEW_HIGH"})
|
|
146
|
-
sdk.data.screener.
|
|
146
|
+
sdk.data.screener.list_52whl.assert_called_once()
|
|
147
147
|
assert "52-Week High/Low" in text
|
|
148
148
|
|
|
149
149
|
|
|
150
150
|
def test_market_sectors_detail_requires_sector_id():
|
|
151
151
|
mcp, sdk = _build_mcp()
|
|
152
|
-
sdk.data.screener.
|
|
152
|
+
sdk.data.screener.list_market_sectors_detail.return_value = {
|
|
153
153
|
"id": "1", "name": "Tech", "change_ratio": "0.01", "data": [],
|
|
154
|
+
"pagination_key": "NEXT123",
|
|
154
155
|
}
|
|
155
|
-
text = _call(
|
|
156
|
-
|
|
156
|
+
text = _call(
|
|
157
|
+
mcp, "get_market_sectors_detail",
|
|
158
|
+
{"sector_id": "1001", "pagination_key": "PREV456"},
|
|
159
|
+
)
|
|
160
|
+
_, kwargs = sdk.data.screener.list_market_sectors_detail.call_args
|
|
157
161
|
assert kwargs["sector_id"] == "1001"
|
|
162
|
+
assert kwargs["pagination_key"] == "PREV456"
|
|
158
163
|
assert "Market Sector Detail" in text
|
|
164
|
+
assert "Next pagination_key: NEXT123" in text
|
|
159
165
|
|
|
160
166
|
|
|
161
167
|
def test_sdk_exception_is_handled_gracefully():
|
|
@@ -368,6 +368,12 @@ class TestFormatFundDividends:
|
|
|
368
368
|
assert "0.5" in result
|
|
369
369
|
assert "2026-01-15" in result
|
|
370
370
|
|
|
371
|
+
def test_unwraps_paginated_response(self):
|
|
372
|
+
data = {"data": [{"dps": "0.7", "pay_date": "2026-02-15"}], "pagination_key": "k1"}
|
|
373
|
+
result = format_fund_dividends(data)
|
|
374
|
+
assert "0.7" in result
|
|
375
|
+
assert "Next pagination_key: k1" in result
|
|
376
|
+
|
|
371
377
|
|
|
372
378
|
class TestFormatFundSplits:
|
|
373
379
|
def test_formats_data(self):
|
|
@@ -152,3 +152,21 @@ class TestFormatAnalystTargetPrice:
|
|
|
152
152
|
def test_non_dict_returns_no_data(self):
|
|
153
153
|
assert format_analyst_target_price("invalid") == _NO_DATA
|
|
154
154
|
assert format_analyst_target_price([]) == _NO_DATA
|
|
155
|
+
# ---------------------------------------------------------------------------
|
|
156
|
+
# Instrument list pagination
|
|
157
|
+
# ---------------------------------------------------------------------------
|
|
158
|
+
class TestFormatInstrumentsPagination:
|
|
159
|
+
def test_unwraps_paginated_response(self):
|
|
160
|
+
from webull_openapi_mcp.formatters import format_instruments
|
|
161
|
+
data = {
|
|
162
|
+
"data": [{"symbol": "AAPL", "name": "APPLE INC"}],
|
|
163
|
+
"pagination_key": "cursor-1",
|
|
164
|
+
}
|
|
165
|
+
result = format_instruments(data)
|
|
166
|
+
assert "AAPL" in result
|
|
167
|
+
assert "Next pagination_key: cursor-1" in result
|
|
168
|
+
def test_last_page_has_no_cursor(self):
|
|
169
|
+
from webull_openapi_mcp.formatters import format_instruments
|
|
170
|
+
result = format_instruments({"data": [{"symbol": "AAPL"}]})
|
|
171
|
+
assert "AAPL" in result
|
|
172
|
+
assert "pagination_key" not in result
|
|
@@ -49,29 +49,26 @@ def test_returns_no_data_for_empty_list(fn):
|
|
|
49
49
|
|
|
50
50
|
class TestFormatGainersLosers:
|
|
51
51
|
def test_formats_data_list(self):
|
|
52
|
-
data =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
}
|
|
52
|
+
data = [
|
|
53
|
+
{
|
|
54
|
+
"symbol": "TSLA",
|
|
55
|
+
"name": "Tesla Inc",
|
|
56
|
+
"price": "250.00",
|
|
57
|
+
"pre_close": "235.00",
|
|
58
|
+
"open": "236.00",
|
|
59
|
+
"high": "252.00",
|
|
60
|
+
"low": "234.00",
|
|
61
|
+
"close": "250.00",
|
|
62
|
+
"change": "15.00",
|
|
63
|
+
"change_ratio": "0.064",
|
|
64
|
+
"amplitude": "0.0766",
|
|
65
|
+
"volume": "5000000",
|
|
66
|
+
"turnover_rate": "0.005",
|
|
67
|
+
"market_value": "800000000000",
|
|
68
|
+
"exchange_code": "NAS",
|
|
69
|
+
"currency_code": "USD",
|
|
70
|
+
},
|
|
71
|
+
]
|
|
75
72
|
result = format_gainers_losers(data)
|
|
76
73
|
assert "Gainers / Losers" in result
|
|
77
74
|
assert "TSLA" in result
|
|
@@ -81,17 +78,11 @@ class TestFormatGainersLosers:
|
|
|
81
78
|
assert "0.064" in result
|
|
82
79
|
assert "0.0766" in result
|
|
83
80
|
assert "NAS" in result
|
|
84
|
-
assert "More results available" in result
|
|
85
|
-
|
|
86
|
-
def test_no_has_more(self):
|
|
87
|
-
data = {"has_more": False, "data": [{"symbol": "X", "name": "Test"}]}
|
|
88
|
-
result = format_gainers_losers(data)
|
|
89
81
|
assert "More results available" not in result
|
|
90
82
|
|
|
83
|
+
|
|
91
84
|
def test_empty_data_list(self):
|
|
92
|
-
|
|
93
|
-
result = format_gainers_losers(data)
|
|
94
|
-
assert result == _NO_DATA
|
|
85
|
+
assert format_gainers_losers([]) == _NO_DATA
|
|
95
86
|
|
|
96
87
|
|
|
97
88
|
# ---------------------------------------------------------------------------
|
|
@@ -100,30 +91,27 @@ class TestFormatGainersLosers:
|
|
|
100
91
|
|
|
101
92
|
class TestFormatMostActive:
|
|
102
93
|
def test_formats_with_relative_volume(self):
|
|
103
|
-
data =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
}
|
|
94
|
+
data = [
|
|
95
|
+
{
|
|
96
|
+
"symbol": "AAPL",
|
|
97
|
+
"name": "Apple Inc",
|
|
98
|
+
"price": "290.00",
|
|
99
|
+
"pre_close": "285.00",
|
|
100
|
+
"open": "286.00",
|
|
101
|
+
"high": "291.00",
|
|
102
|
+
"low": "284.00",
|
|
103
|
+
"close": "290.00",
|
|
104
|
+
"change": "5.00",
|
|
105
|
+
"change_ratio": "0.018",
|
|
106
|
+
"amplitude": "0.0246",
|
|
107
|
+
"volume": "80000000",
|
|
108
|
+
"turnover_rate": "0.005",
|
|
109
|
+
"market_value": "4500000000000",
|
|
110
|
+
"exchange_code": "NAS",
|
|
111
|
+
"currency_code": "USD",
|
|
112
|
+
"relative_volume_10d": "2.35",
|
|
113
|
+
},
|
|
114
|
+
]
|
|
127
115
|
result = format_most_active(data)
|
|
128
116
|
assert "Most Active" in result
|
|
129
117
|
assert "AAPL" in result
|
|
@@ -77,6 +77,13 @@ class TestFormatMarketSectors:
|
|
|
77
77
|
def test_empty_data_key(self):
|
|
78
78
|
assert format_market_sectors({"data": []}) == _NO_DATA
|
|
79
79
|
|
|
80
|
+
def test_shows_next_pagination_key(self):
|
|
81
|
+
data = {
|
|
82
|
+
"data": [{"id": "1", "name": "Energy", "change_ratio": "0.02"}],
|
|
83
|
+
"pagination_key": "abc123",
|
|
84
|
+
}
|
|
85
|
+
assert "Next pagination_key: abc123" in format_market_sectors(data)
|
|
86
|
+
|
|
80
87
|
|
|
81
88
|
# ---------------------------------------------------------------------------
|
|
82
89
|
# Market Sectors Detail
|
|
@@ -131,39 +138,32 @@ class TestFormatMarketSectorsDetail:
|
|
|
131
138
|
|
|
132
139
|
class TestFormatHighDividend:
|
|
133
140
|
def test_formats_data(self):
|
|
134
|
-
data =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
}
|
|
141
|
+
data = [
|
|
142
|
+
{
|
|
143
|
+
"instrument_id": "913256",
|
|
144
|
+
"symbol": "T",
|
|
145
|
+
"name": "AT&T Inc",
|
|
146
|
+
"price": "20.00",
|
|
147
|
+
"change_ratio": "0.01",
|
|
148
|
+
"volume": "30000000",
|
|
149
|
+
"market_value": "150000000000",
|
|
150
|
+
"yield": "0.06",
|
|
151
|
+
"dividend": "1.11",
|
|
152
|
+
"ex_date": "2026-01-09",
|
|
153
|
+
"pe_ttm": "8.5",
|
|
154
|
+
},
|
|
155
|
+
]
|
|
152
156
|
result = format_high_dividend(data)
|
|
153
157
|
assert "High Dividend" in result
|
|
154
158
|
assert "AT&T Inc" in result
|
|
155
159
|
assert "0.06" in result
|
|
156
160
|
assert "1.11" in result
|
|
157
161
|
assert "2026-01-09" in result
|
|
158
|
-
assert "More results available" in result
|
|
159
|
-
|
|
160
|
-
def test_no_has_more(self):
|
|
161
|
-
data = {"has_more": False, "data": [{"symbol": "T", "name": "AT&T", "yield": "0.06"}]}
|
|
162
|
-
result = format_high_dividend(data)
|
|
163
162
|
assert "More results available" not in result
|
|
164
163
|
|
|
164
|
+
|
|
165
165
|
def test_empty_data_list(self):
|
|
166
|
-
assert format_high_dividend(
|
|
166
|
+
assert format_high_dividend([]) == _NO_DATA
|
|
167
167
|
|
|
168
168
|
|
|
169
169
|
# ---------------------------------------------------------------------------
|
|
@@ -172,24 +172,21 @@ class TestFormatHighDividend:
|
|
|
172
172
|
|
|
173
173
|
class TestFormatFiftyTwoWeek:
|
|
174
174
|
def test_formats_data(self):
|
|
175
|
-
data =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
}
|
|
175
|
+
data = [
|
|
176
|
+
{
|
|
177
|
+
"instrument_id": "913256135",
|
|
178
|
+
"symbol": "AAPL",
|
|
179
|
+
"name": "Apple Inc",
|
|
180
|
+
"price": "300.00",
|
|
181
|
+
"change_ratio": "0.02",
|
|
182
|
+
"change_ratio_52w": "0.55",
|
|
183
|
+
"price_1w": "290.00",
|
|
184
|
+
"price_52w": "200.00",
|
|
185
|
+
"high": "305.00",
|
|
186
|
+
"low": "295.00",
|
|
187
|
+
"pe_ttm": "30.0",
|
|
188
|
+
},
|
|
189
|
+
]
|
|
193
190
|
result = format_fifty_two_week(data)
|
|
194
191
|
assert "52-Week High/Low" in result
|
|
195
192
|
assert "AAPL" in result
|
|
@@ -198,13 +195,9 @@ class TestFormatFiftyTwoWeek:
|
|
|
198
195
|
assert "200.00" in result
|
|
199
196
|
assert "30.0" in result
|
|
200
197
|
|
|
201
|
-
def test_has_more_flag(self):
|
|
202
|
-
data = {"has_more": True, "data": [{"symbol": "AAPL", "name": "Apple", "price": "300"}]}
|
|
203
|
-
result = format_fifty_two_week(data)
|
|
204
|
-
assert "More results available" in result
|
|
205
198
|
|
|
206
199
|
def test_empty_data_list(self):
|
|
207
|
-
assert format_fifty_two_week(
|
|
200
|
+
assert format_fifty_two_week([]) == _NO_DATA
|
|
208
201
|
|
|
209
202
|
|
|
210
203
|
# ---------------------------------------------------------------------------
|
|
@@ -920,6 +920,15 @@ def format_order_executions(data: Any) -> str:
|
|
|
920
920
|
# Instrument formatters
|
|
921
921
|
# ---------------------------------------------------------------------------
|
|
922
922
|
|
|
923
|
+
def _next_page_line(data: Any) -> list[str]:
|
|
924
|
+
"""Return the next-page hint line when the response carries a pagination_key."""
|
|
925
|
+
if isinstance(data, dict):
|
|
926
|
+
pagination_key = data.get("pagination_key") or data.get("next_pagination_key")
|
|
927
|
+
if pagination_key:
|
|
928
|
+
return [f"\nNext pagination_key: {pagination_key}"]
|
|
929
|
+
return []
|
|
930
|
+
|
|
931
|
+
|
|
923
932
|
def _format_flat_item(item: dict, indent: str = " ") -> list[str]:
|
|
924
933
|
"""Format a single dict item as flat key-value lines."""
|
|
925
934
|
lines: list[str] = []
|
|
@@ -931,12 +940,21 @@ def _format_flat_item(item: dict, indent: str = " ") -> list[str]:
|
|
|
931
940
|
|
|
932
941
|
|
|
933
942
|
def _format_flat_list(data: Any, title: str) -> str:
|
|
934
|
-
"""Format a list of dicts as flat key-value output.
|
|
943
|
+
"""Format a list of dicts as flat key-value output.
|
|
944
|
+
|
|
945
|
+
Cursor-paginated responses ``{data: [...], pagination_key: "..."}`` are
|
|
946
|
+
unwrapped and the next-page cursor is appended after the items.
|
|
947
|
+
"""
|
|
935
948
|
if not data:
|
|
936
949
|
return _NO_DATA
|
|
950
|
+
next_page: list[str] = []
|
|
937
951
|
if isinstance(data, dict):
|
|
938
|
-
data
|
|
939
|
-
|
|
952
|
+
if isinstance(data.get("data"), list):
|
|
953
|
+
next_page = _next_page_line(data)
|
|
954
|
+
data = data["data"]
|
|
955
|
+
else:
|
|
956
|
+
data = [data]
|
|
957
|
+
if not isinstance(data, list) or not data:
|
|
940
958
|
return _NO_DATA
|
|
941
959
|
lines: list[str] = [f"=== {title} ==="]
|
|
942
960
|
for i, item in enumerate(data):
|
|
@@ -945,6 +963,7 @@ def _format_flat_list(data: Any, title: str) -> str:
|
|
|
945
963
|
if i > 0:
|
|
946
964
|
lines.append("")
|
|
947
965
|
lines.extend(_format_flat_item(item))
|
|
966
|
+
lines.extend(next_page)
|
|
948
967
|
return "\n".join(lines)
|
|
949
968
|
|
|
950
969
|
|
|
@@ -1367,8 +1386,8 @@ def _format_screener_item(item: dict) -> str:
|
|
|
1367
1386
|
def format_gainers_losers(data: Any) -> str:
|
|
1368
1387
|
"""Format gainers/losers screener response.
|
|
1369
1388
|
|
|
1370
|
-
API returns
|
|
1371
|
-
change,
|
|
1389
|
+
API returns a bare list (no pagination): [{instrument_id, symbol, name, price,
|
|
1390
|
+
change, change_ratio, volume, market_value, ...}]
|
|
1372
1391
|
"""
|
|
1373
1392
|
if not data:
|
|
1374
1393
|
return _NO_DATA
|
|
@@ -1382,9 +1401,6 @@ def format_gainers_losers(data: Any) -> str:
|
|
|
1382
1401
|
if isinstance(item, dict):
|
|
1383
1402
|
lines.append(_format_screener_item(item))
|
|
1384
1403
|
|
|
1385
|
-
has_more = data.get("has_more") if isinstance(data, dict) else None
|
|
1386
|
-
if has_more is True:
|
|
1387
|
-
lines.append("\n (More results available — increase page_size or page_index)")
|
|
1388
1404
|
|
|
1389
1405
|
return "\n".join(lines)
|
|
1390
1406
|
|
|
@@ -1392,8 +1408,8 @@ def format_gainers_losers(data: Any) -> str:
|
|
|
1392
1408
|
def format_most_active(data: Any) -> str:
|
|
1393
1409
|
"""Format most active screener response.
|
|
1394
1410
|
|
|
1395
|
-
API returns
|
|
1396
|
-
change,
|
|
1411
|
+
API returns a bare list (no pagination): [{instrument_id, symbol, name, price,
|
|
1412
|
+
change, change_ratio, volume, market_value, relative_volume_10d, ...}]
|
|
1397
1413
|
"""
|
|
1398
1414
|
if not data:
|
|
1399
1415
|
return _NO_DATA
|
|
@@ -1409,9 +1425,6 @@ def format_most_active(data: Any) -> str:
|
|
|
1409
1425
|
extra = f"\n Relative Volume 10d: {rel_vol}" if rel_vol != "N/A" else ""
|
|
1410
1426
|
lines.append(_format_screener_item(item) + extra)
|
|
1411
1427
|
|
|
1412
|
-
has_more = data.get("has_more") if isinstance(data, dict) else None
|
|
1413
|
-
if has_more is True:
|
|
1414
|
-
lines.append("\n (More results available — increase page_size or page_index)")
|
|
1415
1428
|
|
|
1416
1429
|
return "\n".join(lines)
|
|
1417
1430
|
|
|
@@ -1955,12 +1968,14 @@ def format_fund_brief(data: Any) -> str:
|
|
|
1955
1968
|
def format_fund_dividends(data: Any) -> str:
|
|
1956
1969
|
"""Format fund dividends response.
|
|
1957
1970
|
|
|
1958
|
-
API returns
|
|
1971
|
+
API returns {data: [{share_date, publish_date, pay_date, record_date, dps}],
|
|
1972
|
+
pagination_key: str}; pagination_key is absent on the last page.
|
|
1959
1973
|
"""
|
|
1960
1974
|
if not data:
|
|
1961
1975
|
return _NO_DATA
|
|
1976
|
+
next_page = _next_page_line(data)
|
|
1962
1977
|
if isinstance(data, dict):
|
|
1963
|
-
data = [data]
|
|
1978
|
+
data = data["data"] if isinstance(data.get("data"), list) else [data]
|
|
1964
1979
|
if not isinstance(data, list):
|
|
1965
1980
|
return _NO_DATA
|
|
1966
1981
|
|
|
@@ -1973,6 +1988,7 @@ def format_fund_dividends(data: Any) -> str:
|
|
|
1973
1988
|
f"Pay: {_get(item, 'pay_date')} Record: {_get(item, 'record_date')} "
|
|
1974
1989
|
f"Publish: {_get(item, 'publish_date')}"
|
|
1975
1990
|
)
|
|
1991
|
+
lines.extend(next_page)
|
|
1976
1992
|
return "\n".join(lines)
|
|
1977
1993
|
|
|
1978
1994
|
|
|
@@ -2200,11 +2216,12 @@ def format_cash_flow(data: Any) -> str:
|
|
|
2200
2216
|
def format_market_sectors(data: Any) -> str:
|
|
2201
2217
|
"""Format market sectors response.
|
|
2202
2218
|
|
|
2203
|
-
API returns
|
|
2204
|
-
advanced, flat, data: [{instrument_id, name, symbol}]}]
|
|
2219
|
+
API returns {data: [{id, name, change_ratio, volume, market_value, declined,
|
|
2220
|
+
advanced, flat, data: [{instrument_id, name, symbol}]}], pagination_key: str}
|
|
2205
2221
|
"""
|
|
2206
2222
|
if not data:
|
|
2207
2223
|
return _NO_DATA
|
|
2224
|
+
next_page = _next_page_line(data)
|
|
2208
2225
|
if isinstance(data, dict):
|
|
2209
2226
|
data = data.get("data", data) if "data" in data else [data]
|
|
2210
2227
|
if not isinstance(data, list) or not data:
|
|
@@ -2231,6 +2248,7 @@ def format_market_sectors(data: Any) -> str:
|
|
|
2231
2248
|
f" {_get(stock, 'symbol'):>10s} {_get(stock, 'name'):<24s} "
|
|
2232
2249
|
f"(instrument_id: {_get(stock, 'instrument_id')})"
|
|
2233
2250
|
)
|
|
2251
|
+
lines.extend(next_page)
|
|
2234
2252
|
return "\n".join(lines)
|
|
2235
2253
|
|
|
2236
2254
|
|
|
@@ -2251,7 +2269,8 @@ def format_market_sectors_detail(data: Any) -> str:
|
|
|
2251
2269
|
|
|
2252
2270
|
API returns: {id, name, change_ratio, declined, advanced, flat,
|
|
2253
2271
|
data: [{instrument_id, category, currency, name, symbol, exchange_code, close,
|
|
2254
|
-
change_ratio, price, volume, market_value, turnover_rate, amplitude, high, low}]
|
|
2272
|
+
change_ratio, price, volume, market_value, turnover_rate, amplitude, high, low}],
|
|
2273
|
+
pagination_key: str}
|
|
2255
2274
|
"""
|
|
2256
2275
|
if not data:
|
|
2257
2276
|
return _NO_DATA
|
|
@@ -2269,16 +2288,17 @@ def format_market_sectors_detail(data: Any) -> str:
|
|
|
2269
2288
|
for stock in stocks:
|
|
2270
2289
|
if isinstance(stock, dict):
|
|
2271
2290
|
lines.extend(_format_sector_detail_stock(stock))
|
|
2291
|
+
lines.extend(_next_page_line(data))
|
|
2272
2292
|
return "\n".join(lines)
|
|
2273
2293
|
|
|
2274
2294
|
|
|
2275
2295
|
def format_high_dividend(data: Any) -> str:
|
|
2276
2296
|
"""Format high dividend screener response.
|
|
2277
2297
|
|
|
2278
|
-
API returns
|
|
2279
|
-
ticker_symbol, exchange_code, close, change, change_ratio, price, volume,
|
|
2298
|
+
API returns a bare list (no pagination): [{instrument_id, category, currency, name,
|
|
2299
|
+
symbol, ticker_symbol, exchange_code, close, change, change_ratio, price, volume,
|
|
2280
2300
|
market_value, turnover_rate, amplitude, high, low, turnover, yield, dividend,
|
|
2281
|
-
ex_date, pe_ttm}]
|
|
2301
|
+
ex_date, pe_ttm}]
|
|
2282
2302
|
"""
|
|
2283
2303
|
if not data:
|
|
2284
2304
|
return _NO_DATA
|
|
@@ -2304,9 +2324,6 @@ def format_high_dividend(data: Any) -> str:
|
|
|
2304
2324
|
f"Volume: {_get(item, 'volume')} Market Value: {_get(item, 'market_value')}"
|
|
2305
2325
|
)
|
|
2306
2326
|
|
|
2307
|
-
has_more = data.get("has_more") if isinstance(data, dict) else None
|
|
2308
|
-
if has_more is True:
|
|
2309
|
-
lines.append("\n (More results available — increase page_size or page_index)")
|
|
2310
2327
|
|
|
2311
2328
|
return "\n".join(lines)
|
|
2312
2329
|
|
|
@@ -2314,10 +2331,10 @@ def format_high_dividend(data: Any) -> str:
|
|
|
2314
2331
|
def format_fifty_two_week(data: Any) -> str:
|
|
2315
2332
|
"""Format 52-week high/low screener response.
|
|
2316
2333
|
|
|
2317
|
-
API returns
|
|
2318
|
-
ticker_symbol, exchange_code, close, change, change_ratio, price, volume,
|
|
2334
|
+
API returns a bare list (no pagination): [{instrument_id, category, currency, name,
|
|
2335
|
+
symbol, ticker_symbol, exchange_code, close, change, change_ratio, price, volume,
|
|
2319
2336
|
market_value, turnover_rate, high, low, turnover, amplitude, price_1w, price_52w,
|
|
2320
|
-
change_ratio_52w, pe_ttm}]
|
|
2337
|
+
change_ratio_52w, pe_ttm}]
|
|
2321
2338
|
"""
|
|
2322
2339
|
if not data:
|
|
2323
2340
|
return _NO_DATA
|
|
@@ -2343,9 +2360,6 @@ def format_fifty_two_week(data: Any) -> str:
|
|
|
2343
2360
|
f"High: {_get(item, 'high')} Low: {_get(item, 'low')} PE(TTM): {_get(item, 'pe_ttm')}"
|
|
2344
2361
|
)
|
|
2345
2362
|
|
|
2346
|
-
has_more = data.get("has_more") if isinstance(data, dict) else None
|
|
2347
|
-
if has_more is True:
|
|
2348
|
-
lines.append("\n (More results available — increase page_size or page_index)")
|
|
2349
2363
|
|
|
2350
2364
|
return "\n".join(lines)
|
|
2351
2365
|
|
|
@@ -61,8 +61,6 @@ def register_community_tools(
|
|
|
61
61
|
Must be provided together with symbol.
|
|
62
62
|
"""
|
|
63
63
|
audit.log_tool_call("create_community_post", {"symbol": symbol, "category": category})
|
|
64
|
-
# symbol 与 category 必须成对提供;用真值判断使空串与 None 都视为未提供,
|
|
65
|
-
# 并把空串归一化为 None,避免把空值发给 SDK。
|
|
66
64
|
symbol = symbol or None
|
|
67
65
|
category = category or None
|
|
68
66
|
if (symbol is None) != (category is None):
|