Skip to content

Commit 5365585

Browse files
committed
feat: Add interactive testing tool for HyperLiquid MCP features
- Implemented interactive test script (interactive_test.py) to allow users to test various functionalities including account balance, open positions, market data, and order book retrieval. - Created a shell script (run_tests.sh) to run all read-only tests with a user-friendly menu interface. - Developed individual test scripts for account information (test_account_info.py), connection (test_connection.py), funding history (test_funding_history.py), market data (test_market_data.py), order book (test_orderbook.py), price calculator (test_price_calculator.py), and small order validation (test_small_order.py). - Each test script includes detailed output for success and failure cases, enhancing debugging and user experience.
1 parent 0e903a1 commit 5365585

16 files changed

Lines changed: 2266 additions & 17 deletions

MAKEFILE_GUIDE.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# Makefile 使用指南
2+
3+
## 🚀 快速开始
4+
5+
```bash
6+
# 1. 安装依赖
7+
make install
8+
9+
# 2. 查看配置
10+
make config
11+
12+
# 3. 快速验证
13+
make test-quick
14+
15+
# 4. 运行服务器
16+
make run-http
17+
```
18+
19+
## 📋 所有命令
20+
21+
### 开发命令
22+
23+
| 命令 | 说明 |
24+
|------|------|
25+
| `make install` | 安装依赖(uv sync) |
26+
| `make dev` | 开发模式安装 |
27+
| `make run-http` | 启动 HTTP 服务器 (http://127.0.0.1:8080) |
28+
| `make run-stdio` | 启动 stdio 服务器(用于 MCP 客户端) |
29+
| `make config` | 查看当前配置(隐藏私钥) |
30+
| `make logs` | 查看日志文件 |
31+
32+
### 测试命令
33+
34+
| 命令 | 说明 |
35+
|------|------|
36+
| `make test-all` | 运行所有只读测试 ⭐ |
37+
| `make test-quick` | 快速验证(连接+余额+地址) |
38+
| `make test-connection` | 基础连接测试 |
39+
| `make test-account` | 账户信息测试 |
40+
| `make test-balance` | 账户余额检查(现货+合约) |
41+
| `make test-market` | 市场数据测试 |
42+
| `make test-orderbook` | 订单簿测试 |
43+
| `make test-funding` | 资金费率历史测试 |
44+
| `make test-calculator` | 价格计算器测试 |
45+
| `make test-address` | 地址验证测试 |
46+
| `make test-interactive` | 交互式测试工具 |
47+
| `make list-tests` | 列出所有可用测试脚本 |
48+
49+
### 代码质量
50+
51+
| 命令 | 说明 |
52+
|------|------|
53+
| `make format` | 格式化代码(black + isort) |
54+
| `make check` | 检查代码但不修改 |
55+
| `make lint` | 运行代码检查 |
56+
| `make test` | 运行单元测试 |
57+
58+
### 构建和发布
59+
60+
| 命令 | 说明 |
61+
|------|------|
62+
| `make clean` | 清理构建文件 |
63+
| `make build` | 构建发布包 |
64+
| `make publish` | 发布到 PyPI |
65+
| `make test-pypi` | 发布到测试 PyPI |
66+
| `make all` | clean + build |
67+
| `make release` | clean + build + publish |
68+
69+
### 文档和帮助
70+
71+
| 命令 | 说明 |
72+
|------|------|
73+
| `make help` | 显示所有可用命令 |
74+
| `make test-help` | 显示测试快速参考 |
75+
| `make docs` | 显示完整 README |
76+
| `make test-docs` | 显示测试文档 |
77+
| `make list-tests` | 列出所有测试脚本 |
78+
79+
## 🎯 常用工作流
80+
81+
### 首次配置
82+
83+
```bash
84+
# 1. 克隆仓库
85+
git clone https://github.com/jamiesun/hyperliquid-mcp.git
86+
cd hyperliquid-mcp
87+
88+
# 2. 安装依赖
89+
make install
90+
91+
# 3. 配置环境变量
92+
cp .env.example .env
93+
# 编辑 .env 文件,填入你的配置
94+
95+
# 4. 验证配置
96+
make test-quick
97+
98+
# 5. 运行所有测试
99+
make test-all
100+
```
101+
102+
### 日常开发
103+
104+
```bash
105+
# 查看配置
106+
make config
107+
108+
# 测试连接
109+
make test-connection
110+
111+
# 启动服务器
112+
make run-http
113+
114+
# 查看日志
115+
make logs
116+
```
117+
118+
### 测试新功能
119+
120+
```bash
121+
# 测试市场数据
122+
make test-market
123+
124+
# 测试账户信息
125+
make test-account
126+
127+
# 交互式测试
128+
make test-interactive
129+
```
130+
131+
### 发布新版本
132+
133+
```bash
134+
# 清理
135+
make clean
136+
137+
# 构建
138+
make build
139+
140+
# 发布到测试 PyPI
141+
make test-pypi
142+
143+
# 发布到正式 PyPI
144+
make publish
145+
```
146+
147+
## 💡 提示
148+
149+
- 所有测试命令都是**只读**的,不会修改账户状态
150+
- 使用 `make test-quick` 可以快速验证配置是否正确
151+
- `make test-all` 会运行所有测试,适合全面检查
152+
- `make config` 会隐藏私钥,可以安全地查看配置
153+
- 首次使用建议在测试网环境下进行 (`HYPERLIQUID_TESTNET=true`)
154+
155+
## 🔗 相关文档
156+
157+
- [主 README](../README.md)
158+
- [测试脚本文档](test_scripts/README.md)
159+
- [测试快速参考](test_scripts/QUICK_REFERENCE.md)

Makefile

Lines changed: 169 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,70 @@
1-
.PHONY: help install dev clean build publish test run-http run-stdio lint format check
1+
# ============================================================================
2+
# HyperLiquid MCP Makefile
3+
# ============================================================================
4+
#
5+
# 快速开始:
6+
# make install # 安装依赖
7+
# make config # 查看配置
8+
# make test-quick # 快速验证(连接+余额+地址)
9+
# make test-all # 运行所有只读测试
10+
# make run-http # 启动 HTTP 服务器
11+
#
12+
# 测试:
13+
# make test-market # 市场数据测试
14+
# make test-account # 账户信息测试
15+
# make test-balance # 余额检查
16+
#
17+
# 帮助:
18+
# make help # 显示所有可用命令
19+
# make test-help # 显示测试快速参考
20+
# make list-tests # 列出所有测试脚本
21+
#
22+
# ============================================================================
23+
24+
.PHONY: help install dev clean build publish test run-http run-stdio lint format check \
25+
test-connection test-account test-balance test-market test-orderbook \
26+
test-funding test-calculator test-all test-interactive config logs
227

328
# 默认目标
429
help:
530
@echo "HyperLiquid MCP - 可用命令:"
631
@echo ""
732
@echo "开发命令:"
8-
@echo " make install - 安装依赖(uv sync)"
9-
@echo " make dev - 开发模式安装"
10-
@echo " make run-http - 启动 HTTP 服务器"
11-
@echo " make run-stdio - 启动 stdio 服务器"
33+
@echo " make install - 安装依赖(uv sync)"
34+
@echo " make dev - 开发模式安装"
35+
@echo " make run-http - 启动 HTTP 服务器"
36+
@echo " make run-stdio - 启动 stdio 服务器"
37+
@echo ""
38+
@echo "测试命令:"
39+
@echo " make test-all - 运行所有只读测试 ⭐"
40+
@echo " make test-connection - 基础连接测试"
41+
@echo " make test-account - 账户信息测试"
42+
@echo " make test-balance - 账户余额检查"
43+
@echo " make test-market - 市场数据测试"
44+
@echo " make test-orderbook - 订单簿测试"
45+
@echo " make test-funding - 资金费率历史测试"
46+
@echo " make test-calculator - 价格计算器测试"
47+
@echo " make test-interactive - 交互式测试工具"
1248
@echo ""
1349
@echo "代码质量:"
14-
@echo " make lint - 运行代码检查"
15-
@echo " make format - 格式化代码"
16-
@echo " make check - 检查代码但不修改"
17-
@echo " make test - 运行测试"
50+
@echo " make lint - 运行代码检查"
51+
@echo " make format - 格式化代码"
52+
@echo " make check - 检查代码但不修改"
53+
@echo " make test - 运行单元测试"
1854
@echo ""
1955
@echo "构建和发布:"
20-
@echo " make clean - 清理构建文件"
21-
@echo " make build - 构建发布包"
22-
@echo " make publish - 发布到 PyPI"
23-
@echo " make test-pypi - 发布到测试 PyPI"
56+
@echo " make clean - 清理构建文件"
57+
@echo " make build - 构建发布包"
58+
@echo " make publish - 发布到 PyPI"
59+
@echo " make test-pypi - 发布到测试 PyPI"
2460
@echo ""
2561
@echo "快捷命令:"
26-
@echo " make all - clean + build"
27-
@echo " make release - clean + build + publish"
62+
@echo " make all - clean + build"
63+
@echo " make release - clean + build + publish"
64+
65+
# ============================================================================
66+
# 运行服务器
67+
# ============================================================================
2868

2969
# 安装依赖
3070
install:
@@ -36,12 +76,40 @@ dev:
3676

3777
# 运行 HTTP 服务器
3878
run-http:
79+
@echo "🚀 启动 HTTP 服务器 (http://127.0.0.1:8080)..."
3980
uv run hyperliquid-mcp start
4081

4182
# 运行 stdio 服务器
4283
run-stdio:
84+
@echo "🚀 启动 stdio 服务器..."
4385
uv run hyperliquid-mcp stdio
4486

87+
# 查看日志
88+
logs:
89+
@if [ -f hyperliquid_mcp.log ]; then \
90+
tail -f hyperliquid_mcp.log; \
91+
else \
92+
echo "⚠️ 日志文件不存在"; \
93+
fi
94+
95+
# 查看配置
96+
config:
97+
@echo "📋 当前配置:"
98+
@echo ""
99+
@if [ -f .env ]; then \
100+
echo "从 .env 文件:"; \
101+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"; \
102+
grep -v '^#' .env | grep -v '^$$' | sed 's/HYPERLIQUID_PRIVATE_KEY=.*/HYPERLIQUID_PRIVATE_KEY=***隐藏***/'; \
103+
else \
104+
echo "⚠️ .env 文件不存在"; \
105+
fi
106+
@echo ""
107+
@echo "提示: 复制 .env.example 到 .env 并填入你的配置"
108+
109+
# ============================================================================
110+
# 代码质量
111+
# ============================================================================
112+
45113
# 代码格式化
46114
format:
47115
uv run black .
@@ -56,11 +124,95 @@ check:
56124
lint: check
57125
@echo "✅ 代码检查通过"
58126

59-
# 运行测试
127+
# ============================================================================
128+
# 文档和帮助
129+
# ============================================================================
130+
131+
# 显示测试脚本帮助
132+
test-help:
133+
@cat test_scripts/QUICK_REFERENCE.md
134+
135+
# 显示完整 README
136+
docs:
137+
@cat README.md
138+
139+
# 显示测试文档
140+
test-docs:
141+
@cat test_scripts/README.md
142+
143+
# 列出所有可用的测试脚本
144+
list-tests:
145+
@echo "📝 可用的测试脚本:"
146+
@echo ""
147+
@ls -1 test_scripts/*.py | xargs -I {} basename {} | sort | nl
148+
@echo ""
149+
@echo "运行: make test-<名称> 或 uv run python test_scripts/<脚本名>"
150+
151+
# ============================================================================
152+
# 清理和构建
153+
# ============================================================================
154+
155+
# ============================================================================
156+
# 测试命令
157+
# ============================================================================
158+
159+
# 运行单元测试
60160
test:
61-
@echo "⚠️ 暂无测试,跳过"
161+
@echo "⚠️ 暂无单元测试,跳过"
62162
@# uv run pytest
63163

164+
# 运行所有只读测试
165+
test-all:
166+
@echo "🧪 运行所有只读测试..."
167+
@./test_scripts/run_tests.sh all
168+
169+
# 基础连接测试
170+
test-connection:
171+
@echo "🔗 运行基础连接测试..."
172+
@uv run python test_scripts/test_connection.py
173+
174+
# 账户信息测试
175+
test-account:
176+
@echo "👤 运行账户信息测试..."
177+
@uv run python test_scripts/test_account_info.py
178+
179+
# 账户余额检查
180+
test-balance:
181+
@echo "💰 运行账户余额检查..."
182+
@uv run python test_scripts/check_all_balances.py
183+
184+
# 市场数据测试
185+
test-market:
186+
@echo "📊 运行市场数据测试..."
187+
@uv run python test_scripts/test_market_data.py
188+
189+
# 订单簿测试
190+
test-orderbook:
191+
@echo "📖 运行订单簿测试..."
192+
@uv run python test_scripts/test_orderbook.py
193+
194+
# 资金费率历史测试
195+
test-funding:
196+
@echo "💵 运行资金费率历史测试..."
197+
@uv run python test_scripts/test_funding_history.py
198+
199+
# 价格计算器测试
200+
test-calculator:
201+
@echo "🧮 运行价格计算器测试..."
202+
@uv run python test_scripts/test_price_calculator.py
203+
204+
# 交互式测试工具
205+
test-interactive:
206+
@echo "🎮 启动交互式测试工具..."
207+
@uv run python test_scripts/interactive_test.py
208+
209+
# 快速验证(连接 + 余额)
210+
test-quick:
211+
@echo "⚡ 快速验证..."
212+
@$(MAKE) test-connection
213+
@echo ""
214+
@$(MAKE) test-balance
215+
64216
# 清理构建文件
65217
clean:
66218
rm -rf dist/

0 commit comments

Comments
 (0)