Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Deploy Documentation

on:
push:
branches:
- main
paths:
- 'docs/**'
- 'mkdocs.yml'
- '.github/workflows/docs.yml'
workflow_dispatch:

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Cache dependencies
uses: actions/cache@v4
with:
key: ${{ github.ref }}
path: .cache

- name: Install dependencies
run: |
pip install -r docs-requirements.txt

- name: Build and deploy
run: |
mkdocs gh-deploy --force
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ env/
.DS_Store
Thumbs.db

test.py
# MkDocs
site/
.cache/

test.py
265 changes: 265 additions & 0 deletions API_DOCS_COMPLETE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
# API 文档已补充完成! ✅

## 新增的 API 文档

我已经为你创建了完整的 API 参考文档:

### 1. 工具 API 参考 (`docs/api/tools-reference.md`) ✅

**内容**:

- 📊 **账户管理** (5 个工具)

- `get_account_balance` - 获取余额
- `get_open_positions` - 获取仓位
- `get_open_orders` - 获取订单
- `get_trade_history` - 交易历史
- `get_account_summary` - 账户概览

- 📈 **交易工具** (4 个工具)

- `place_limit_order` - 限价单
- `market_open_position` - 市价开仓
- `market_close_position` - 市价平仓
- `place_bracket_order` - 括号订单
- `close_position` - 关闭仓位

- 🎯 **止盈止损管理** (3 个工具)

- `set_take_profit_stop_loss` - 设置 TP/SL
- `set_take_profit` - 只设置止盈
- `set_stop_loss` - 只设置止损

- 📝 **订单管理** (4 个工具)

- `cancel_order` - 取消订单
- `cancel_order_by_client_id` - 按客户端 ID 取消
- `cancel_all_orders` - 批量取消
- `modify_order` - 修改订单

- 💹 **市场数据** (3 个工具)

- `get_market_data` - 市场数据
- `get_orderbook` - 订单簿
- `get_funding_history` - 资金费率

- ⚙️ **账户设置** (2 个工具)

- `update_leverage` - 更新杠杆
- `transfer_between_spot_and_perp` - 转账

- 🧮 **实用工具** (1 个工具)
- `calculate_token_amount_from_dollars` - 美元转代币

**特色**:

- ✨ 每个工具都有详细的参数说明
- 📝 完整的代码示例
- ⚠️ 重要提示和警告框
- 💡 使用技巧和最佳实践

### 2. 返回格式说明 (`docs/api/response-format.md`) ✅

**内容**:

- 标准响应格式(成功/失败)
- 所有工具的返回示例
- 字段详细说明
- 最佳实践

**包含**:

- ✅ 账户信息返回格式
- ✅ 交易操作返回格式
- ✅ 订单管理返回格式
- ✅ 市场数据返回格式
- ✅ 错误响应格式
- ✅ 字段说明表格

### 3. 错误处理指南 (`docs/api/error-handling.md`) ✅

**内容**:

- 6 种错误类型详解
- 错误处理模式
- 常见错误场景及解决方案
- 日志记录和恢复策略

**错误类型**:

1. `VALIDATION_ERROR` - 验证错误
2. `INSUFFICIENT_BALANCE` - 余额不足
3. `POSITION_NOT_FOUND` - 仓位未找到
4. `ORDER_NOT_FOUND` - 订单未找到
5. `API_ERROR` - API 错误
6. `INVALID_PRICE/SIZE` - 价格/数量无效

**错误处理模式**:

- 基础错误检查
- 详细错误处理
- 异常处理
- 防御性编程

**实用示例**:

- ✅ 重试机制
- ✅ 降级策略
- ✅ 日志记录
- ✅ 错误恢复

## 📁 完整文档结构

```
docs/
├── index.md ✅ 首页
├── getting-started/ ✅ 快速开始
│ ├── installation.md ✅ 安装指南
│ ├── configuration.md ✅ 配置指南
│ └── quick-start.md ✅ 快速验证
├── api/ ✅ API 参考(新增)
│ ├── tools-reference.md ✅ 工具 API 参考
│ ├── response-format.md ✅ 返回格式
│ └── error-handling.md ✅ 错误处理
├── guides/ 🚧 使用指南(待补充)
│ ├── mcp-integration.md 🚧 MCP 集成
│ ├── trading-tools.md 🚧 交易工具
│ ├── account-management.md 🚧 账户管理
│ ├── market-data.md 🚧 市场数据
│ └── use-cases.md 🚧 常见用例
├── developers/ 🚧 开发者文档(待补充)
│ ├── architecture.md 🚧 架构设计
│ ├── testing.md 🚧 测试工具
│ └── contributing.md 🚧 贡献指南
├── troubleshooting.md ✅ 故障排除
└── changelog.md ✅ 更新日志
```

## 🎯 API 文档亮点

### 1. 详尽的工具说明

每个工具都包含:

- **参数列表**:类型、默认值、说明
- **返回示例**:实际的 JSON 响应
- **代码示例**:Python 调用示例
- **注意事项**:重要提示和警告

### 2. 突出 Size 参数问题

特别强调了最容易出错的 `size` 参数:

!!! warning "重要"
**`size` 参数是代币数量,不是美元金额!** - ✅ `0.1` = 0.1 个 BTC 代币 - ❌ `20.0` ≠ $20 美元

### 3. 清晰的错误处理

提供了:

- 所有错误类型的详细说明
- 实际的错误响应示例
- 具体的解决方案代码
- 重试和降级策略

### 4. 最佳实践

每个章节都包含最佳实践:

- ✅ 使用前验证
- ✅ 错误检查
- ✅ 日志记录
- ✅ 重试机制

## 🔍 快速预览

### 工具 API 参考

````markdown
### market_open_position

使用市价单开仓(最优执行)。

**参数**:

- `coin` (str): 交易对
- `side` (str): "buy" 做多 或 "sell" 做空
- `size` (float): **代币数量**(不是美元金额!)

**示例**:
​```python

# 先计算代币数量

calc = calculate_token_amount_from_dollars("BTC", 100.0)

# 开多仓

order = market_open_position("BTC", "buy", calc["token_amount"])
​```
````

### 错误处理示例

```python
result = place_limit_order("BTC", "buy", 0.1, 45000)

if not result["success"]:
error_code = result.get("error_code")

if error_code == "INSUFFICIENT_BALANCE":
print("余额不足,请充值或减少订单大小")
elif error_code == "API_ERROR":
print("API 错误,稍后重试")
```

## 📊 文档统计

- **总页面数**: 10+ 页
- **API 工具数**: 25+ 个
- **代码示例**: 50+ 个
- **错误类型**: 6 种
- **最佳实践**: 多个章节

## 🚀 下一步

### 还需要补充的文档:

1. **使用指南** (`docs/guides/`)

- MCP 客户端集成教程
- 交易工具详细使用
- 账户管理指南
- 市场数据获取
- 常见使用场景

2. **开发者文档** (`docs/developers/`)
- 架构设计说明
- 测试工具使用
- 贡献指南

需要我继续补充这些文档吗?

## 📖 查看文档

```bash
# 本地预览
make docs-serve

# 或直接使用 mkdocs
mkdocs serve
```

访问 http://127.0.0.1:8000 查看完整文档!

---

**API 文档已经完整创建!** 🎉

现在用户可以查看:

- ✅ 所有工具的完整 API 参考
- ✅ 详细的返回格式说明
- ✅ 全面的错误处理指南
- ✅ 丰富的代码示例
- ✅ 最佳实践建议
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ help:
@echo " make publish - 发布到 PyPI"
@echo " make version - 显示当前版本"
@echo ""
@echo "文档:"
@echo " make docs-install - 安装文档依赖"
@echo " make docs-serve - 本地预览文档 ⭐"
@echo " make docs-build - 构建文档"
@echo " make docs-deploy - 部署到 GitHub Pages"
@echo ""
@echo "快捷命令:"
@echo " make all - clean + build"
@echo " make release - clean + build + publish"
Expand Down Expand Up @@ -280,3 +286,36 @@ full-release:
@echo "🎉 发布完成!别忘了:"
@echo " git push origin main"
@echo " git push origin v$$(grep '^version = ' pyproject.toml | cut -d'"' -f2)"

# ============================================================================
# 文档命令
# ============================================================================

# 安装文档依赖
docs-install:
@echo "📦 安装文档依赖..."
pip install -r docs-requirements.txt

# 本地预览文档
docs-serve:
@echo "🌐 启动文档服务器..."
@echo "📖 浏览器访问 http://127.0.0.1:8000"
mkdocs serve

# 构建文档
docs-build:
@echo "📚 构建文档..."
mkdocs build
@echo "✅ 文档已构建到 site/ 目录"

# 部署文档到 GitHub Pages
docs-deploy:
@echo "🚀 部署文档到 GitHub Pages..."
mkdocs gh-deploy --force
@echo "✅ 文档已部署"

# 清理文档构建
docs-clean:
@echo "🧹 清理文档构建..."
rm -rf site/
@echo "✅ 清理完成"
30 changes: 30 additions & 0 deletions Makefile.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 构建文档网站
.PHONY: docs-build
docs-build:
@echo "📚 Building documentation..."
mkdocs build

# 本地预览文档
.PHONY: docs-serve
docs-serve:
@echo "🌐 Starting documentation server..."
@echo "📖 Open http://127.0.0.1:8000 in your browser"
mkdocs serve

# 部署文档到 GitHub Pages
.PHONY: docs-deploy
docs-deploy:
@echo "🚀 Deploying documentation to GitHub Pages..."
mkdocs gh-deploy --force

# 安装文档依赖
.PHONY: docs-install
docs-install:
@echo "📦 Installing documentation dependencies..."
pip install -r docs-requirements.txt

# 清理文档构建
.PHONY: docs-clean
docs-clean:
@echo "🧹 Cleaning documentation build..."
rm -rf site/
Loading