Get the FREE Ultimate OpenClaw Setup Guide →
S

Bybit Futures

Verified

@Sunnyztj

npx machina-cli add skill @Sunnyztj/bybit-futures --openclaw
Files (1)
SKILL.md
3.4 KB

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.pyconfig.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.

# 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

Source

git clone https://clawhub.ai/Sunnyztj/bybit-futuresView on GitHub

Overview

A complete trading infrastructure for Bybit USDT perpetual futures, with risk management, paper trading, and live execution. It supports EMA crossover and RSI mean reversion strategies, backtesting, and a WebSocket-based real-time engine for fast, resilient trading.

How This Skill Works

Config.py stores API keys and risk parameters, while risk_manager.py enforces position sizing, daily loss limits, max positions, and leverage. The paper_trading_ws.py and live_trading.py implement the trading logic against Bybit via WebSocket v5; backtest.py provides historical testing. The WebSocket engine subscribes to tickers and klines, auto-reconnects on disconnect, and persists state every 5 minutes.

When to Use It

  • Building a crypto futures trading bot that connects to Bybit USDT perpetual futures
  • Implementing stop-loss, take-profit, leverage, and position sizing in a Bybit-based strategy
  • Testing strategies with paper trading before going live
  • Backtesting EMA crossover or RSI mean-reversion signals on crypto assets
  • Deploying a WebSocket-based real-time trading system on a VPS with notifications

Quick Start

  1. Step 1: pip install ccxt websockets numpy requests
  2. Step 2: Copy scripts/config_template.py → config.py and fill in API keys and risk parameters
  3. Step 3: Run paper trading: python scripts/paper_trading_ws.py (then switch to live_trading.py after validation)

Best Practices

  • Tune risk parameters in config.py to match your capital (e.g., max position %, max leverage, SL/TP)
  • Always run paper_trading_ws.py first to validate logic before enabling live_trading.py
  • Backtest EMA/Rsi strategies on multiple assets and timeframes to ensure robustness
  • Enable Telegram notifications and monitor position events, errors, and summaries
  • Rely on WebSocket v5 feeds with proper subscriptions and use the 5-minute state persistence for resilience

Example Use Cases

  • ETH/USDT 1h EMA crossover bot with default risks
  • SOL/USDT RSI mean reversion on 1h timeframe
  • Bybit USDT perpetual futures bot deployed via systemd on a VPS with Telegram alerts
  • Paper trading workflow using WebSocket real-time data before live trades
  • Backtesting and deploying custom strategies via references/custom_strategy.md

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers