Skip to content

Repository files navigation

cryptobot

An automated crypto day-trading system, built in phases. This repo contains Phase 1 (backtesting engine) and Phase 2 (live paper trading with Discord alerts) — because no strategy touches real money until it has proven itself twice: on historical data, then on live data with fake money.

Quickstart

pip install pandas numpy

# 1. Smoke-test the machinery on synthetic data
python run_backtest.py

# 2. Get real data (needs internet access to the exchange)
pip install ccxt
python fetch_data.py BTC/USDT 15m 365

# 3. Backtest on real data
python run_backtest.py BTC_USDT_15m.csv

Outputs: a report to stdout, plus trades.csv and equity_curve.csv.

Phase 2 — paper trade against live prices

pip install -r requirements.txt

# 1. Verify the machinery (no network needed — replays bundled real data)
python paper_selftest.py

# 2. Optional: Discord alerts.
#    Discord -> Server Settings -> Integrations -> Webhooks -> New Webhook -> Copy URL
export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."

# 3. Go live (paper money, real prices)
python paper_trader.py            # BTC/USD on Kraken by default
python paper_trader.py ETH/USD    # any pair, runs as its own instance

The paper account persists across restarts (paper_state.json) — delete it to start fresh. Default exchange is Kraken (edit PaperConfig in config.py); public market data needs no account or API key. Keep it running on an always-on machine: nohup python paper_trader.py &, tmux, a Raspberry Pi, or a free-tier cloud VM.

Architecture

config.py          all tunable parameters (strategy, risk, costs)
indicators.py      EMA, RSI, MACD, ATR — pure pandas
strategy.py        indicators -> entry/exit signals (EMA cross + RSI + volume)
risk.py            position sizing, ATR stops, daily loss circuit breaker
backtest.py        bar-by-bar engine + metrics + report
synthetic_data.py  fake OHLCV for testing the machinery only
fetch_data.py      real OHLCV via ccxt (run on your own machine)
run_backtest.py    entry point
tune.py            parameter sweep with a train/validation split
alerts.py          Discord webhook alerts (entries, exits, daily summaries)
paper_trader.py    Phase 2 — live paper trading loop (REST polling)
paper_selftest.py  replays bundled data through the live code path
requirements.txt   dependencies
BTC_USD_15m.csv    18 months of real Bitstamp BTC/USD (resampled from 1m)

Try the sweep yourself: python tune.py BTC_USD_15m.csv — it tunes on the first 70% of the data and evaluates the winner on the last 30% it never saw, which is the minimum honest way to pick parameters.

Data flows one way: OHLCV -> strategy -> signals -> risk -> backtest -> report. The backtester only depends on three columns from the strategy (entry_signal, exit_signal, atr), so you can swap in any strategy that produces them.

Why you can (mostly) trust the numbers

  • No lookahead bias — signals evaluate on a bar's close, orders fill at the next bar's open.
  • Conservative intrabar fills — if a stop and a take-profit were both reachable in one candle, the stop is assumed to hit first.
  • Costs are real — every fill pays 0.1% fees and 0.05% slippage. Edit BacktestConfig to match your actual exchange tier.
  • Risk is enforced — 1% risk per trade via ATR-based stops, 25% max position, and a -3% daily circuit breaker that force-flattens and halts.

What backtests still can't protect you from: overfitting (tuning parameters until history looks good), regime change, and exchange outages. Test out-of-sample: tune on one time period, validate on another you never touched.

Roadmap

  • Phase 1 — backtesting engine
  • Phase 2 — paper trading: live prices, simulated fills, Discord alerts — same strategy/risk code as the backtester
  • Phase 3 — live execution: real orders through ccxt, kill switch, monitoring dashboard

Disclaimer

This is educational software. Crypto day trading is high-risk and most automated retail strategies lose money after costs. Nothing here is financial advice; never trade money you can't afford to lose.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages