futu-stock-mcp-server 0.1.0__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.
Potentially problematic release.
This version of futu-stock-mcp-server might be problematic. Click here for more details.
- futu_stock_mcp_server-0.1.0/.gitignore +41 -0
- futu_stock_mcp_server-0.1.0/LICENSE +21 -0
- futu_stock_mcp_server-0.1.0/PKG-INFO +661 -0
- futu_stock_mcp_server-0.1.0/README.md +619 -0
- futu_stock_mcp_server-0.1.0/pyproject.toml +83 -0
- futu_stock_mcp_server-0.1.0/src/futu_stock_mcp_server/__init__.py +0 -0
- futu_stock_mcp_server-0.1.0/src/futu_stock_mcp_server/server.py +1475 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual Environment
|
|
24
|
+
.env
|
|
25
|
+
.venv
|
|
26
|
+
env/
|
|
27
|
+
venv/
|
|
28
|
+
ENV/
|
|
29
|
+
|
|
30
|
+
# IDE
|
|
31
|
+
.idea/
|
|
32
|
+
.vscode/
|
|
33
|
+
*.swp
|
|
34
|
+
*.swo
|
|
35
|
+
|
|
36
|
+
# Logs
|
|
37
|
+
*.log
|
|
38
|
+
logs/
|
|
39
|
+
|
|
40
|
+
# Local development
|
|
41
|
+
.DS_Store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Futu Stock MCP Server
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: futu-stock-mcp-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Model Context Protocol (MCP) server for accessing Futu OpenAPI functionality
|
|
5
|
+
Project-URL: Homepage, https://github.com/shuizhengqi1/futu-stock-mcp-server
|
|
6
|
+
Project-URL: Documentation, https://github.com/shuizhengqi1/futu-stock-mcp-server#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/shuizhengqi1/futu-stock-mcp-server
|
|
8
|
+
Project-URL: Issues, https://github.com/shuizhengqi1/futu-stock-mcp-server/issues
|
|
9
|
+
Author-email: shuizhengqi <shuizhengqi1@163.com>
|
|
10
|
+
Maintainer-email: shuizhengqi <shuizhengqi1@163.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: api,finance,futu,mcp,stock,trading
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: aiohttp
|
|
26
|
+
Requires-Dist: fastapi
|
|
27
|
+
Requires-Dist: futu-api
|
|
28
|
+
Requires-Dist: loguru
|
|
29
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
30
|
+
Requires-Dist: psutil
|
|
31
|
+
Requires-Dist: pydantic
|
|
32
|
+
Requires-Dist: python-dotenv
|
|
33
|
+
Requires-Dist: uvicorn
|
|
34
|
+
Requires-Dist: websockets
|
|
35
|
+
Provides-Extra: dev
|
|
36
|
+
Requires-Dist: black; extra == 'dev'
|
|
37
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
38
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
40
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
# Futu Stock MCP Server
|
|
44
|
+
|
|
45
|
+
[](https://www.python.org)
|
|
46
|
+
[](LICENSE)
|
|
47
|
+
[](https://openapi.futunn.com/futu-api-doc/)
|
|
48
|
+
|
|
49
|
+
基于[模型上下文协议(MCP)](https://github.com/cursor-ai/model-context-protocol)的富途证券行情交易接口服务器。将富途OpenAPI功能以标准化的MCP协议提供给AI模型使用,支持行情订阅、数据查询等功能。
|
|
50
|
+
|
|
51
|
+
## 🌟 特性
|
|
52
|
+
|
|
53
|
+
- 🔌 完全兼容 MCP 2.0 协议标准
|
|
54
|
+
- 📊 支持港股、美股、A股等市场的实时行情
|
|
55
|
+
- 🔄 支持实时数据订阅和推送
|
|
56
|
+
- 📈 支持K线、逐笔、买卖盘等多维度数据
|
|
57
|
+
- 🔒 安全的API调用和数据访问机制
|
|
58
|
+
- 🛠 提供完整的开发工具和示例代码
|
|
59
|
+
|
|
60
|
+
## ⚠️ 前置要求
|
|
61
|
+
|
|
62
|
+
在使用本项目之前,您需要:
|
|
63
|
+
|
|
64
|
+
1. 拥有富途证券账户并开通OpenAPI权限
|
|
65
|
+
2. 安装并运行富途的OpenD网关程序([官方文档](https://openapi.futunn.com/futu-api-doc/intro/intro.html))
|
|
66
|
+
3. 根据您的需求订阅相应的行情权限
|
|
67
|
+
|
|
68
|
+
## 🔒 安全提示
|
|
69
|
+
|
|
70
|
+
- 请勿在代码中硬编码任何账号密码信息
|
|
71
|
+
- 确保`.env`文件已添加到`.gitignore`中
|
|
72
|
+
- 妥善保管您的API访问凭证
|
|
73
|
+
- 遵守富途OpenAPI的使用条款和限制
|
|
74
|
+
|
|
75
|
+
## 📝 免责声明
|
|
76
|
+
|
|
77
|
+
本项目是一个开源工具,旨在简化富途OpenAPI的接入流程。使用本项目时请注意:
|
|
78
|
+
|
|
79
|
+
1. 遵守相关法律法规和富途OpenAPI的使用条款
|
|
80
|
+
2. 自行承担使用本项目进行交易的风险
|
|
81
|
+
3. 本项目不提供任何投资建议
|
|
82
|
+
4. 使用本项目前请确保您已获得所需的行情权限
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
- Standard MCP 2.0 protocol compliance
|
|
87
|
+
- Comprehensive Futu API coverage
|
|
88
|
+
- Real-time data subscription support
|
|
89
|
+
- Market data access
|
|
90
|
+
- Derivatives information
|
|
91
|
+
- Account query capabilities
|
|
92
|
+
- Resource-based data access
|
|
93
|
+
- Interactive prompts for analysis
|
|
94
|
+
|
|
95
|
+
## Prerequisites
|
|
96
|
+
|
|
97
|
+
- Python 3.10+
|
|
98
|
+
- Futu OpenAPI SDK
|
|
99
|
+
- Model Context Protocol SDK
|
|
100
|
+
- uv (recommended)
|
|
101
|
+
|
|
102
|
+
## 🚀 快速开始
|
|
103
|
+
|
|
104
|
+
### 方式一:通过 PyPI 安装(推荐)
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# 安装包
|
|
108
|
+
pip install futu-stock-mcp-server
|
|
109
|
+
|
|
110
|
+
# 运行服务器
|
|
111
|
+
futu-mcp-server
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 方式二:通过 Docker 运行
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
# 拉取镜像
|
|
118
|
+
docker pull your-registry/futu-stock-mcp-server:latest
|
|
119
|
+
|
|
120
|
+
# 运行容器
|
|
121
|
+
docker run -d \
|
|
122
|
+
--name futu-mcp-server \
|
|
123
|
+
-p 8000:8000 \
|
|
124
|
+
-e FUTU_HOST=127.0.0.1 \
|
|
125
|
+
-e FUTU_PORT=11111 \
|
|
126
|
+
your-registry/futu-stock-mcp-server:latest
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 方式三:从源码安装
|
|
130
|
+
|
|
131
|
+
1. Clone the repository:
|
|
132
|
+
```bash
|
|
133
|
+
git clone https://github.com/yourusername/futu-stock-mcp-server.git
|
|
134
|
+
cd futu-stock-mcp-server
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
2. Install uv:
|
|
138
|
+
```bash
|
|
139
|
+
# macOS/Linux
|
|
140
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
141
|
+
|
|
142
|
+
# Windows (PowerShell)
|
|
143
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
3. Create and activate a virtual environment:
|
|
147
|
+
```bash
|
|
148
|
+
# Create virtual environment
|
|
149
|
+
uv venv
|
|
150
|
+
|
|
151
|
+
# Activate virtual environment
|
|
152
|
+
# On macOS/Linux:
|
|
153
|
+
source .venv/bin/activate
|
|
154
|
+
# On Windows:
|
|
155
|
+
.venv\Scripts\activate
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
4. Install dependencies:
|
|
159
|
+
```bash
|
|
160
|
+
# Install in editable mode
|
|
161
|
+
uv pip install -e .
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
5. Copy the environment file and configure:
|
|
165
|
+
```bash
|
|
166
|
+
cp .env.example .env
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Edit the `.env` file with your server settings:
|
|
170
|
+
```
|
|
171
|
+
HOST=0.0.0.0
|
|
172
|
+
PORT=8000
|
|
173
|
+
FUTU_HOST=127.0.0.1
|
|
174
|
+
FUTU_PORT=11111
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Development
|
|
178
|
+
|
|
179
|
+
### Managing Dependencies
|
|
180
|
+
|
|
181
|
+
Add new dependencies to `pyproject.toml`:
|
|
182
|
+
```toml
|
|
183
|
+
[project]
|
|
184
|
+
dependencies = [
|
|
185
|
+
# ... existing dependencies ...
|
|
186
|
+
"new-package>=1.0.0",
|
|
187
|
+
]
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Then update your environment:
|
|
191
|
+
```bash
|
|
192
|
+
uv pip install -e .
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Code Style
|
|
196
|
+
|
|
197
|
+
This project uses Ruff for code linting and formatting. The configuration is in `pyproject.toml`:
|
|
198
|
+
|
|
199
|
+
```toml
|
|
200
|
+
[tool.ruff]
|
|
201
|
+
line-length = 100
|
|
202
|
+
target-version = "py38"
|
|
203
|
+
|
|
204
|
+
[tool.ruff.lint]
|
|
205
|
+
select = ["E", "F", "I", "N", "W", "B", "UP"]
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Run linting:
|
|
209
|
+
```bash
|
|
210
|
+
uv pip install ruff
|
|
211
|
+
ruff check .
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Run formatting:
|
|
215
|
+
```bash
|
|
216
|
+
ruff format .
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Usage
|
|
220
|
+
|
|
221
|
+
1. Start the server:
|
|
222
|
+
```bash
|
|
223
|
+
python -m futu_stock_mcp_server.server
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
2. Connect to the server using an MCP client:
|
|
227
|
+
```python
|
|
228
|
+
from mcp import ClientSession, StdioServerParameters
|
|
229
|
+
from mcp.client.stdio import stdio_client
|
|
230
|
+
|
|
231
|
+
async def main():
|
|
232
|
+
server_params = StdioServerParameters(
|
|
233
|
+
command="python",
|
|
234
|
+
args=["src/server.py"]
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
async with stdio_client(server_params) as (read, write):
|
|
238
|
+
async with ClientSession(read, write) as session:
|
|
239
|
+
# Initialize the connection
|
|
240
|
+
await session.initialize()
|
|
241
|
+
|
|
242
|
+
# List available tools
|
|
243
|
+
tools = await session.list_tools()
|
|
244
|
+
|
|
245
|
+
# Call a tool
|
|
246
|
+
result = await session.call_tool(
|
|
247
|
+
"get_stock_quote",
|
|
248
|
+
arguments={"symbols": ["HK.00700"]}
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
# Access a resource
|
|
252
|
+
content, mime_type = await session.read_resource(
|
|
253
|
+
"market://HK.00700"
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# Get a prompt
|
|
257
|
+
prompt = await session.get_prompt(
|
|
258
|
+
"market_analysis",
|
|
259
|
+
arguments={"symbol": "HK.00700"}
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
if __name__ == "__main__":
|
|
263
|
+
import asyncio
|
|
264
|
+
asyncio.run(main())
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Available API Methods
|
|
268
|
+
|
|
269
|
+
### Market Data Tools
|
|
270
|
+
- `get_stock_quote`: Get stock quote data
|
|
271
|
+
- `get_market_snapshot`: Get market snapshot
|
|
272
|
+
- `get_cur_kline`: Get current K-line data
|
|
273
|
+
- `get_history_kline`: Get historical K-line data
|
|
274
|
+
- `get_rt_data`: Get real-time data
|
|
275
|
+
- `get_ticker`: Get ticker data
|
|
276
|
+
- `get_order_book`: Get order book data
|
|
277
|
+
- `get_broker_queue`: Get broker queue data
|
|
278
|
+
|
|
279
|
+
### Subscription Tools
|
|
280
|
+
- `subscribe`: Subscribe to real-time data
|
|
281
|
+
- `unsubscribe`: Unsubscribe from real-time data
|
|
282
|
+
|
|
283
|
+
### Derivatives Tools
|
|
284
|
+
- `get_option_chain`: Get option chain data
|
|
285
|
+
- `get_option_expiration_date`: Get option expiration dates
|
|
286
|
+
- `get_option_condor`: Get option condor strategy data
|
|
287
|
+
- `get_option_butterfly`: Get option butterfly strategy data
|
|
288
|
+
|
|
289
|
+
### Account Query Tools
|
|
290
|
+
- `get_account_list`: Get account list
|
|
291
|
+
- `get_asset_info`: Get asset information
|
|
292
|
+
- `get_asset_allocation`: Get asset allocation information
|
|
293
|
+
|
|
294
|
+
### Market Information Tools
|
|
295
|
+
- `get_market_state`: Get market state
|
|
296
|
+
- `get_security_info`: Get security information
|
|
297
|
+
- `get_security_list`: Get security list
|
|
298
|
+
|
|
299
|
+
### Stock Filter Commands
|
|
300
|
+
|
|
301
|
+
#### get_stock_filter
|
|
302
|
+
Filter stocks based on various conditions.
|
|
303
|
+
|
|
304
|
+
Parameters:
|
|
305
|
+
- `base_filters` (optional): List of basic stock filters
|
|
306
|
+
```python
|
|
307
|
+
{
|
|
308
|
+
"field_name": int, # StockField enum value
|
|
309
|
+
"filter_min": float, # Optional minimum value
|
|
310
|
+
"filter_max": float, # Optional maximum value
|
|
311
|
+
"is_no_filter": bool, # Optional, whether to skip filtering
|
|
312
|
+
"sort_dir": int # Optional, sort direction
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
- `accumulate_filters` (optional): List of accumulate filters
|
|
316
|
+
```python
|
|
317
|
+
{
|
|
318
|
+
"field_name": int, # AccumulateField enum value
|
|
319
|
+
"filter_min": float,
|
|
320
|
+
"filter_max": float,
|
|
321
|
+
"is_no_filter": bool,
|
|
322
|
+
"sort_dir": int,
|
|
323
|
+
"days": int # Required, number of days to accumulate
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
- `financial_filters` (optional): List of financial filters
|
|
327
|
+
```python
|
|
328
|
+
{
|
|
329
|
+
"field_name": int, # FinancialField enum value
|
|
330
|
+
"filter_min": float,
|
|
331
|
+
"filter_max": float,
|
|
332
|
+
"is_no_filter": bool,
|
|
333
|
+
"sort_dir": int,
|
|
334
|
+
"quarter": int # Required, financial quarter
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
- `market` (optional): Market code (e.g. "HK.Motherboard", "US.NASDAQ")
|
|
338
|
+
- `page` (optional): Page number, starting from 1 (default: 1)
|
|
339
|
+
- `page_size` (optional): Number of results per page, max 200 (default: 200)
|
|
340
|
+
|
|
341
|
+
Supported Market Codes:
|
|
342
|
+
- `HK.Motherboard`: Hong Kong Main Board
|
|
343
|
+
- `HK.GEM`: Hong Kong GEM
|
|
344
|
+
- `HK.BK1911`: H-Share Main Board
|
|
345
|
+
- `HK.BK1912`: H-Share GEM
|
|
346
|
+
- `US.NYSE`: NYSE
|
|
347
|
+
- `US.AMEX`: AMEX
|
|
348
|
+
- `US.NASDAQ`: NASDAQ
|
|
349
|
+
- `SH.3000000`: Shanghai Main Board
|
|
350
|
+
- `SZ.3000001`: Shenzhen Main Board
|
|
351
|
+
- `SZ.3000004`: Shenzhen ChiNext
|
|
352
|
+
|
|
353
|
+
Example:
|
|
354
|
+
```python
|
|
355
|
+
# Get stocks with price between 10 and 50 HKD in Hong Kong Main Board
|
|
356
|
+
filters = {
|
|
357
|
+
"base_filters": [{
|
|
358
|
+
"field_name": 5, # Current price
|
|
359
|
+
"filter_min": 10.0,
|
|
360
|
+
"filter_max": 50.0
|
|
361
|
+
}],
|
|
362
|
+
"market": "HK.Motherboard"
|
|
363
|
+
}
|
|
364
|
+
result = await client.get_stock_filter(**filters)
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Notes:
|
|
368
|
+
- Limited to 10 requests per 30 seconds
|
|
369
|
+
- Each page returns maximum 200 results
|
|
370
|
+
- Recommended to use no more than 250 filter conditions
|
|
371
|
+
- Maximum 10 accumulate conditions of the same type
|
|
372
|
+
- Dynamic data sorting (like current price) may change between pages
|
|
373
|
+
- Cannot compare different types of indicators (e.g. MA5 vs EMA10)
|
|
374
|
+
|
|
375
|
+
## Resources
|
|
376
|
+
|
|
377
|
+
### Market Data
|
|
378
|
+
- `market://{symbol}`: Get market data for a symbol
|
|
379
|
+
- `kline://{symbol}/{ktype}`: Get K-line data for a symbol
|
|
380
|
+
|
|
381
|
+
## Prompts
|
|
382
|
+
|
|
383
|
+
### Analysis
|
|
384
|
+
- `market_analysis`: Create a market analysis prompt
|
|
385
|
+
- `option_strategy`: Create an option strategy analysis prompt
|
|
386
|
+
|
|
387
|
+
## Error Handling
|
|
388
|
+
|
|
389
|
+
The server follows the MCP 2.0 error response format:
|
|
390
|
+
|
|
391
|
+
```json
|
|
392
|
+
{
|
|
393
|
+
"jsonrpc": "2.0",
|
|
394
|
+
"id": "request_id",
|
|
395
|
+
"error": {
|
|
396
|
+
"code": -32000,
|
|
397
|
+
"message": "Error message",
|
|
398
|
+
"data": null
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Security
|
|
404
|
+
|
|
405
|
+
- The server uses secure WebSocket connections
|
|
406
|
+
- All API calls are authenticated through the Futu OpenAPI
|
|
407
|
+
- Environment variables are used for sensitive configuration
|
|
408
|
+
|
|
409
|
+
## Development
|
|
410
|
+
|
|
411
|
+
### Adding New Tools
|
|
412
|
+
|
|
413
|
+
To add a new tool, use the `@mcp.tool()` decorator:
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
@mcp.tool()
|
|
417
|
+
async def new_tool(param1: str, param2: int) -> Dict[str, Any]:
|
|
418
|
+
"""Tool description"""
|
|
419
|
+
# Implementation
|
|
420
|
+
return result
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Adding New Resources
|
|
424
|
+
|
|
425
|
+
To add a new resource, use the `@mcp.resource()` decorator:
|
|
426
|
+
|
|
427
|
+
```python
|
|
428
|
+
@mcp.resource("resource://{param1}/{param2}")
|
|
429
|
+
async def new_resource(param1: str, param2: str) -> Dict[str, Any]:
|
|
430
|
+
"""Resource description"""
|
|
431
|
+
# Implementation
|
|
432
|
+
return result
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### Adding New Prompts
|
|
436
|
+
|
|
437
|
+
To add a new prompt, use the `@mcp.prompt()` decorator:
|
|
438
|
+
|
|
439
|
+
```python
|
|
440
|
+
@mcp.prompt()
|
|
441
|
+
async def new_prompt(param1: str) -> str:
|
|
442
|
+
"""Prompt description"""
|
|
443
|
+
return f"Prompt template with {param1}"
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
## License
|
|
447
|
+
|
|
448
|
+
MIT License
|
|
449
|
+
|
|
450
|
+
## Available MCP Functions
|
|
451
|
+
|
|
452
|
+
### Market Data Functions
|
|
453
|
+
|
|
454
|
+
#### get_stock_quote
|
|
455
|
+
Get stock quote data for given symbols.
|
|
456
|
+
```python
|
|
457
|
+
symbols = ["HK.00700", "US.AAPL", "SH.600519"]
|
|
458
|
+
result = await session.call_tool("get_stock_quote", {"symbols": symbols})
|
|
459
|
+
```
|
|
460
|
+
Returns quote data including price, volume, turnover, etc.
|
|
461
|
+
|
|
462
|
+
#### get_market_snapshot
|
|
463
|
+
Get market snapshot for given symbols.
|
|
464
|
+
```python
|
|
465
|
+
symbols = ["HK.00700", "US.AAPL", "SH.600519"]
|
|
466
|
+
result = await session.call_tool("get_market_snapshot", {"symbols": symbols})
|
|
467
|
+
```
|
|
468
|
+
Returns comprehensive market data including price, volume, bid/ask prices, etc.
|
|
469
|
+
|
|
470
|
+
#### get_cur_kline
|
|
471
|
+
Get current K-line data.
|
|
472
|
+
```python
|
|
473
|
+
result = await session.call_tool("get_cur_kline", {
|
|
474
|
+
"symbol": "HK.00700",
|
|
475
|
+
"ktype": "K_1M", # K_1M, K_5M, K_15M, K_30M, K_60M, K_DAY, K_WEEK, K_MON
|
|
476
|
+
"count": 100
|
|
477
|
+
})
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
#### get_history_kline
|
|
481
|
+
Get historical K-line data.
|
|
482
|
+
```python
|
|
483
|
+
result = await session.call_tool("get_history_kline", {
|
|
484
|
+
"symbol": "HK.00700",
|
|
485
|
+
"ktype": "K_DAY",
|
|
486
|
+
"start": "2024-01-01",
|
|
487
|
+
"end": "2024-03-31"
|
|
488
|
+
})
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
#### get_rt_data
|
|
492
|
+
Get real-time trading data.
|
|
493
|
+
```python
|
|
494
|
+
result = await session.call_tool("get_rt_data", {"symbol": "HK.00700"})
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### get_ticker
|
|
498
|
+
Get ticker data (detailed trades).
|
|
499
|
+
```python
|
|
500
|
+
result = await session.call_tool("get_ticker", {"symbol": "HK.00700"})
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### get_order_book
|
|
504
|
+
Get order book data.
|
|
505
|
+
```python
|
|
506
|
+
result = await session.call_tool("get_order_book", {"symbol": "HK.00700"})
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
#### get_broker_queue
|
|
510
|
+
Get broker queue data.
|
|
511
|
+
```python
|
|
512
|
+
result = await session.call_tool("get_broker_queue", {"symbol": "HK.00700"})
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
### Subscription Functions
|
|
516
|
+
|
|
517
|
+
#### subscribe
|
|
518
|
+
Subscribe to real-time data.
|
|
519
|
+
```python
|
|
520
|
+
result = await session.call_tool("subscribe", {
|
|
521
|
+
"symbols": ["HK.00700", "US.AAPL"],
|
|
522
|
+
"sub_types": ["QUOTE", "TICKER", "K_1M"]
|
|
523
|
+
})
|
|
524
|
+
```
|
|
525
|
+
Subscription types:
|
|
526
|
+
- "QUOTE": Basic quote
|
|
527
|
+
- "ORDER_BOOK": Order book
|
|
528
|
+
- "TICKER": Trades
|
|
529
|
+
- "RT_DATA": Real-time data
|
|
530
|
+
- "BROKER": Broker queue
|
|
531
|
+
- "K_1M" to "K_MON": K-line data
|
|
532
|
+
|
|
533
|
+
#### unsubscribe
|
|
534
|
+
Unsubscribe from real-time data.
|
|
535
|
+
```python
|
|
536
|
+
result = await session.call_tool("unsubscribe", {
|
|
537
|
+
"symbols": ["HK.00700", "US.AAPL"],
|
|
538
|
+
"sub_types": ["QUOTE", "TICKER"]
|
|
539
|
+
})
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### Options Functions
|
|
543
|
+
|
|
544
|
+
#### get_option_chain
|
|
545
|
+
Get option chain data.
|
|
546
|
+
```python
|
|
547
|
+
result = await session.call_tool("get_option_chain", {
|
|
548
|
+
"symbol": "HK.00700",
|
|
549
|
+
"start": "2024-04-01",
|
|
550
|
+
"end": "2024-06-30"
|
|
551
|
+
})
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
#### get_option_expiration_date
|
|
555
|
+
Get option expiration dates.
|
|
556
|
+
```python
|
|
557
|
+
result = await session.call_tool("get_option_expiration_date", {
|
|
558
|
+
"symbol": "HK.00700"
|
|
559
|
+
})
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
#### get_option_condor
|
|
563
|
+
Get option condor strategy data.
|
|
564
|
+
```python
|
|
565
|
+
result = await session.call_tool("get_option_condor", {
|
|
566
|
+
"symbol": "HK.00700",
|
|
567
|
+
"expiry": "2024-06-30",
|
|
568
|
+
"strike_price": 350.0
|
|
569
|
+
})
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
#### get_option_butterfly
|
|
573
|
+
Get option butterfly strategy data.
|
|
574
|
+
```python
|
|
575
|
+
result = await session.call_tool("get_option_butterfly", {
|
|
576
|
+
"symbol": "HK.00700",
|
|
577
|
+
"expiry": "2024-06-30",
|
|
578
|
+
"strike_price": 350.0
|
|
579
|
+
})
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
### Account Functions
|
|
583
|
+
|
|
584
|
+
#### get_account_list
|
|
585
|
+
Get account list.
|
|
586
|
+
```python
|
|
587
|
+
result = await session.call_tool("get_account_list", {"random_string": "dummy"})
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
#### get_funds
|
|
591
|
+
Get account funds information.
|
|
592
|
+
```python
|
|
593
|
+
result = await session.call_tool("get_funds", {"random_string": "dummy"})
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
#### get_positions
|
|
597
|
+
Get account positions.
|
|
598
|
+
```python
|
|
599
|
+
result = await session.call_tool("get_positions", {"random_string": "dummy"})
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
#### get_max_power
|
|
603
|
+
Get maximum trading power.
|
|
604
|
+
```python
|
|
605
|
+
result = await session.call_tool("get_max_power", {"random_string": "dummy"})
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
#### get_margin_ratio
|
|
609
|
+
Get margin ratio for a security.
|
|
610
|
+
```python
|
|
611
|
+
result = await session.call_tool("get_margin_ratio", {"symbol": "HK.00700"})
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Market Information Functions
|
|
615
|
+
|
|
616
|
+
#### get_market_state
|
|
617
|
+
Get market state.
|
|
618
|
+
```python
|
|
619
|
+
result = await session.call_tool("get_market_state", {"market": "HK"})
|
|
620
|
+
```
|
|
621
|
+
Available markets: "HK", "US", "SH", "SZ"
|
|
622
|
+
|
|
623
|
+
#### get_security_info
|
|
624
|
+
Get security information.
|
|
625
|
+
```python
|
|
626
|
+
result = await session.call_tool("get_security_info", {
|
|
627
|
+
"market": "HK",
|
|
628
|
+
"code": "00700"
|
|
629
|
+
})
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
#### get_security_list
|
|
633
|
+
Get security list for a market.
|
|
634
|
+
```python
|
|
635
|
+
result = await session.call_tool("get_security_list", {"market": "HK"})
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
#### get_stock_filter
|
|
639
|
+
Get filtered stock list based on conditions.
|
|
640
|
+
```python
|
|
641
|
+
result = await session.call_tool("get_stock_filter", {
|
|
642
|
+
"market": "HK.Motherboard",
|
|
643
|
+
"base_filters": [{
|
|
644
|
+
"field_name": 1, # Price
|
|
645
|
+
"filter_min": 10.0,
|
|
646
|
+
"filter_max": 50.0,
|
|
647
|
+
"sort_dir": 1 # Ascending
|
|
648
|
+
}],
|
|
649
|
+
"page": 1,
|
|
650
|
+
"page_size": 50
|
|
651
|
+
})
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### Time Function
|
|
655
|
+
|
|
656
|
+
#### get_current_time
|
|
657
|
+
Get current server time.
|
|
658
|
+
```python
|
|
659
|
+
result = await session.call_tool("get_current_time", {"random_string": "dummy"})
|
|
660
|
+
```
|
|
661
|
+
Returns timestamp, formatted datetime, date, time and timezone.
|