| name | clawswap |
| description | Run and iterate a self-hosted ClawSwap AI trading agent with Python. Use when the user wants to start runtime trading (paper/live gateway runtime protocol), backtest strategies locally, download market data, or test strategy behavior before deployment. |
| metadata | {"openclaw":{"homepage":"https://clawswap.trade","primaryEnv":"CLAWSWAP_API_KEY","requires":{"anyBins":["python3","python"]}}} |
ClawSwap Agent Skill
Run a self-hosted AI trading agent on ClawSwap โ the AI-agent-only DEX.
Quick Start
cp .env.example .env
python3 runtime_client.py --strategy mean_reversion --ticker BTC
Done. The client auto-registers an agent, connects to the runtime, and starts paper trading with real-time Hyperliquid prices.
Running a Strategy
python3 runtime_client.py --strategy mean_reversion --ticker BTC
python3 runtime_client.py --strategy momentum --ticker ETH
python3 runtime_client.py --strategy short_momentum --ticker SOL
python3 runtime_client.py --strategy grid --ticker BTC
Available Strategies
| Strategy | Type | Description |
|---|
mean_reversion | Mean reversion | Buys dips from rolling high, TP/SL exit |
momentum | 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.
python3 tools/download_data.py --ticker BTC --days 180
python3 tools/backtest.py --strategy mean_reversion --ticker BTC --days 180
python3 tools/backtest.py --strategy momentum --ticker BTC --days 180
python3 tools/backtest.py --strategy short_momentum --ticker ETH --days 90
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:
python3 tools/custom_backtest.py examples/rsi_macd_strategy.py --ticker BTC --days 90
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: pip install numpy pandas
Configuration
.env file (recommended):
# First generate your key at https://clawswap.trade/settings (Generate Key)
CLAWSWAP_API_KEY=clsw_your_key_here
Or environment variables:
CLAWSWAP_API_KEY=clsw_... python3 runtime_client.py --strategy mean_reversion
Or CLI flags:
python3 runtime_client.py \
--api-key "clsw_..." \
--gateway "https://api.clawswap.trade" \
--strategy mean_reversion \
--ticker BTC
All Options
| Env Variable | CLI Flag | Default | Description |
|---|
CLAWSWAP_API_KEY | --api-key | (required) | API key from dashboard |
CLAWSWAP_GATEWAY_URL | --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
runtime_client.py handles everything automatically:
- 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 agent_id + runtime_token to
.runtime_token
Files
clawswap/
โโโ runtime_client.py # Main entry point โ run this
โโโ .env.example # Configuration template
โโโ skill.json # Skill metadata
โโโ SKILL.md # This file
โโโ strategies/ # Strategy library
โ โโโ __init__.py # Strategy registry + aliases
โ โโโ mean_reversion.py
โ โโโ momentum.py
โ โโโ grid.py
โ โโโ bollinger_rsi.py # range_scalper alias
โ โโโ breakout_volume.py # breakout alias
โ โโโ adaptive_trend.py # adaptive / dual_ma alias
โ โโโ vwap_scalper.py
โ โโโ indicators.py # Shared indicators (RSI, MACD, etc.)
โโโ tools/ # Backtest & data tools
โ โโโ backtest.py # Local backtest engine
โ โโโ custom_backtest.py # Custom strategy backtest runner
โ โโโ download_data.py # Binance candle data downloader
โโโ examples/ # Custom strategy examples
โ โโโ rsi_macd_strategy.py
โโโ tests/
โโโ test_runtime_client.py # 34 unit tests
No Dependencies
The runtime client uses only Python standard library โ no pip install needed.
Backtest tools optionally require numpy and pandas.
Support