hyperliquid-info-mcp 是一个 MCP(Model Context Protocol)服务器,旨在从 Hyperliquid 永续合约去中心化交易所(perp DEX)提供实时数据与洞察,供机器人、仪表盘和分析工具使用。
主要能力
用户数据查询
- get_user_state:获取用户在永续或现货市场的持仓、保证金和可提余额。
- get_user_open_orders:检索用户账户的所有未成交订单。
- get_user_trade_history:获取成交历史,包含交易对、数量和价格等细节。
- get_user_funding_history:查询资金费支付历史,支持自定义时间范围。
- get_user_fees:获取用户特定的费率结构(maker/taker 费率)。
- get_user_staking_summary 与 get_user_staking_rewards:访问质押详情和奖励。
- get_user_order_by_oid 与 get_user_order_by_cloid:通过订单 ID 或客户端订单 ID 检索特定订单详情。
- get_user_sub_accounts:列出与主账户关联的子账户。
市场数据工具
- get_all_mids:获取所有交易对的中间价。
- get_l2_snapshot:获取特定币种的 Level 2 订单簿快照。
- get_candles_snapshot:获取可自定义间隔和时间范围的 K 线数据。
- get_coin_funding_history:查询特定币种的资金费率历史。
- get_perp_dexs:获取永续市场元数据(使用 meta)。
- get_perp_metadata 与 get_spot_metadata:获取永续和现货市场的详细元数据,可选资产上下文。
分析提示词
- analyze_positions:一个引导式提示词,使用相关工具分析用户交易活动。
其他特性
- ISO 8601 支持:基于时间的查询(get_candles_snapshot、get_coin_funding_history、get_user_funding_history)接受 ISO 8601 时间字符串,以便精确过滤数据。
使用方式
环境要求
- Python 3.10(Hyperliquid Python SDK 要求)。
- 用于用户特定查询的有效 Hyperliquid 账户地址。
- uv 或 pip 用于包管理。
安装
克隆仓库: git clone https://github.com/kukapay/hyperliquid-info-mcp.git cd hyperliquid-info-mcp
安装依赖: 使用 uv:uv sync
运行服务器
在开发模式下使用 MCP Inspector 运行服务器,或将其安装到 Claude Desktop 中使用。
交互示例
使用 MCP Inspector 或 Claude Desktop,可以通过自然语言提示与服务器交互。以下示例展示如何以对话方式触发 analyze_positions 提示词和各个工具。
分析交易持仓: 提示词:"Please analyze the trading activity for my Hyperliquid account with address 0xYourAddress. Provide insights on my positions, open orders, and recent trades." 行为:触发 analyze_positions 提示词,使用 get_user_state、get_user_open_orders、get_user_trade_history、get_user_funding_history 和 get_user_fees 获取数据并生成风险/绩效分析。 示例输出: For account 0xYourAddress:
- Current Positions: 0.1 BTC long at $50,000, unrealized PNL +$500.
- Open Orders: 1 limit order to sell 0.05 BTC at $52,000.
- Recent Trades: Bought 0.1 BTC at $50,000 on 2025-05-30.
- Funding Payments: Paid $10 in funding fees last week.
- Fees: Maker fee 0.02%, taker fee 0.05%. Recommendation: Monitor BTC price closely due to high leverage.
获取用户状态: 提示词:"Show me the current state of my Hyperliquid account 0xYourAddress, including my positions and margin details for perpetuals." 行为:调用 get_user_state(account_address="0xYourAddress", check_spot=False)。 示例输出: { "assetPositions": [ { "position": { "coin": "BTC", "szi": "0.1", "entryPx": "50000.0", "markPx": "50500.0", "unrealizedPnl": "500.0" } } ], "marginSummary": { "accountValue": "10000.0", "totalMarginUsed": "2000.0" }, "withdrawable": "8000.0" }
获取 K 线数据: 提示词:"Can you get the 1-minute candlestick data for ETH on Hyperliquid from January 1, 2025, to January 2, 2025?" 行为:调用 get_candles_snapshot(coin_name="ETH", interval="1m", start_time="2025-01-01T00:00:00Z", end_time="2025-01-02T00:00:00Z")。 示例输出: [ { "t": 1672531200000, "o": "3000.0", "h": "3010.0", "l": "2995.0", "c": "3005.0", "v": "1000.0" }, ... ]
查看交易历史: 提示词:"What are the recent trades for my account 0xYourAddress on Hyperliquid?" 行为:调用 get_user_trade_history(account_address="0xYourAddress")。 示例输出: [ { "coin": "ETH", "px": "3000.0", "sz": "0.5", "time": 1672531200000, "tid": "123456" }, ... ]
获取市场元数据: 提示词:"Tell me about the perpetual markets available on Hyperliquid, including trading pairs." 行为:调用 get_perp_metadata(include_asset_ctxs=False)。 示例输出: { "universe": [ { "name": "BTC-PERP", "maxLeverage": 50, "szDecimals": 4, "tickSz": "0.1" }, ... ] }
适用场景
- 交易机器人:获取实时市场数据和用户账户状态,用于自动化交易策略。
- 仪表盘:展示用户持仓、订单、交易历史和资金费率等数据。
- 分析工具:利用 analyze_positions 提示词进行风险与绩效分析。
限制
- 需要 Python 3.10 环境。
- 用户特定查询需要有效的 Hyperliquid 账户地址。
- 项目采用 MIT 许可证。
- 其他未在资料中提及的功能、收费、价格、平台或效果暂未提供。