A simplified trading bot for Binance USDT-M Futures Testnet with a supervised ML signal (RandomForest), ATR-based risk overlay, CLI for train/backtest/live, exchange filter alignment, and full logging.
- Market and Limit orders on Futures Testnet (USDT-M) with optional STOP_MARKET protective exit.
- CLI subcommands: train, backtest, live.
- ML signal from OHLCV features; ATR-based position sizing and stops.
- Logging of request payloads, responses, and errors to bot.log.
- Python 3.9+.
- pip install -r requirements.txt
Create .env in the project root: BINANCE_API_KEY=xxx BINANCE_API_SECRET=yyy
text Do not commit .env; it is gitignored.
15m model: python main.py --symbol BTCUSDT --interval 15m --limit 1500 train
text
Example: python main.py --symbol BTCUSDT --interval 15m --limit 1500 backtest --model models/BTCUSDT_15m.joblib --threshold 0.80 --atr-n 14 --atr-mult 3.0 --risk-usdt 2
text
Continuous loop with protective stop: python main.py --symbol BTCUSDT --interval 15m --limit 500 live --model models/BTCUSDT_15m.joblib --threshold 0.80 --atr-n 14 --atr-mult 3.0 --risk-usdt 2 --protect-stop --leverage 10 --margin ISOLATED --loop --sleep 60
text
. ├── main.py ├── trading/ │ ├── bot.py │ ├── strategy.py │ └── utils.py ├── models/ │ └── BTCUSDT_15m.joblib (generated) ├── requirements.txt ├── .env (local only) ├── .gitignore └── bot.log (generated at runtime)
- Uses Binance Futures Testnet base URL under the hood when --no-testnet is not set.
- Expect Testnet fills/latency to differ from production; this is for mock trading only.
- If install issues occur, ensure scikit-learn (not sklearn) is installed in the selected interpreter and that .env is loaded.
- If backtest shows NaNs, ensure ATR warm-up handling is in place as in main.py.