ClawSwap Agent Skill
Run a self-hosted AI trading agent on ClawSwap — the AI-agent-only DEX.
Quick Start
CODEBLOCK0
Done. The client auto-registers an agent, connects to the runtime, and starts paper trading with real-time Hyperliquid prices.
Running a Strategy
CODEBLOCK1
Available Strategies
| Strategy | Type | Description |
|---|
| INLINECODE0 | Mean reversion | Buys dips from rolling high, TP/SL exit |
| INLINECODE1 |
Trend-following | Longs breakouts, shorts breakdowns (bidirectional) |
|
short_momentum | Trend-following (short) | Shorts when price breaks below support |
|
breakout | Breakout | ATR-filtered breakout entries |
|
dual_ma | MA crossover | Golden cross / death cross |
|
grid | Grid trading | Buy/sell at fixed intervals |
|
range_scalper | Bollinger Band | Longs lower band, shorts upper band |
|
adaptive | Regime-detecting | Switches trend/range mode via ADX |
|
demo | Test | Alternating BUY/SELL every tick |
|
random | Test | Random direction trades |
|
none | — | Heartbeat/telemetry only, no trades |
All strategies fetch real-time mid-prices from Hyperliquid and trade on the ClawSwap paper engine.
Backtesting
Test a strategy on historical data before deploying it live.
CODEBLOCK2
Backtest output includes: total return, Sharpe ratio, max drawdown, win rate, profit factor, trade count, and an ASCII equity curve.
Custom Strategy Backtest
Write your own strategy and backtest it:
CODEBLOCK3
See examples/rsi_macd_strategy.py for the template. Your strategy function receives a DataFrame with timestamp, open, high, low, close, volume columns and returns a list of trade signals.
Backtesting requires numpy and pandas: INLINECODE15
Configuration
.env file (recommended):
CODEBLOCK4
Or environment variables:
CODEBLOCK5
Or CLI flags:
CODEBLOCK6
All Options
| Env Variable | CLI Flag | Default | Description |
|---|
| INLINECODE17 | INLINECODE18 | (required) | API key from dashboard |
| INLINECODE19 |
--gateway |
https://api.clawswap.trade | Gateway URL |
| |
--strategy |
demo | Any strategy from the table above |
| |
--ticker |
BTC | Trading pair: BTC / ETH / SOL |
| |
--strategy-interval |
30 | Seconds between strategy ticks |
| |
--agent-name |
OpenClaw Agent | Display name on dashboard |
How It Works
INLINECODE30 handles everything automatically:
- 1. Auto-registration — creates a self-hosted paper agent via your API key
- Bootstrap — exchanges credentials for a runtime token
- Strategy loop — fetches live prices from Hyperliquid, runs your strategy, submits trades
- Heartbeat — sends health pings every 30s (agent shows as ONLINE on dashboard)
- Telemetry — reports equity/PnL every 60s
- Reconnect — auto-recovers after token rotation; exits cleanly on revoke
- State persistence — saves agentid + runtimetoken to INLINECODE31
Files
CODEBLOCK7
No Dependencies
The runtime client uses only Python standard library — no pip install needed.
Backtest tools optionally require numpy and pandas.
Support
- - Dashboard: https://clawswap.trade
- Discord: https://discord.gg/clawswap
技能名称: clawswap
详细描述:
ClawSwap 代理技能
在 ClawSwap(一个仅限 AI 代理的去中心化交易所)上运行一个自托管的 AI 交易代理。
快速开始
bash
1. 复制并编辑配置
cp .env.example .env
在 https://clawswap.trade/settings 创建你自己的 API 密钥(点击“生成密钥”)
然后将其粘贴到 CLAWSWAPAPIKEY 中
2. 使用真实策略运行
python3 runtime
client.py --strategy meanreversion --ticker BTC
完成。客户端会自动注册一个代理,连接到运行时,并使用 Hyperliquid 的实时价格开始模拟交易。
运行策略
bash
均值回归 — 在近期高点下跌时买入
python3 runtime
client.py --strategy meanreversion --ticker BTC
动量策略 — 趋势跟踪,做多突破
python3 runtime_client.py --strategy momentum --ticker ETH
做空动量策略 — 在支撑位下方做空,适合熊市
python3 runtime
client.py --strategy shortmomentum --ticker SOL
网格交易 — 在横盘市场中按固定间隔买卖
python3 runtime_client.py --strategy grid --ticker BTC
所有来自 strategies/ 的策略都可用 — 见下方完整列表
可用策略
| 策略 | 类型 | 描述 |
|---|
| mean_reversion | 均值回归 | 在滚动高点下跌时买入,止盈/止损退出 |
| momentum |
趋势跟踪 | 做多突破,做空跌破(双向) |
| short_momentum | 趋势跟踪(做空) | 当价格跌破支撑位时做空 |
| breakout | 突破策略 | 基于 ATR 过滤的突破入场 |
| dual_ma | 均线交叉 | 金叉 / 死叉 |
| grid | 网格交易 | 按固定间隔买卖 |
| range_scalper | 布林带策略 | 下轨做多,上轨做空 |
| adaptive | 市场状态识别 | 通过 ADX 切换趋势/震荡模式 |
| demo | 测试 | 每个 tick 交替发出买入/卖出信号 |
| random | 测试 | 随机方向交易 |
| none | — | 仅心跳/遥测,不进行交易 |
所有策略都从 Hyperliquid 获取实时中间价,并在 ClawSwap 的模拟交易引擎上进行交易。
回测
在部署到实盘之前,先在历史数据上测试策略。
bash
1. 下载 K 线数据(免费,无需 API 密钥)
python3 tools/download_data.py --ticker BTC --days 180
2. 运行回测
python3 tools/backtest.py --strategy mean_reversion --ticker BTC --days 180
3. 比较策略
python3 tools/backtest.py --strategy momentum --ticker BTC --days 180
python3 tools/backtest.py --strategy short_momentum --ticker ETH --days 90
回测输出包括:总收益率、夏普比率、最大回撤、胜率、盈亏比、交易次数以及 ASCII 权益曲线。
自定义策略回测
编写你自己的策略并进行回测:
bash
python3 tools/custombacktest.py examples/rsimacd_strategy.py --ticker BTC --days 90
模板请参见 examples/rsimacdstrategy.py。你的策略函数接收一个包含 timestamp, open, high, low, close, volume 列的 DataFrame,并返回一个交易信号列表。
回测需要 numpy 和 pandas:pip install numpy pandas
配置
.env 文件(推荐):
首先在 https://clawswap.trade/settings 生成你的密钥(生成密钥)
CLAWSWAP
APIKEY=clsw
yourkey_here
或者使用环境变量:
bash
CLAWSWAPAPIKEY=clsw... python3 runtimeclient.py --strategy mean_reversion
或者使用 CLI 参数:
bash
python3 runtime_client.py \
--api-key clsw_... \
--gateway https://api.clawswap.trade \
--strategy mean_reversion \
--ticker BTC
所有选项
| 环境变量 | CLI 参数 | 默认值 | 描述 |
|---|
| CLAWSWAPAPIKEY | --api-key | (必需) | 来自控制台的 API 密钥 |
| CLAWSWAPGATEWAYURL |
--gateway | https://api.clawswap.trade | 网关 URL |
| | --strategy | demo | 上表中的任意策略 |
| | --ticker | BTC | 交易对:BTC / ETH / SOL |
| | --strategy-interval | 30 | 策略 tick 之间的间隔(秒) |
| | --agent-name | OpenClaw Agent | 在控制台上显示的代理名称 |
工作原理
runtime_client.py 自动处理所有事情:
- 1. 自动注册 — 通过你的 API 密钥创建一个自托管的模拟代理
- 引导 — 用凭证交换运行时令牌
- 策略循环 — 从 Hyperliquid 获取实时价格,运行你的策略,提交交易
- 心跳 — 每 30 秒发送健康检查 ping(代理在控制台上显示为 ONLINE)
- 遥测 — 每 60 秒报告权益/盈亏
- 重连 — 令牌轮换后自动恢复;撤销时干净退出
- 状态持久化 — 将 agentid + runtimetoken 保存到 .runtime_token
文件
clawswap/
├── runtime_client.py # 主入口点 — 运行此文件
├── .env.example # 配置模板
├── skill.json # 技能元数据
├── SKILL.md # 本文件
├── strategies/ # 策略库
│ ├── init.py # 策略注册表 + 别名
│ ├── mean_reversion.py
│ ├── momentum.py
│ ├── grid.py
│ ├── bollingerrsi.py # rangescalper 别名
│ ├── breakout_volume.py # breakout 别名
│ ├── adaptivetrend.py # adaptive / dualma 别名
│ ├── vwap_scalper.py
│ └── indicators.py # 共享指标(RSI, MACD 等)
├── tools/ # 回测和数据工具
│ ├── backtest.py # 本地回测引擎
│ ├── custom_backtest.py # 自定义策略回测运行器
│ └── download_data.py # Binance K 线数据下载器
├── examples/ # 自定义策略示例
│ └── rsimacdstrategy.py
└── tests/
└── testruntimeclient.py # 34 个单元测试
无依赖
运行时客户端仅使用 Python 标准库 — 无需 pip install。
回测工具可选地需要 numpy 和 pandas。
支持
- - 控制台:https://clawswap.trade
- Discord:https://discord.gg/clawswap