Crypto Trader Skill
Automated cryptocurrency trading with 8 strategies, multi-exchange support, AI sentiment analysis, and comprehensive risk management.
Important: By default all operations run against testnet (paper trading). Set CRYPTO_DEMO=false only when you are absolutely certain the user wants to trade with real money.
Prerequisites
Install dependencies once from the skill directory:
CODEBLOCK0
Required environment variables (set in .env or via OpenClaw settings):
- -
BINANCE_API_KEY and BINANCE_API_SECRET (required for Binance) - INLINECODE4 (default: paper trading mode)
Optional:
- -
BYBIT_API_KEY, BYBIT_API_SECRET (for Bybit) - INLINECODE7 ,
KRAKEN_API_SECRET (for Kraken) - INLINECODE9 ,
COINBASE_API_SECRET (for Coinbase) - INLINECODE11 ,
TELEGRAM_CHAT_ID (for Telegram alerts) - INLINECODE13 (for Discord alerts)
- INLINECODE14 (for sentiment analysis)
Available Modes
1. status -- Portfolio and strategy overview
CODEBLOCK1
Returns JSON with:
- - Portfolio value per exchange
- Active strategies and their state
- Risk status (daily P&L, drawdown, kill switch)
- Environment (paper/live)
Use when the user asks: "How is my portfolio?", "What's running?", "Give me an overview."
2. balance -- Check exchange balances
CODEBLOCK2
Returns balances for the specified exchange (or all exchanges). Shows total, free, and used amounts per asset.
Use when the user asks: "How much BTC do I have?", "What's my balance?", "Show my funds."
3. start_strategy -- Start a trading strategy
CODEBLOCK3
Supported strategies:
| Strategy | Name | Description |
|---|
| Grid Trading | INLINECODE15 | Buy/sell at evenly spaced price levels within a range |
| DCA |
dca | Buy fixed amounts at regular intervals |
| Trend Following |
trend_following | EMA crossover + RSI signals |
| Scalping |
scalping | Fast small trades on spread/momentum |
| Arbitrage |
arbitrage | Cross-exchange price difference exploitation |
| Swing Trading |
swing_trading | Bollinger Bands + MACD, hold 2-14 days |
| Copy Trading |
copy_trading | Replicate trades from tracked wallets/traders |
| Rebalancing |
rebalancing | Maintain target portfolio allocation |
Each strategy uses defaults from config/strategies.yaml which can be overridden via --params.
CRITICAL: Always confirm with the user before starting a strategy. Show the parameters clearly and ask for approval.
Use when the user asks: "Start grid trading on BTC", "I want to DCA into ETH", "Follow the trend on SOL."
4. stop_strategy -- Stop a running strategy
CODEBLOCK4
Stops a specific strategy instance. The strategy ID is returned when starting and shown in the list.
5. list_strategies -- List all strategies
CODEBLOCK5
Returns all available and running strategies with their status, parameters, and performance stats.
6. backtest -- Test a strategy on historical data
CODEBLOCK6
Returns performance metrics:
- - Total return % vs buy-and-hold
- Win rate, trade count
- Max drawdown, Sharpe ratio
- Fee impact
- Individual order history
Results are saved to data/backtests/.
Use when the user asks: "Would grid trading have worked?", "Backtest DCA on ETH", "Test this strategy."
7. history -- Trade history
CODEBLOCK7
Returns completed orders from all exchanges for the last N days.
8. sentiment -- Market sentiment analysis
CODEBLOCK8
Analyzes sentiment from:
- - Crypto news RSS feeds (CoinTelegraph, CoinDesk)
- CryptoPanic (requires API key)
- Reddit (r/cryptocurrency, r/bitcoin)
- Twitter (requires bearer token)
Returns aggregate score (-1.0 to 1.0) with labels: verybearish, bearish, neutral, bullish, verybullish.
Use when the user asks: "What's the market sentiment?", "Is BTC bullish right now?", "Any news about ETH?"
9. monitor -- Real-time monitoring daemon
CODEBLOCK9
The monitoring daemon runs in the background and:
- - Checks open orders every 10 seconds
- Updates portfolio snapshot every 60 seconds
- Checks risk limits every 60 seconds
- Evaluates strategy signals every 5 minutes
- Runs sentiment analysis every 30 minutes
- Sends alerts via Telegram/Discord/Email
10. emergency_stop -- Kill switch
CODEBLOCK10
Immediately:
- 1. Cancels ALL open orders on ALL exchanges
- Stops ALL running strategies
- Activates the kill switch (blocks all future trades)
The kill switch must be manually deactivated before trading can resume.
Use when the user says: "Stop everything!", "Emergency!", "Kill all trades."
Configuration Files
config/exchanges.yaml
Exchange connectivity settings, sandbox mode, rate limits.
config/strategies.yaml
Default parameters for each strategy. Users can override via
--params.
config/risk_limits.yaml
Risk management rules:
- -
max_position_size_pct: Max portfolio % per position (default: 25%) - INLINECODE28 : Emergency stop on daily loss (default: 50 EUR)
- INLINECODE29 : Stop at drawdown from ATH (default: 15%)
- INLINECODE30 : Max per order (default: 100 EUR)
- INLINECODE31 : Max concurrent orders (default: 50)
- Stop-loss (fixed 5%, trailing 3%)
- Take-profit (10%, partial at 5%)
config/notifications.yaml
Alert routing rules per event type and channel.
Safety Rules
- 1. NEVER execute trades without explicit user confirmation in live mode.
- Default mode is paper trading (
CRYPTO_DEMO=true). Remind the user which mode is active. - API keys must have TRADE permissions only. NEVER withdrawal permissions.
- Risk limits are enforced automatically. If a limit is hit, explain to the user what happened.
- Emergency stop is always available and overrides everything.
- Always show estimated cost and risk before confirming a trade.
- If
CRYPTO_DEMO=false, warn the user clearly that this uses real money. - Log all actions. The user can review history at any time.
- When starting a strategy, show the full parameter set and ask for confirmation.
- Never bypass risk limits, even if the user asks. Explain why the limit exists.
Output Format
All modes return structured JSON to stdout. Parse it and present a human-readable summary to the user. Highlight important numbers (P&L, prices, risk metrics). Use clear formatting with tables where appropriate.
Running Tests
CODEBLOCK11
Troubleshooting
"Exchange not initialized"
Check that the API key and secret are set in environment variables for the target exchange.
"Authentication failed"
Verify your API keys are correct and not expired. For testnet, make sure you're using testnet keys.
"Rate limit reached"
The skill automatically retries with backoff. If persistent, reduce strategy evaluation frequency.
"Kill switch is active"
The emergency stop was triggered. Review what happened, then deactivate:
The kill switch state is stored in
~/.openclaw/.crypto-trader-risk-state.json. Set
"killed": false to reset, or use a future CLI command to deactivate.
加密货币交易技能
支持8种策略的自动化加密货币交易,多交易所支持,AI情绪分析,以及全面的风险管理。
重要提示:默认情况下,所有操作均在测试网(模拟交易)上运行。只有在您完全确定用户希望使用真实资金进行交易时,才设置CRYPTO_DEMO=false。
前置条件
从技能目录安装依赖项一次:
bash
pip install -r {baseDir}/requirements.txt
所需环境变量(在.env或通过OpenClaw设置):
- - BINANCEAPIKEY 和 BINANCEAPISECRET(Binance必需)
- CRYPTO_DEMO=true(默认:模拟交易模式)
可选:
- - BYBITAPIKEY、BYBITAPISECRET(用于Bybit)
- KRAKENAPIKEY、KRAKENAPISECRET(用于Kraken)
- COINBASEAPIKEY、COINBASEAPISECRET(用于Coinbase)
- TELEGRAMBOTTOKEN、TELEGRAMCHATID(用于Telegram提醒)
- DISCORDWEBHOOKURL(用于Discord提醒)
- CRYPTOPANICAPIKEY(用于情绪分析)
可用模式
1. status -- 投资组合和策略概览
bash
python3 {baseDir}/scripts/main.py --mode status
返回JSON包含:
- - 每个交易所的投资组合价值
- 活跃策略及其状态
- 风险状态(每日盈亏、回撤、紧急停止开关)
- 环境(模拟/实盘)
当用户询问时使用:我的投资组合怎么样?、什么在运行?、给我一个概览。
2. balance -- 查看交易所余额
bash
python3 {baseDir}/scripts/main.py --mode balance
python3 {baseDir}/scripts/main.py --mode balance --exchange binance
返回指定交易所(或所有交易所)的余额。显示每种资产的总量、可用量和已用量。
当用户询问时使用:我有多少BTC?、我的余额是多少?、显示我的资金。
3. start_strategy -- 启动交易策略
bash
python3 {baseDir}/scripts/main.py --mode startstrategy --strategy grid --params {symbol:BTC/USDT,pricerange:[90000,110000],numgrids:10,orderamount_usdt:10}
python3 {baseDir}/scripts/main.py --mode startstrategy --strategy dca --params {symbol:ETH/USDT,interval:daily,amountperbuyusdt:5}
python3 {baseDir}/scripts/main.py --mode start_strategy --strategy trend --params {symbol:BTC/USDT,timeframe:4h}
支持的策略:
| 策略 | 名称 | 描述 |
|---|
| 网格交易 | grid_trading | 在价格范围内以均匀间隔的价格水平买入/卖出 |
| 定投 |
dca | 按固定间隔买入固定金额 |
| 趋势跟踪 | trend_following | EMA交叉 + RSI信号 |
| 剥头皮 | scalping | 基于价差/动量的快速小额交易 |
| 套利 | arbitrage | 跨交易所价格差异利用 |
| 波段交易 | swing_trading | 布林带 + MACD,持有2-14天 |
| 跟单交易 | copy_trading | 复制追踪钱包/交易者的交易 |
| 再平衡 | rebalancing | 维持目标投资组合配置 |
每个策略使用config/strategies.yaml中的默认值,可通过--params覆盖。
关键:在启动策略前始终与用户确认。清晰显示参数并征求批准。
当用户询问时使用:在BTC上启动网格交易、我想定投ETH、跟踪SOL的趋势。
4. stop_strategy -- 停止运行中的策略
bash
python3 {baseDir}/scripts/main.py --mode stop_strategy --strategy-id
停止特定的策略实例。策略ID在启动时返回,并在列表中显示。
5. list_strategies -- 列出所有策略
bash
python3 {baseDir}/scripts/main.py --mode list_strategies
返回所有可用和运行中的策略及其状态、参数和性能统计。
6. backtest -- 在历史数据上测试策略
bash
python3 {baseDir}/scripts/main.py --mode backtest --strategy gridtrading --params {symbol:BTC/USDT,pricerange:[40000,50000],num_grids:10} --start 2025-01-01 --end 2025-12-31
python3 {baseDir}/scripts/main.py --mode backtest --strategy dca --params {symbol:BTC/USDT,interval:daily,amountperbuy_usdt:10} --start 2025-06-01 --end 2025-12-31
python3 {baseDir}/scripts/main.py --mode backtest --strategy trend_following --params {symbol:BTC/USDT,timeframe:4h} --start 2025-01-01 --end 2025-12-31
返回性能指标:
- - 总收益率% vs 买入持有
- 胜率、交易次数
- 最大回撤、夏普比率
- 费用影响
- 单个订单历史
结果保存到data/backtests/。
当用户询问时使用:网格交易会有效吗?、回测ETH的定投、测试这个策略。
7. history -- 交易历史
bash
python3 {baseDir}/scripts/main.py --mode history --days 7
python3 {baseDir}/scripts/main.py --mode history --days 30
返回过去N天来自所有交易所的已完成订单。
8. sentiment -- 市场情绪分析
bash
python3 {baseDir}/scripts/main.py --mode sentiment --symbol BTC
python3 {baseDir}/scripts/main.py --mode sentiment --symbol ETH
从以下来源分析情绪:
- - 加密货币新闻RSS源(CoinTelegraph、CoinDesk)
- CryptoPanic(需要API密钥)
- Reddit(r/cryptocurrency、r/bitcoin)
- Twitter(需要bearer token)
返回聚合评分(-1.0到1.0),带有标签:非常看跌、看跌、中性、看涨、非常看涨。
当用户询问时使用:市场情绪如何?、BTC现在看涨吗?、有关于ETH的消息吗?
9. monitor -- 实时监控守护进程
bash
python3 {baseDir}/scripts/main.py --mode monitor --action start
python3 {baseDir}/scripts/main.py --mode monitor --action status
python3 {baseDir}/scripts/main.py --mode monitor --action stop
监控守护进程在后台运行,并:
- - 每10秒检查未成交订单
- 每60秒更新投资组合快照
- 每60秒检查风险限制
- 每5分钟评估策略信号
- 每30分钟运行情绪分析
- 通过Telegram/Discord/Email发送提醒
10. emergency_stop -- 紧急停止开关
bash
python3 {baseDir}/scripts/main.py --mode emergency_stop
立即:
- 1. 取消所有交易所的所有未成交订单
- 停止所有运行中的策略
- 激活紧急停止开关(阻止所有未来交易)
在交易恢复前必须手动停用紧急停止开关。
当用户说时使用:停止一切!、紧急情况!、终止所有交易。
配置文件
config/exchanges.yaml
交易所连接设置、沙箱模式、速率限制。
config/strategies.yaml
每个策略的默认参数。用户可通过--params覆盖。
config/risk_limits.yaml
风险管理规则:
- - maxpositionsizepct:每个头寸的最大投资组合百分比(默认:25%)
- maxdailylosseur:每日亏损时的紧急停止(默认:50欧元)
- maxdrawdownpct:从历史最高点回撤时停止(默认:15%)
- maxordersizeeur:每笔订单最大金额(默认:100欧元)
- maxopen_orders:最大并发订单数(默认:50)
- 止损(固定5%,追踪3%)
- 止盈(10%,部分在5%)
config/notifications.yaml
按事件类型和渠道的提醒路由规则。
安全规则
- 1. 绝不在实盘模式下未经用户明确确认执行交易。
- 默认模式是模拟交易(CRYPTO_DEMO=true)。提醒用户当前处于哪种模式。
- API密钥必须只有交易权限。绝不有提现权限。
- 风险限制自动执行。如果达到限制,向用户解释发生了什么。
- 紧急停止始终可用并覆盖一切。
6.