README
Source: /app/README.md
Binance Bot
Python Binance Spot trading bot with a Flask dashboard, SQLite trade journal, backtesting, and an optional ML-assisted V7 decision layer.
Version
- Current version:
V7 - Strategy core: rule-based SMA + RSI + regime/scoring engine
- ML role: optional second-stage trade quality filter and score booster
- Dashboard port:
8081 - Deployment target: Docker / Synology NAS compatible
Sitemap
Project root:
Application modules:
app/bot.pyapp/dashboard.pyapp/backtest.pyapp/train_model.pyapp/strategy.pyapp/risk.pyapp/scanner.pyapp/tracker.pyapp/state.pyapp/feature_engineering.pyapp/ml_model.pyapp/decision_fusion.pyapp/market_regime.pyapp/signal_ranker.pyapp/symbol_stats.pyapp/config_validator.pyapp/indicators.pyapp/alerts.pyapp/env_utils.py
Main live trading loop.
Flask dashboard and /health endpoint.
Rule-only and ML-assisted backtesting.
CLI training entrypoint for the V7 ML model.
Rule-based entry/exit logic, multi-timeframe checks, regime-aware exits.
Risk sizing, exposure caps, duplicate setup protection.
Symbol universe filtering and candidate scanning.
SQLite schema, migrations, journal queries, backtest/model registry.
JSON runtime state, opportunities, rejections.
Shared market/setup feature extraction for live and backtest.
Local model loading, training, inference, metadata.
Rule score + ML score fusion logic.
Explainable regime classification.
Deterministic internal scoring engine.
Symbol memory and performance penalties.
Startup validation.
Technical indicators and volatility helpers.
Telegram notifications.
Shared .env loading helper.
Version Notes
V6.5
- Multi-timeframe confirmation
- Explainable market regime detection
- Deterministic internal scoring/confidence engine
- Adaptive risk sizing
- ATR-style dynamic stops and targets
- Symbol memory and loss-streak protection
- Improved dashboard and trade journal
V7
- ML-assisted feature extraction
- Historical label generation from SQLite trades
- Local model training pipeline
- Optional ML inference layer for live bot and backtest
- Decision fusion between rule engine and ML score
- Dashboard sections for ML model status and ML decisions
How It Works
- The scanner finds eligible symbols.
- The rule engine in
app/strategy.pyevaluates entry quality. - V7 feature extraction builds a structured snapshot.
- If ML is enabled and a trained model exists, the ML layer scores the setup.
- Decision fusion combines rule score and ML score.
- Risk management sizes the trade.
- Trades, signals, features, and equity are stored in SQLite and JSON state files.
Running
Install dependencies locally:
pip install -r requirements.txt
Run the live bot:
python app/bot.py
Run the dashboard:
python app/dashboard.py
Open:
http://localhost:8081
Backtesting
Rule-only mode:
python app/backtest.py --symbol BTCUSDT --days 90 --mode rule
ML-assisted mode:
python app/backtest.py --symbol BTCUSDT --days 90 --mode ml
Training the V7 ML Model
Important:
- The model only trains on V7 trades that have stored
feature_snapshotdata. - Old trades from earlier versions are not enough unless they were logged with V7 feature snapshots.
- If no trained model exists, the bot safely falls back to rule-only behavior.
Recommended process:
- Run the V7 bot and collect completed trades.
- Make sure trades are being logged with feature snapshots.
- Install dependencies:
pip install -r requirements.txt
- Train the model:
python app/train_model.py
Optional training flags:
python app/train_model.py --lookback-days 365 --min-samples 50
python app/train_model.py --label-mode binary
python app/train_model.py --model-path /data/models/trade_quality_model.pkl
Training output includes:
- model version
- training sample count
- metrics
- top feature importances
After training:
- Set
ML_ENABLED=trueinapp/.env - Restart the bot and dashboard
- Review the ML section in the dashboard
- Compare rule-only vs ML backtests before trusting live filtering
Minimum ML Readiness
Suggested minimum before enabling live ML filtering:
50-100completed V7 trades: enough to experiment100-200completed V7 trades: reasonable for paper testing200+completed V7 trades: better for serious evaluation
Quality matters more than count:
- include winners and losers
- include multiple symbols
- include multiple market regimes
- avoid training only on one narrow market phase
Main Data Files
- SQLite DB:
data/trades.db - Runtime status:
data/status.json - Open positions:
data/positions.json - Signals cache:
data/signals.json - Opportunities cache:
data/opportunities.json - Rejections cache:
data/rejections.json - Logs:
logs/bot.log
Key Environment Areas
See app/.env for:
- Binance / mode settings
- strategy and timeframe settings
- regime/scoring settings
- risk settings
- dashboard settings
- ML settings
Docker
Rebuild after dependency changes:
docker compose build --no-cache
docker compose up -d
Safety Notes
- ML does not place trades by itself.
- Hard risk limits remain rule/risk managed.
- If the model is missing or inference fails, the bot continues in rule-only fallback mode.
- Never commit real secrets from
.env.