coinex-mcp-server 0.1.0a1__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 coinex-mcp-server might be problematic. Click here for more details.
- coinex_mcp_server-0.1.0a1/.env.example +9 -0
- coinex_mcp_server-0.1.0a1/CLAUDE.md +114 -0
- coinex_mcp_server-0.1.0a1/LICENSE +201 -0
- coinex_mcp_server-0.1.0a1/MANIFEST.in +23 -0
- coinex_mcp_server-0.1.0a1/PKG-INFO +237 -0
- coinex_mcp_server-0.1.0a1/README.md +204 -0
- coinex_mcp_server-0.1.0a1/README_cn.md +202 -0
- coinex_mcp_server-0.1.0a1/pyproject.toml +72 -0
- coinex_mcp_server-0.1.0a1/setup.cfg +4 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server/__init__.py +13 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server/coinex_client.py +393 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server/main.py +637 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server.egg-info/PKG-INFO +237 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server.egg-info/SOURCES.txt +15 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server.egg-info/dependency_links.txt +1 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server.egg-info/requires.txt +4 -0
- coinex_mcp_server-0.1.0a1/src/coinex_mcp_server.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# CoinEx API Credentials
|
|
2
|
+
# Get your API credentials from: https://www.coinex.com/
|
|
3
|
+
COINEX_ACCESS_ID=your_access_id_here
|
|
4
|
+
COINEX_SECRET_KEY=your_secret_key_here
|
|
5
|
+
|
|
6
|
+
# Optional: HTTP Authentication Settings
|
|
7
|
+
# HTTP_AUTH_ENABLED=true
|
|
8
|
+
# API_TOKEN=your_bearer_token_here
|
|
9
|
+
# API_SCOPES=read,write
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
|
|
7
|
+
这是一个 CoinEx MCP (Model Context Protocol) 服务器,允许 AI 代理与 CoinEx 加密货币交易所交互。该项目使用 FastMCP 框架构建,支持现货和期货市场的数据查询与交易操作。
|
|
8
|
+
|
|
9
|
+
## 核心架构
|
|
10
|
+
|
|
11
|
+
### 主要组件
|
|
12
|
+
- `main.py` - MCP 服务器入口点,定义所有工具和传输配置
|
|
13
|
+
- `coinex_client.py` - CoinEx API 客户端,统一封装现货/期货 API 调用
|
|
14
|
+
- `bench/test_public_methods.py` - 公开接口测试脚本
|
|
15
|
+
- `deploy/` - Nginx 和 Supervisor 部署配置
|
|
16
|
+
|
|
17
|
+
### 技术栈
|
|
18
|
+
- **FastMCP 2.x** - MCP 服务器框架
|
|
19
|
+
- **httpx** - HTTP 客户端
|
|
20
|
+
- **pydantic** - 数据验证
|
|
21
|
+
- **python-dotenv** - 环境变量管理
|
|
22
|
+
|
|
23
|
+
## 开发命令
|
|
24
|
+
|
|
25
|
+
### 安装依赖
|
|
26
|
+
```bash
|
|
27
|
+
uv sync
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 运行服务器
|
|
31
|
+
```bash
|
|
32
|
+
# 默认 stdio 模式
|
|
33
|
+
python main.py
|
|
34
|
+
|
|
35
|
+
# HTTP 模式
|
|
36
|
+
python main.py --transport http --host 0.0.0.0 --port 8000 --enable-http-auth
|
|
37
|
+
|
|
38
|
+
# 查看帮助
|
|
39
|
+
python main.py --help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 测试公开接口
|
|
43
|
+
```bash
|
|
44
|
+
cd tests
|
|
45
|
+
pytest test_public_methods.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 开发工具
|
|
49
|
+
```bash
|
|
50
|
+
# 代码格式化
|
|
51
|
+
black .
|
|
52
|
+
|
|
53
|
+
# 类型检查
|
|
54
|
+
mypy main.py coinex_client.py
|
|
55
|
+
|
|
56
|
+
# 运行测试
|
|
57
|
+
pytest
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 关键设计模式
|
|
61
|
+
|
|
62
|
+
### 认证处理
|
|
63
|
+
- **stdio 模式**: 从环境变量读取 API 凭据
|
|
64
|
+
- **HTTP/SSE 模式**: 通过请求头传递凭据 (`X-CoinEx-Access-Id`, `X-CoinEx-Secret-Key`)
|
|
65
|
+
- 使用 `get_secret_client_from_request()` 动态创建客户端实例
|
|
66
|
+
|
|
67
|
+
### 工具标签系统
|
|
68
|
+
- `tags={"public"}`: 公开市场数据查询,无需认证
|
|
69
|
+
- `tags={"auth"}`: 账户和交易功能,需要 API 凭据
|
|
70
|
+
- HTTP 模式默认只暴露 public 工具,需 `--enable-http-auth` 启用 auth 工具
|
|
71
|
+
|
|
72
|
+
### 参数标准化
|
|
73
|
+
- `symbol`: 支持 `BTCUSDT`/`BTC/USDT`/`btc` 格式,自动规范化
|
|
74
|
+
- `market_type`: `"spot"`(默认) 或 `"futures"`
|
|
75
|
+
- `period`: K线周期,有白名单验证
|
|
76
|
+
|
|
77
|
+
### 错误处理
|
|
78
|
+
- 所有 API 调用返回统一格式: `{code: int, message: str, data: any}`
|
|
79
|
+
- 错误情况记录日志但不抛异常,返回原始 API 响应
|
|
80
|
+
|
|
81
|
+
## 环境配置
|
|
82
|
+
|
|
83
|
+
### 必需的环境变量
|
|
84
|
+
```bash
|
|
85
|
+
# API 凭据 (stdio 模式)
|
|
86
|
+
COINEX_ACCESS_ID=your_access_id
|
|
87
|
+
COINEX_SECRET_KEY=your_secret_key
|
|
88
|
+
|
|
89
|
+
# 可选配置
|
|
90
|
+
HTTP_AUTH_ENABLED=true # 启用 HTTP 认证
|
|
91
|
+
API_TOKEN=bearer_token # Bearer 令牌保护
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 配置文件
|
|
95
|
+
- `.env` - 本地开发环境变量
|
|
96
|
+
- `deploy/nginx/coinex_mcp.conf` - Nginx 反向代理配置
|
|
97
|
+
- `deploy/supervisor/coinex_mcp.conf` - Supervisor 进程管理
|
|
98
|
+
|
|
99
|
+
## 部署注意事项
|
|
100
|
+
|
|
101
|
+
1. **安全**: HTTP 模式下的凭据传递仅适用于内网环境
|
|
102
|
+
2. **HTTPS**: 生产环境必须使用 HTTPS 保护 API 凭据
|
|
103
|
+
3. **日志**: 确保反向代理不记录敏感头信息
|
|
104
|
+
4. **工作进程**: 可通过 `--workers` 参数配置多进程
|
|
105
|
+
|
|
106
|
+
## 开发约定
|
|
107
|
+
|
|
108
|
+
- 使用 f-string 进行字符串格式化
|
|
109
|
+
- API 方法使用 async/await 模式
|
|
110
|
+
- 工具函数遵循 FastMCP 装饰器规范
|
|
111
|
+
- 错误处理优先返回结构化响应而非抛异常
|
|
112
|
+
|
|
113
|
+
## 输出
|
|
114
|
+
- 项目文档和注释都用英文,但问答的时候,请使用中文描述
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Include documentation files
|
|
2
|
+
include README.md
|
|
3
|
+
include README_cn.md
|
|
4
|
+
include LICENSE
|
|
5
|
+
include CLAUDE.md
|
|
6
|
+
|
|
7
|
+
# Include configuration examples
|
|
8
|
+
include .env.example
|
|
9
|
+
|
|
10
|
+
# Exclude development and build files
|
|
11
|
+
global-exclude __pycache__
|
|
12
|
+
global-exclude *.py[co]
|
|
13
|
+
global-exclude .DS_Store
|
|
14
|
+
global-exclude *.so
|
|
15
|
+
global-exclude *.dylib
|
|
16
|
+
|
|
17
|
+
# Exclude test and development directories
|
|
18
|
+
prune tests
|
|
19
|
+
prune .git
|
|
20
|
+
prune .idea
|
|
21
|
+
prune .pytest_cache
|
|
22
|
+
prune .venv
|
|
23
|
+
prune deploy
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coinex-mcp-server
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: A CoinEx MCP (Model Context Protocol) server that enables AI agents to interact with the CoinEx cryptocurrency exchange
|
|
5
|
+
Author: CoinEx MCP Contributors
|
|
6
|
+
Maintainer: CoinEx MCP Contributors
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
Project-URL: Homepage, https://github.com/yourusername/coinex_mcp_server
|
|
9
|
+
Project-URL: Repository, https://github.com/yourusername/coinex_mcp_server
|
|
10
|
+
Project-URL: Documentation, https://github.com/yourusername/coinex_mcp_server#readme
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/yourusername/coinex_mcp_server/issues
|
|
12
|
+
Keywords: coinex,mcp,model-context-protocol,cryptocurrency,exchange,trading,api,fastmcp,ai-agent
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
21
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
23
|
+
Classifier: Framework :: AsyncIO
|
|
24
|
+
Classifier: Environment :: Console
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: httpx>=0.28.1
|
|
29
|
+
Requires-Dist: fastmcp==2.12.4
|
|
30
|
+
Requires-Dist: python-dotenv>=1.1.1
|
|
31
|
+
Requires-Dist: pydantic>=2.7.0
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# CoinEx MCP Server
|
|
35
|
+
|
|
36
|
+
[中文版本](README_cn.md) | English
|
|
37
|
+
|
|
38
|
+
A CoinEx MCP (Model Context Protocol) server that enables AI agents to interact with the CoinEx cryptocurrency exchange.
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- 🔍 Retrieve market data (spot/futures with unified parameters)
|
|
43
|
+
- 💰 Query account balances (authentication required)
|
|
44
|
+
- 📊 Get K-line data (spot/futures)
|
|
45
|
+
- 📈 View order book depth (spot/futures)
|
|
46
|
+
- 💹 Place orders (authentication required)
|
|
47
|
+
- 📋 Query order history (authentication required)
|
|
48
|
+
- 📜 Futures-specific: funding rates, premium/basis history, margin tiers, liquidation history, etc.
|
|
49
|
+
|
|
50
|
+
## Installation & Configuration
|
|
51
|
+
|
|
52
|
+
### 1. Install Dependencies
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
uv sync
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Configure API Credentials
|
|
59
|
+
|
|
60
|
+
In the default stdio mode, API credentials are obtained through environment variables, but typically MCP servers are not launched directly from the command line. You can configure credentials in two ways:
|
|
61
|
+
|
|
62
|
+
#### 2.1 MCP Client Configuration
|
|
63
|
+
Through MCP clients like Claude Desktop, CherryStudio, or mcp inspector.
|
|
64
|
+
|
|
65
|
+
#### 2.2 Local File Configuration
|
|
66
|
+
1. Copy the environment variable template file:
|
|
67
|
+
```bash
|
|
68
|
+
cp .env.example .env
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
2. Edit the `.env` file and fill in your CoinEx API credentials:
|
|
72
|
+
```env
|
|
73
|
+
COINEX_ACCESS_ID=your_access_id_here
|
|
74
|
+
COINEX_SECRET_KEY=your_secret_key_here
|
|
75
|
+
```
|
|
76
|
+
_Note: In SSE or Streamable HTTP mode, environment variable credentials will be ignored._
|
|
77
|
+
|
|
78
|
+
### 3. Obtain CoinEx API Credentials
|
|
79
|
+
|
|
80
|
+
1. Log in to [CoinEx Official Website](https://www.coinex.com/)
|
|
81
|
+
2. Go to **User Center** -> **API Management**
|
|
82
|
+
3. Create a new API Key
|
|
83
|
+
4. Copy the Access ID and Secret Key to your `.env` file
|
|
84
|
+
|
|
85
|
+
⚠️ **Security Notice**:
|
|
86
|
+
- Keep your API credentials safe and do not share them with others
|
|
87
|
+
- Set appropriate permissions for your API Key, only enabling necessary functions
|
|
88
|
+
- Do not commit the `.env` file to version control systems
|
|
89
|
+
|
|
90
|
+
## Usage
|
|
91
|
+
|
|
92
|
+
### Start the Server
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
python -m coinex_mcp_server.main
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Command Line Arguments & Examples
|
|
99
|
+
|
|
100
|
+
The server supports command line arguments for switching transport protocols and network configuration:
|
|
101
|
+
|
|
102
|
+
- `--transport`: Transport protocol, options: `stdio` (default) | `http` (equivalent to `streamable-http`) | `streamable-http` | `sse`
|
|
103
|
+
- `--host`: HTTP service bind address (only valid for http/streamable-http mode)
|
|
104
|
+
- `--port`: HTTP service port (only valid for http/streamable-http mode)
|
|
105
|
+
- `--path`: Endpoint path
|
|
106
|
+
- http/streamable-http mode: MCP endpoint path (default `/mcp`)
|
|
107
|
+
- sse mode: SSE mount path
|
|
108
|
+
- `--enable-http-auth`: Enable HTTP-based authentication and sensitive tools (disabled by default, only exposes query tools)
|
|
109
|
+
- `--workers`: Number of worker processes for HTTP/SSE mode (managed by underlying uvicorn)
|
|
110
|
+
|
|
111
|
+
#### View Help:
|
|
112
|
+
```bash
|
|
113
|
+
python -m coinex_mcp_server.main --help
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Default stdio Service Start
|
|
117
|
+
(Usually no manual start needed, configure startup file and parameters in agent)
|
|
118
|
+
```bash
|
|
119
|
+
python -m coinex_mcp_server.main
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Start HTTP Service
|
|
123
|
+
```bash
|
|
124
|
+
python -m coinex_mcp_server.main --transport http --host 0.0.0.0 --port 8000 --path /mcp --workers 2
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Note: If using HTTP GET method to directly access the `/mcp` endpoint, it may return `406 Not Acceptable`, which is normal—Streamable HTTP endpoints require protocol-compliant interaction flows; this return code also proves the HTTP service has started and is responding.
|
|
128
|
+
|
|
129
|
+
### Pass CoinEx Credentials via HTTP Headers (HTTP Mode)
|
|
130
|
+
The server does not store third-party exchange credentials. For tools requiring authentication (balance/place order/cancel order/order history), include the following headers in HTTP requests (case-insensitive):
|
|
131
|
+
- `X-CoinEx-Access-Id: <your CoinEx Access ID>`
|
|
132
|
+
- `X-CoinEx-Secret-Key: <your CoinEx Secret Key>`
|
|
133
|
+
|
|
134
|
+
**Important Notes**
|
|
135
|
+
- **Never** enable credential pass-through functionality in publicly exposed services; ensure the entire server backend is controlled within an internal network! (Even with HTTPS transport, reverse proxies and other server nodes may offload request headers and log them)
|
|
136
|
+
- Deploy via HTTPS to prevent man-in-the-middle eavesdropping (use reverse proxy/Nginx/Caddy to add TLS to MCP endpoints).
|
|
137
|
+
- These headers are only needed when "HTTP authentication is enabled" and you're calling tools that require user credentials (auth tag).
|
|
138
|
+
- Enable with: `--enable-http-auth` or set environment variable `HTTP_AUTH_ENABLED=true`
|
|
139
|
+
- By default, HTTP authentication is disabled, exposing only query tools (public), which don't need or read the above headers.
|
|
140
|
+
- Only valid for HTTP/Streamable HTTP mode; STDIO mode reads credentials from environment variables (or .env config file).
|
|
141
|
+
|
|
142
|
+
### Logging & Security
|
|
143
|
+
- Ensure reverse proxies/APM/logging systems don't record sensitive headers like `Authorization` or `X-CoinEx-*`.
|
|
144
|
+
|
|
145
|
+
## Tools Overview
|
|
146
|
+
|
|
147
|
+
Note: In HTTP mode, only `public` type tools are exposed by default; `auth` type tools require enabling `--enable-http-auth` or setting `HTTP_AUTH_ENABLED=true` to be available.
|
|
148
|
+
|
|
149
|
+
### Standard Parameter Conventions:
|
|
150
|
+
- `market_type`: Default `"spot"`, use `"futures"` for contracts.
|
|
151
|
+
- `symbol`: Supports `BTCUSDT` / `BTC/USDT` / `btc` / `BTC` (defaults to `USDT` if no quote currency).
|
|
152
|
+
- `interval` (depth aggregation levels): Default `"0"`.
|
|
153
|
+
- `period`: Default `"1hour"`, validated against spot/futures whitelists.
|
|
154
|
+
- `start_time`/`end_time`: Millisecond timestamps.
|
|
155
|
+
|
|
156
|
+
### Market Data (public)
|
|
157
|
+
* `list_markets(market_type="spot"|"futures", symbols: str|list[str]|None)`
|
|
158
|
+
- Get market status; `symbols` can be comma-separated or array, returns all if not provided.
|
|
159
|
+
* `get_tickers(market_type="spot"|"futures", symbol: str|list[str]|None, top_n=5)`
|
|
160
|
+
- Get ticker snapshots; returns top `top_n` when `symbol` not provided.
|
|
161
|
+
* `get_orderbook(symbol, limit=20, market_type="spot"|"futures", interval="0")`
|
|
162
|
+
- Get order book (depth); supports futures.
|
|
163
|
+
* `get_kline(symbol, period="1hour", limit=100, market_type="spot"|"futures")`
|
|
164
|
+
- Get K-line data; periods validated against respective spot/futures whitelists.
|
|
165
|
+
* `get_recent_trades(symbol, market_type="spot"|"futures", limit=100)`
|
|
166
|
+
- Get recent trades (deals).
|
|
167
|
+
* `get_index_price(market_type="spot"|"futures", symbol: str|list[str]|None, top_n=5)`
|
|
168
|
+
- Get market index (spot/futures).
|
|
169
|
+
|
|
170
|
+
### Futures-Specific (public)
|
|
171
|
+
* `get_funding_rate(symbol)`
|
|
172
|
+
- Get current funding rate.
|
|
173
|
+
* `get_funding_rate_history(symbol, start_time?, end_time?, page=1, limit=100)`
|
|
174
|
+
- Get funding rate history.
|
|
175
|
+
* `get_premium_index_history(symbol, start_time?, end_time?, page=1, limit=100)`
|
|
176
|
+
- Get premium index history.
|
|
177
|
+
* `get_basis_history(symbol, start_time?, end_time?, page=1, limit=100)`
|
|
178
|
+
- Get basis rate history.
|
|
179
|
+
* `get_position_tiers(symbol)`
|
|
180
|
+
- Get position tiers/margin tier information.
|
|
181
|
+
* `get_liquidation_history(symbol?, side?, start_time?, end_time?, page=1, limit=100)`
|
|
182
|
+
- Get liquidation history.
|
|
183
|
+
|
|
184
|
+
### Account & Trading (auth)
|
|
185
|
+
* `get_account_balance()`
|
|
186
|
+
- Get account balance information.
|
|
187
|
+
* `place_order(symbol, side, type, amount, price?)`
|
|
188
|
+
- Place trading order.
|
|
189
|
+
* `cancel_order(symbol, order_id)`
|
|
190
|
+
- Cancel order.
|
|
191
|
+
* `get_order_history(symbol?, limit=100)`
|
|
192
|
+
- Get order history (open orders + completed orders).
|
|
193
|
+
|
|
194
|
+
## Environment Variables
|
|
195
|
+
|
|
196
|
+
| Variable | Description | Required |
|
|
197
|
+
|----------|-------------|----------|
|
|
198
|
+
| `COINEX_ACCESS_ID` | CoinEx API Access ID | No (optional with HTTP pass-through) |
|
|
199
|
+
| `COINEX_SECRET_KEY` | CoinEx API Secret Key | No (optional with HTTP pass-through) |
|
|
200
|
+
| `API_TOKEN` | Bearer token to protect MCP endpoint | No |
|
|
201
|
+
| `API_SCOPES` | Required scopes for endpoint | No |
|
|
202
|
+
| `HTTP_AUTH_ENABLED` | Enable HTTP authentication (default false) | No |
|
|
203
|
+
|
|
204
|
+
## Development
|
|
205
|
+
|
|
206
|
+
### Project Structure
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
coinex_mcp_server/
|
|
210
|
+
├── main.py # MCP server main file
|
|
211
|
+
├── coinex_client.py # CoinEx API client (unified spot/futures wrapper)
|
|
212
|
+
├── doc/
|
|
213
|
+
│ ├── coinex_api/
|
|
214
|
+
│ │ └── coinex_api.md # CoinEx API documentation
|
|
215
|
+
├── pyproject.toml # Project configuration
|
|
216
|
+
└── README.md # Project documentation
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Dependencies
|
|
220
|
+
|
|
221
|
+
- `fastmcp` - FastMCP framework (2.x)
|
|
222
|
+
- `httpx` - HTTP client
|
|
223
|
+
- `python-dotenv` - Environment variable loading
|
|
224
|
+
|
|
225
|
+
## Troubleshooting
|
|
226
|
+
- If calls return `code != 0`, record the `message` and check parameters (`period`, `limit`, `symbol` normalization).
|
|
227
|
+
- In corporate network environments or with firewall restrictions, external APIs may be blocked; please verify network policies.
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
This project is open source under the [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) license.
|
|
232
|
+
|
|
233
|
+
## Contributing
|
|
234
|
+
Issues and Pull Requests are welcome!
|
|
235
|
+
|
|
236
|
+
## Disclaimer
|
|
237
|
+
This tool is for educational and research purposes only. When using this tool for actual trading, please fully understand the risks and operate carefully. The developers are not responsible for any losses resulting from the use of this tool.
|