home / skills / openclaw / skills / bybit-futures

bybit-futures skill

/skills/sunnyztj/bybit-futures

This skill helps you build and operate a Bybit USDT perpetual futures trading system with risk controls, paper trading, backtesting, and WebSocket live

npx playbooks add skill openclaw/skills --skill bybit-futures

Review the files below or copy the command above to add this skill to your agents.

Files (9)
SKILL.md
3.4 KB
---
name: bybit-futures
description: Complete Bybit USDT perpetual futures trading system with risk management, paper trading, and live execution. Use when building a crypto futures trading bot, connecting to Bybit API, implementing stop-loss/take-profit, managing leverage and position sizing, paper trading strategies, backtesting, or deploying a WebSocket-based real-time trading system. Supports EMA crossover, RSI, and custom strategy templates.
---

# Bybit Futures Trading System

Complete trading infrastructure for Bybit USDT perpetual futures contracts.

## Quick Start

1. Install dependencies: `pip install ccxt websockets numpy requests`
2. Copy `scripts/config_template.py` → `config.py`, fill in API keys
3. Run paper trading: `python scripts/paper_trading_ws.py`
4. When validated, switch to live: `python scripts/live_trading.py`

## Architecture

```
config.py          ← API keys + risk parameters
risk_manager.py    ← Position sizing, daily loss limits, max positions
paper_trading_ws.py ← WebSocket real-time paper trading
live_trading.py    ← Live execution (same logic, real orders)
backtest.py        ← Historical backtesting engine
```

## Risk Management

All trades enforced by `risk_manager.py`:
- **Max position**: configurable % of capital per trade (default 20%)
- **Max leverage**: configurable (default 5x)
- **Stop loss**: automatic per-trade (default 3%)
- **Take profit**: automatic per-trade (default 6%, 2:1 R/R)
- **Daily loss limit**: halt trading after X% daily drawdown (default 10%)
- **Max concurrent positions**: configurable (default 3)

## Included Strategies

### EMA Crossover (ETH)
- EMA(12) crosses above EMA(26) → long
- EMA(12) crosses below EMA(26) → short
- Best on: ETH/USDT 1h timeframe

### RSI Mean Reversion (SOL, HYPE, PEPE)
- RSI(14) crosses up from below 30 → long
- RSI(14) crosses down from above 70 → short
- Best on: SOL, HYPE (73% WR), 1000PEPE (53% WR) 1h timeframe
- Backtested: HYPE +$339, PEPE +$210 on 90-day 1h data

### Custom Strategy Template
See `references/custom_strategy.md` for adding your own signals.

## WebSocket Real-Time Engine

The paper/live trading engine uses Bybit's WebSocket v5 API:
- **Ticker subscription**: millisecond-level price updates for SL/TP
- **Kline subscription**: signal calculation on candle close only
- **Auto-reconnect**: 5s retry on disconnect
- **State persistence**: saves every 5 minutes to JSON

## Deployment

Recommended: systemd service on a VPS.

```bash
# Create service file
sudo tee /etc/systemd/system/paper-trading.service << 'EOF'
[Unit]
Description=Paper Trading Bot (WebSocket)
After=network.target

[Service]
Type=simple
WorkingDirectory=/root/trading
ExecStart=/usr/bin/python3 paper_trading_ws.py
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable --now paper-trading
```

## Telegram Notifications

Built-in Telegram push for all events:
- Position opened/closed
- Stop loss / take profit hit
- 6-hourly summary reports
- Error alerts

Set `TG_BOT_TOKEN` and `TG_CHAT_ID` in config.

## Files

- `scripts/config_template.py` — Configuration template
- `scripts/risk_manager.py` — Risk management engine
- `scripts/paper_trading_ws.py` — WebSocket paper trading bot
- `scripts/live_trading.py` — Live trading bot
- `scripts/backtest.py` — Backtesting engine
- `references/custom_strategy.md` — Guide for adding custom strategies
- `references/bybit_api_notes.md` — Bybit API gotchas and tips

Overview

This skill is a complete Bybit USDT perpetual futures trading system for building, testing, and running automated crypto futures strategies. It includes paper trading, live execution, risk management, WebSocket real-time data, and common strategy templates (EMA crossover, RSI mean reversion). Use it to prototype, backtest, and deploy production trading bots with configurable risk controls and Telegram alerts.

How this skill works

The system connects to Bybit via WebSocket v5 for millisecond tick data and candle feeds, computing signals only on closed candles while using ticks for precise stop-loss/take-profit management. Core modules include a risk manager for position sizing and limits, a paper-trading engine that mirrors live logic, a live execution module that places real orders, and a backtester for historical validation. State persistence and auto-reconnect keep the engine resilient, and Telegram notifications report events and errors.

When to use it

  • Building a crypto futures trading bot that targets Bybit USDT perpetuals
  • Validating strategies in paper trading before risking capital
  • Implementing strict risk rules: max position, leverage, stop-loss, daily drawdown
  • Backtesting strategies on historical 1h data (EMA/RSI templates provided)
  • Deploying a WebSocket-based real-time execution system with persistence and alerts

Best practices

  • Start in paper trading and validate signals, sl/ tp behavior, and state persistence
  • Configure conservative default risk settings (lower leverage, smaller position %) and tune after live performance
  • Run backtests over multiple market regimes before live deployment
  • Use systemd or another process manager for reliable uptime and auto-restarts
  • Keep API keys and Telegram credentials secure; rotate keys and limit permissions

Example use cases

  • Run EMA(12,26) crossover on ETH/USDT 1h as a live trading strategy with automatic SL/TP and size control
  • Backtest RSI(14) mean-reversion on SOL and alternative tokens to measure edge and win rate
  • Prototype a custom strategy using the provided template, validate in paper trading, then switch to live execution
  • Deploy the paper trading WebSocket service on a VPS with systemd for continuous monitoring and Telegram alerts
  • Enforce daily drawdown and max concurrent positions across multiple symbols to protect capital

FAQ

Can I modify or add custom strategies?

Yes. A custom strategy template and guidance are included; plug your signal logic into the strategy module and use the same risk and execution pipelines for testing and deployment.

Is switching from paper to live safe?

The live module mirrors paper-trading logic so behavior should match if config and API credentials are set correctly. Always run end-to-end checks with small sizes and maintain conservative risk limits when first going live.