- Hyperliquid Trader Mcp
Hyperliquid Trader Mcp
中文🇨🇳
Hyperliquid MCP Trader
A trading toolchain built on the Model Context Protocol (MCP).
It wraps commonly used Hyperliquid Python SDK endpoints and exposes them as MCP tools:
get_mark_price(symbol): fetch the latest mark priceplace_omarket/limit(symbol, side, qty, price, tif): place a market or limit orderplace_spot_market/limit(...): spot entry points (not yet implemented in the current Hyperliquid SDK; calls raiseNotImplementedError)cancel_order(order_id): cancel an order by idget_positions(dex): return current positions (dexcan be empty,perp, orspot)get_balances(dex): return balances and margin summaries (samedexoptions as above)
1. Environment Setup
- Install uv (
pip install uvor follow the upstream guide). - Create a virtual environment at the project root and sync dependencies:
uv venv uv syncPrefer manual installs? Run
uv pip install -r requirements.txt. - Copy
.env.exampleto.env(or export variables manually) and fill in real credentials:cp .env.example .env # Edit .env: # HL_ACCOUNT_ADDRESS=0xYourMainWalletAddress # HL_SECRET_KEY=0xYourApiWalletPrivateKey # HL_NETWORK=testnet # or mainnet
Security tip: use Hyperliquid’s API wallet (trading permission only) and never commit real private keys.
Optional variables:HL_API_BASE_URL(custom endpoint),HL_SKIP_WS(set to true to skip WebSocket).
2. Run the MCP Server
uv run --env-file .env python -m app.mcp_server
By default the server speaks over stdin/stdout, which is ideal for local development.
To integrate with an MCP host (e.g., Claude Desktop, OpenAI Agents), register the same command in the host config.
Alternatively activate .venv manually and run python -m app.mcp_server.
To host over HTTP or SSE, specify the transport and network parameters:
# Streamable HTTP (defaults to 127.0.0.1:8000/mcp)
uv run --env-file .env python -m app.mcp_server --transport streamable-http --host 0.0.0.0 --port 9000
# SSE (works with OpenAI Agents, default mount path /sse)
uv run --env-file .env python -m app.mcp_server --transport sse
Environment variables are also supported: MCP_TRANSPORT=streamable-http, FASTMCP_HOST, FASTMCP_PORT, etc.
3. Troubleshooting
- Ensure
HL_ACCOUNT_ADDRESSandHL_SECRET_KEYmatch the chosen network (HL_NETWORK). - For rate limits (429) or timeouts, add retry/limit logic inside
HLClient. - Always test on the testnet first; switch to mainnet only after validating the workflow.
The project structure follows patterns from Hyperliquid’s official/community SDK samples and the MCP Python SDK documentation.
Server Config
{
"mcpServers": {
"Q2h0Fx49bWV0wT0hzIvcA": {
"name": "hp交易",
"type": "streamableHttp",
"description": "",
"isActive": true,
"url": "http://0.0.0.0:9000/mcp",
"installSource": "unknown"
}
}
}