A starter template for a self-learning crypto trading bot.
Includes Python backend scripts for data ingestion, feature engineering, a simple ML model (Random Forest), a self-learning loop, backtesting utilities, sample reports, and a minimal web placeholder.
This is a template- you'll need to add your own API keys and tweak strategies before using with real money.
- Fetch OHLCV via CCXT (script stub)
- Compute common technical indicators (RSI, SMA, EMA)
- Train a simple supervised ML model (RandomForest) to predict short-term movement
- Simple self-learning loop that simulates trades and updates the model
- Backtesting metrics and sample JSON report
- GitHub Actions workflow for scheduled runs
- Create a Python virtualenv:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt-
Edit
.env(create from.env.example) with your keys and config. -
Run a backtest (sample):
python -m src.bot --symbol BTC/USDT --timeframe 1h --mode backtest- Run live (VERY RISKY - only after testing):
python -m src.bot --symbol BTC/USDT --timeframe 1h --mode papercrypto-self-learning-bot/
├─ src/
│ ├─ data.py
│ ├─ features.py
│ ├─ model.py
│ ├─ bot.py
├─ config/
│ └─ bot.config.json
├─ reports/
│ └─ sample-report.json
├─ web/
│ └─ README.md
├─ .github/workflows/daily-bot.yml
├─ .env.example
├─ requirements.txt
└─ README.md
- This template is educational. Do not use with real funds until thoroughly tested.
- Trading cryptocurrencies involves substantial risk.
A full-stack crypto strategy lab with a Python backtest engine and a production-style Next.js dashboard.
This project gives you a complete loop:
- load market data,
- engineer technical features,
- train a model,
- run a trading simulation,
- persist metrics/history,
- and visualize everything in a polished web app.
- Data layer for sample CSV and live exchange OHLCV via
ccxt. - Feature engineering pipeline (
SMA,EMA,RSI,MACD, returns). - Supervised model wrapper (
RandomForestClassifier). - Backtesting engine with long-only execution logic.
- Rich report generation with:
- final equity,
- return vs buy/hold,
- max drawdown,
- Sharpe,
- Calmar,
- trade count, win rate, exposure.
- Persistent artifacts:
reports/sample-report.json(latest run),reports/backtest-history.jsonl(run archive),reports/latest-equity-curve.csv(chart-ready time series),reports/model.joblib(optional saved model).
- Executive dashboard with branded layout and visuals.
- KPI cards, equity curve chart, market context chart, and recent run table.
- Server-side data loading from backend artifacts.
- API routes for integration:
GET /api/reportGET /api/configGET /api/historyGET /api/equity
src/data.pydata loading (CSV + exchange)src/features.pyindicators and feature columnssrc/model.pyML training/inference wrappersrc/bot.pyCLI entrypoint and report pipelineconfig/bot.config.jsondefault strategy/runtime settingsreports/generated run artifactsweb/Next.js dashboard
python3 -m venv .venv
./.venv/bin/pip install -r requirements.txtRun a backtest:
./.venv/bin/python -m src.bot --mode backtest --save_modelThe command updates:
reports/sample-report.jsonreports/backtest-history.jsonlreports/latest-equity-curve.csvreports/model.joblib(when--save_modelis used)
cd web
npm install
npm run devOpen http://localhost:3000.
Production build:
npm run build
npm run startMain command:
./.venv/bin/python -m src.bot --mode backtest [options]Important options:
--symboltrading pair (defaultBTC/USDT)--timeframecandle timeframe (default1h)--initial_balancestarting capital (default10000)--fee_ratetransaction fee per trade (default0.001)--predict_horizontarget horizon in candles--data_modesampleorexchange--data_pathcustom CSV path when using sample mode--exchange_nameexchange id for ccxt (defaultbinance)--limitOHLCV row limit in exchange mode--report_dirartifact output directory (defaultreports)--save_modelpersist model to disk--model_pathmodel output path (defaultreports/model.joblib)
./.venv/bin/python -m src.bot \
--mode backtest \
--data_mode exchange \
--exchange_name binance \
--symbol BTC/USDT \
--timeframe 1h \
--limit 1200 \
--save_modelThis software is for research and education. It is not investment advice. Crypto trading is high risk. Do not deploy with real capital without robust validation, controls, and monitoring.
See LICENSE.
(Resolve merge conflicts and fix bot syntax error)
