A CoinEx MCP (Model Context Protocol) server that enables AI agents to interact with the CoinEx cryptocurrency exchange
Project description
CoinEx MCP Server
中文版本 | English
A CoinEx MCP (Model Context Protocol) server that enables AI agents to interact with the CoinEx cryptocurrency exchange.
Features
- 🔍 Retrieve market data (spot/futures with unified parameters)
- 💰 Query account balances (authentication required)
- 📊 Get K-line data (spot/futures)
- 📈 View order book depth (spot/futures)
- 💹 Place orders (authentication required)
- 📋 Query order history (authentication required)
- 📜 Futures-specific: funding rates, premium/basis history, margin tiers, liquidation history, etc.
Installation & Configuration
1. Install Dependencies
uv sync
2. Configure API Credentials
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:
2.1 MCP Client Configuration
Through MCP clients like Claude Desktop, CherryStudio, or mcp inspector.
2.2 Local File Configuration
- Copy the environment variable template file:
cp .env.example .env
- Edit the
.envfile and fill in your CoinEx API credentials:
COINEX_ACCESS_ID=your_access_id_here
COINEX_SECRET_KEY=your_secret_key_here
Note: In SSE or Streamable HTTP mode, environment variable credentials will be ignored.
3. Obtain CoinEx API Credentials
- Log in to CoinEx Official Website
- Go to User Center -> API Management
- Create a new API Key
- Copy the Access ID and Secret Key to your
.envfile
⚠️ Security Notice:
- Keep your API credentials safe and do not share them with others
- Set appropriate permissions for your API Key, only enabling necessary functions
- Do not commit the
.envfile to version control systems
Usage
Start the Server
python -m coinex_mcp_server.main
Command Line Arguments & Examples
The server supports command line arguments for switching transport protocols and network configuration:
--transport: Transport protocol, options:stdio(default) |http(equivalent tostreamable-http) |streamable-http|sse--host: HTTP service bind address (only valid for http/streamable-http mode)--port: HTTP service port (only valid for http/streamable-http mode)--path: Endpoint path- http/streamable-http mode: MCP endpoint path (default
/mcp) - sse mode: SSE mount path
- http/streamable-http mode: MCP endpoint path (default
--enable-http-auth: Enable HTTP-based authentication and sensitive tools (disabled by default, only exposes query tools)--workers: Number of worker processes for HTTP/SSE mode (managed by underlying uvicorn)
View Help:
python -m coinex_mcp_server.main --help
Default stdio Service Start
(Usually no manual start needed, configure startup file and parameters in agent)
python -m coinex_mcp_server.main
Start HTTP Service
python -m coinex_mcp_server.main --transport http --host 0.0.0.0 --port 8000 --path /mcp --workers 2
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.
Pass CoinEx Credentials via HTTP Headers (HTTP Mode)
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):
X-CoinEx-Access-Id: <your CoinEx Access ID>X-CoinEx-Secret-Key: <your CoinEx Secret Key>
Important Notes
- 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)
- Deploy via HTTPS to prevent man-in-the-middle eavesdropping (use reverse proxy/Nginx/Caddy to add TLS to MCP endpoints).
- These headers are only needed when "HTTP authentication is enabled" and you're calling tools that require user credentials (auth tag).
- Enable with:
--enable-http-author set environment variableHTTP_AUTH_ENABLED=true - By default, HTTP authentication is disabled, exposing only query tools (public), which don't need or read the above headers.
- Enable with:
- Only valid for HTTP/Streamable HTTP mode; STDIO mode reads credentials from environment variables (or .env config file).
Logging & Security
- Ensure reverse proxies/APM/logging systems don't record sensitive headers like
AuthorizationorX-CoinEx-*.
Tools Overview
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.
Standard Parameter Conventions:
market_type: Default"spot", use"futures"for contracts.symbol: SupportsBTCUSDT/BTC/USDT/btc/BTC(defaults toUSDTif no quote currency).interval(depth aggregation levels): Default"0".period: Default"1hour", validated against spot/futures whitelists.start_time/end_time: Millisecond timestamps.
Market Data (public)
list_markets(market_type="spot"|"futures", symbols: str|list[str]|None)- Get market status;
symbolscan be comma-separated or array, returns all if not provided.
- Get market status;
get_tickers(market_type="spot"|"futures", symbol: str|list[str]|None, top_n=5)- Get ticker snapshots; returns top
top_nwhensymbolnot provided.
- Get ticker snapshots; returns top
get_orderbook(symbol, limit=20, market_type="spot"|"futures", interval="0")- Get order book (depth); supports futures.
get_kline(symbol, period="1hour", limit=100, market_type="spot"|"futures")- Get K-line data; periods validated against respective spot/futures whitelists.
get_recent_trades(symbol, market_type="spot"|"futures", limit=100)- Get recent trades (deals).
get_index_price(market_type="spot"|"futures", symbol: str|list[str]|None, top_n=5)- Get market index (spot/futures).
Futures-Specific (public)
get_funding_rate(symbol)- Get current funding rate.
get_funding_rate_history(symbol, start_time?, end_time?, page=1, limit=100)- Get funding rate history.
get_premium_index_history(symbol, start_time?, end_time?, page=1, limit=100)- Get premium index history.
get_basis_history(symbol, start_time?, end_time?, page=1, limit=100)- Get basis rate history.
get_position_tiers(symbol)- Get position tiers/margin tier information.
get_liquidation_history(symbol?, side?, start_time?, end_time?, page=1, limit=100)- Get liquidation history.
Account & Trading (auth)
get_account_balance()- Get account balance information.
place_order(symbol, side, type, amount, price?)- Place trading order.
cancel_order(symbol, order_id)- Cancel order.
get_order_history(symbol?, limit=100)- Get order history (open orders + completed orders).
Environment Variables
| Variable | Description | Required |
|---|---|---|
COINEX_ACCESS_ID |
CoinEx API Access ID | No (optional with HTTP pass-through) |
COINEX_SECRET_KEY |
CoinEx API Secret Key | No (optional with HTTP pass-through) |
API_TOKEN |
Bearer token to protect MCP endpoint | No |
API_SCOPES |
Required scopes for endpoint | No |
HTTP_AUTH_ENABLED |
Enable HTTP authentication (default false) | No |
Development
Project Structure
coinex_mcp_server/
├── main.py # MCP server main file
├── coinex_client.py # CoinEx API client (unified spot/futures wrapper)
├── doc/
│ ├── coinex_api/
│ │ └── coinex_api.md # CoinEx API documentation
├── pyproject.toml # Project configuration
└── README.md # Project documentation
Dependencies
fastmcp- FastMCP framework (2.x)httpx- HTTP clientpython-dotenv- Environment variable loading
Troubleshooting
- If calls return
code != 0, record themessageand check parameters (period,limit,symbolnormalization). - In corporate network environments or with firewall restrictions, external APIs may be blocked; please verify network policies.
License
This project is open source under the Apache 2.0 license.
Contributing
Issues and Pull Requests are welcome!
Disclaimer
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coinex_mcp_server-0.1.0a1.tar.gz.
File metadata
- Download URL: coinex_mcp_server-0.1.0a1.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c46d64120d8c4c3a5e58a80eadada64e05ff9d93a21dbe32dd5a1c6e6a4fd3a
|
|
| MD5 |
10bc5ba3e30824e25fcd6dec4aa9fc48
|
|
| BLAKE2b-256 |
79ab1c3cf0c97a2d30c51e9186a81e3e90eb46fc8b38edcce6ca40a29d114a38
|
File details
Details for the file coinex_mcp_server-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: coinex_mcp_server-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ad795dfcb978a5adf249eec7d9405b9c703cc39b529783a3c99ce0b101931a0
|
|
| MD5 |
1ae2a9435aa535ba88284de0ba4ad612
|
|
| BLAKE2b-256 |
9bda13c3a3589a8e7a84aa43ecae523e9fa54fe1f7bc3142d1a8422862373507
|