Skip to content

Add live trading bot (paper/testnet/live modes)#6

Open
luaroncrew wants to merge 1 commit into
mainfrom
add-live-trading-bot
Open

Add live trading bot (paper/testnet/live modes)#6
luaroncrew wants to merge 1 commit into
mainfrom
add-live-trading-bot

Conversation

@luaroncrew
Copy link
Copy Markdown
Owner

Summary

Builds a production-ready automated trading bot on top of the existing vibetrader inference pipeline.

  • bot/db.py — SQLite layer for signals, trades, and positions (3 tables). Positions persist across restarts.
  • bot/live_bot.pyLiveTradingBot class wrapping the diffusion model → signal extraction pipeline with configurable risk management and three execution modes:
    • Paper (default): simulated portfolio, real market prices, no API keys needed
    • Testnet: real Binance testnet orders (BINANCE_TESTNET_API_KEY/SECRET)
    • Live: real Binance spot orders (BINANCE_API_KEY + BINANCE_API_SECRET)
  • bot/status.py — CLI status command showing open positions, recent signals/trades, and aggregate P&L

Key design decisions

  • Spot-only (no shorting): SELL signal closes an existing long, never opens a short — safe for Binance spot
  • Risk management: --position-size, --stop-loss, --take-profit, --min-confidence all configurable
  • Fixes hardcoded RSI/MACD bug in original trader.py (was RSI=50.0, MACD=0.0 always)
  • Handles both pixel (green_pct/red_pct) and Mistral (reasoning) signal flavors via getattr

Usage

# Paper trade BTC/USDT + ETH/USDT every 4h
python -m bot.live_bot --checkpoint checkpoints/ --pairs BTC/USDT ETH/USDT

# One-shot cycle
python -m bot.live_bot --checkpoint checkpoints/ --pairs BTC/USDT --once

# Live trading
BINANCE_API_KEY=... BINANCE_API_SECRET=... \
  python -m bot.live_bot --checkpoint checkpoints/ --pairs BTC/USDT --live

# Check status
python -m bot.status
python -m bot.status --json

Test plan

  • python3 -c "from bot.db import init_db; ..." smoke test passes ✅
  • Syntax check on all 3 files passes ✅
  • SQLite round-trip test (init → log → query) passes ✅
  • python -m bot.status --help renders correctly ✅
  • Manual paper trade cycle with real Binance OHLCV data
  • Live cycle on testnet with small position

🤖 Generated with Claude Code

- bot/db.py: SQLite layer for signals, trades, positions tables
- bot/live_bot.py: LiveTradingBot class wrapping the existing inference
  pipeline with configurable pairs, risk management (stop-loss/take-profit/
  position-sizing), and paper/testnet/live execution modes
- bot/status.py: CLI status command showing open positions, recent signals,
  recent trades, and aggregate P&L summary

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant