Files

Paper Trading Bot

A real-time paper trading bot that executes trades based on signals from the multi-personality signal generator.

Features

  • Real-time TUI Interface - Beautiful terminal UI showing all trading activity
  • Multi-personality Support - Trade signals from both scalping and swing strategies
  • Risk Management - Configurable stop-loss, take-profit, and position sizing
  • SQLite Tracking - All trades stored in database for analysis
  • Live Price Monitoring - Reads current BTC price from candles.db
  • Signal Filtering - Filter by confidence, personality, and timeframe

Installation

cd traider
pip install -r requirements.txt

Configuration

Edit config.json to customize:

{
  "initial_balance": 10000.0,        // Starting capital
  "position_size_percent": 2.0,      // % of balance per trade
  "max_positions": 3,                // Max concurrent positions
  "stop_loss_percent": 2.0,          // Stop loss %
  "take_profit_percent": 4.0,        // Take profit %
  "min_confidence": 0.5,             // Minimum signal confidence
  "enabled_personalities": ["scalping", "swing"],
  "enabled_timeframes": ["1m", "5m"]
}

Usage

Make sure the signal generator is running first:

# In signals/ directory
./signals.py

Then start the paper trader:

# In traider/ directory
./trader.py

TUI Interface

The TUI displays:

  • Header: Current BTC price, balance, equity, and total PnL
  • Statistics: Win rate, total trades, wins/losses
  • Open Positions: Live view of active trades with unrealized PnL
  • Recent Closed Trades: Last 10 completed trades
  • Recent Signals: Incoming signals from the generator

Database Schema

trades table

  • Trade details (entry/exit prices, type, timeframe)
  • PnL calculations
  • Signal confidence and personality
  • Exit reasons (Stop Loss, Take Profit)

balance_history table

  • Historical balance snapshots
  • Equity tracking over time

Trading Logic

  1. Signal Reception: Listens to Unix socket from signal generator
  2. Filtering: Applies confidence, personality, and timeframe filters
  3. Position Sizing: Calculates position based on balance %
  4. Entry: Opens LONG (BUY signal) or SHORT (SELL signal) position
  5. Exit Monitoring: Continuously checks stop-loss and take-profit levels
  6. Closure: Calculates PnL and updates balance

Risk Management

  • Maximum concurrent positions limit
  • Stop-loss protection on every trade
  • Position sizing based on account balance
  • (Future: Daily loss limits, trailing stops)

Keyboard Controls

  • Ctrl+C - Graceful shutdown (closes socket connections, saves state)

File Structure

traider/
├── trader.py           # Main bot with TUI
├── config.json         # Configuration
├── trades.db          # Trade history (auto-created)
├── requirements.txt   # Python dependencies
└── logs/              # (Future: logging)

Example Output

┌─────────────────────────────────────────────────────────┐
│ PAPER TRADING BOT | BTC: $95,234.50 | Balance: $10,245.32 │
│ Equity: $10,387.12 | PnL: +$387.12 (+3.87%)              │
└─────────────────────────────────────────────────────────┘

┌─────────────┐  ┌──────────────────────────┐
│ Statistics  │  │ Open Positions (2)       │
├─────────────┤  ├──────────────────────────┤
│ Total: 47   │  │ ID  Type  Entry  PnL     │
│ Wins: 28    │  │ 48  LONG  95100  +$142   │
│ Losses: 19  │  │ 49  LONG  95200  +$34    │
│ Win Rate: 60%│ └──────────────────────────┘
└─────────────┘

Notes

  • This is paper trading only - no real money involved
  • Requires running signal generator and populated candles.db
  • Price updates every 1 second from most recent candle
  • Signals processed in real-time as they arrive

Future Enhancements

  • Trailing stop-loss implementation
  • Daily loss limit enforcement
  • Performance analytics dashboard
  • Export trade history to CSV
  • Backtesting mode
  • Web dashboard option