# @openfinclaw/openfinclaw-strategy

OpenFinClaw - 统一金融工具插件。一个 API Key，一站式服务：

- **行情数据**: 价格查询、K线、加密市场数据、多资产对比、代码搜索
- **策略工具**: 发布、验证、Fork、排行榜

## 安装

```bash
openclaw plugins install @openfinclaw/openfinclaw-strategy
```

## 快速开始

```bash
# 查看策略排行榜
openclaw strategy leaderboard

# 查看收益榜 Top 10
openclaw strategy leaderboard returns --limit 10

# 查看策略详情
openclaw strategy show <strategy-id> --remote
```

或者直接告诉 Agent 你想做什么：

- "BTC 现在多少钱" → Agent 会使用 `fin_price`
- "ETH 最近 7 天走势" → Agent 会使用 `fin_kline`
- "DeFi 哪个协议 TVL 最高" → Agent 会使用 `fin_crypto`
- "帮我看看排行榜有什么好策略" → Agent 会使用 `skill_leaderboard`

## 功能概览

### 行情数据工具

| 工具名            | 说明                       | API Key |
| ----------------- | -------------------------- | ------- |
| `fin_price`       | 价格查询（股票/加密/指数） | 需要    |
| `fin_kline`       | K线/OHLCV 数据             | 需要    |
| `fin_crypto`      | 加密市场数据（21个端点）   | 需要    |
| `fin_compare`     | 多资产价格对比             | 需要    |
| `fin_slim_search` | 代码/名称搜索              | 需要    |

### 策略工具

| 工具名                 | 说明                       | API Key |
| ---------------------- | -------------------------- | ------- |
| `skill_leaderboard`    | 查询排行榜                 | 需要    |
| `skill_get_info`       | 获取 Hub 策略公开详情      | 需要    |
| `skill_validate`       | 本地验证策略包（FEP v2.0） | 需要    |
| `skill_list_local`     | 列出本地策略               | 需要    |
| `skill_fork`           | 从 Hub 下载策略到本地      | 需要    |
| `skill_publish`        | 发布策略 ZIP 到 Hub        | 需要    |
| `skill_publish_verify` | 查询发布状态和回测报告     | 需要    |

## CLI 命令

```bash
# 查看排行榜
openclaw strategy leaderboard
openclaw strategy leaderboard returns --limit 10

# 从 Hub Fork 策略
openclaw strategy fork <strategy-id>

# 列出本地策略
openclaw strategy list

# 查看策略详情
openclaw strategy show <name-or-id> [--remote]

# 删除本地策略
openclaw strategy remove <name-or-id> --force
```

## 配置

从 https://hub.openfinclaw.ai 获取 API Key（以 `fch_` 开头），一个 Key 即可使用所有功能：

```bash
openclaw config set plugins.entries.openfinclaw-strategy.config.apiKey YOUR_API_KEY
```

或使用环境变量：

```bash
export OPENFINCLAW_API_KEY=YOUR_API_KEY
```

### 配置选项

| 配置项              | 环境变量              | 说明             | 默认值                       |
| ------------------- | --------------------- | ---------------- | ---------------------------- |
| `apiKey`            | `OPENFINCLAW_API_KEY` | 统一 API Key     | 必填                         |
| `hubApiUrl`         | `HUB_API_URL`         | Hub 服务地址     | `https://hub.openfinclaw.ai` |
| `datahubGatewayUrl` | `DATAHUB_GATEWAY_URL` | DataHub 网关地址 | `http://43.134.61.136:9080`  |
| `requestTimeoutMs`  | `REQUEST_TIMEOUT_MS`  | 请求超时（毫秒） | `60000`                      |

### ⚠️ API Key 安全提醒

**重要：请勿泄露你的 API Key！**

- API Key 以 `fch_` 开头，用于 Hub 和 DataHub 接口校验
- **不要**将 API Key 提交到 Git 仓库或公开分享
- **不要**在公开聊天、截图、代码示例中暴露真实的 API Key
- 如果怀疑 Key 已泄露，请立即在 Hub 个人设置中重新生成

## Skills

### 行情数据 Skills

| Skill         | 说明     |
| ------------- | -------- |
| `price-check` | 快速查价 |

### 策略 Skills

| Skill              | 说明             |
| ------------------ | ---------------- |
| `openfinclaw`      | 平台入口         |
| `strategy-builder` | 自然语言生成策略 |
| `skill-publish`    | 发布策略到 Hub   |
| `strategy-fork`    | 从 Hub 下载策略  |
| `strategy-pack`    | 创建回测策略包   |

## 本地存储

策略存储在 `~/.openfinclaw/workspace/strategies/`：

```
~/.openfinclaw/workspace/strategies/
└── 2026-03-16/
    ├── btc-adaptive-dca-34a5792f/   # Fork 来的策略
    │   ├── fep.yaml
    │   ├── scripts/strategy.py
    │   └── .fork-meta.json
    └── my-new-strategy/             # 自建策略
        └── ...
```

## 链接

- **Hub 平台**: https://hub.openfinclaw.ai
- **排行榜**: https://hub.openfinclaw.ai/leaderboard
- **获取 API Key**: https://hub.openfinclaw.ai/dashboard
- **GitHub**: https://github.com/cryptoSUN2049/openFinclaw

## License

MIT
