This project implements the core of a trading bot based on the Smart Money Concepts (SMC) strategy.
src/main.py: Entry point (FastAPI server).src/data_loader.py: Data loading from exchange (ccxt) and metrics calculation (ATR).src/smc_analysis.py: SMC logic (Swing Highs/Lows, BOS/ChoCh, FVG).src/signal_generator.py: Signal generation based on multi-timeframe analysis.src/models.py: Pydantic data models.config/settings.py: Configuration (API keys, trading pairs).
-
Create a virtual environment:
python -m venv venv .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile (or copy.env.exampleif available) and add your keys:EXCHANGE_ID=binance API_KEY=your_key API_SECRET=your_secret IS_SANDBOX=True
Start the server:
python src/main.pyThe server will be available at http://localhost:8000.
For production (bot + API in a single run) use:
python run.pyAuto-start/auto-restart scripts are located in scripts/windows/:
start_bot.ps1— startspython run.pyin the background and saves the PID inlogs/bot.pid.stop_bot.ps1— stops the process by PID.restart_bot.ps1— controlled restart.watchdog.ps1— checks PID + health endpoint (/api/stats) and restarts on failure.install_tasks.ps1— creates 2 Task Scheduler tasks:AITradeBot-StartOnBootAITradeBot-Watchdog(every 2 minutes)
uninstall_tasks.ps1— removes tasks.
Run PowerShell as Administrator:
Set-ExecutionPolicy -Scope Process Bypass
.\scripts\windows\install_tasks.ps1If you need to explicitly specify Python from .venv:
.\scripts\windows\install_tasks.ps1 -PythonExe ".\.venv\Scripts\python.exe".\scripts\windows\start_bot.ps1
.\scripts\windows\stop_bot.ps1
.\scripts\windows\restart_bot.ps1- Ensure there is a Python process (
run.py) and alogs/bot.pidfile. - Check the API:
http://127.0.0.1:8000/api/stats. - Check the watchdog log:
logs/watchdog.log.
.\scripts\windows\uninstall_tasks.ps1GET /analyze/{symbol}: Get analysis and signal for a specific pair (e.g.,BTC/USDT).POST /scan: Start background scanning of all configured pairs.
Logs are written to logs/app.log.
- The collector
src/ml_data_collector.pyonly savesEXECUTEsignals and appends the result when the trade closes. - Use only clean exits for training:
exit_clean == 1. - Split should be time-based only (old trades in train, new ones in validation), not random split.
- Minimum for serious conclusions: 500–1000 clean trades.
Dataset preparation before training:
python -m src.ml_training_pipeline --csv logs/ml_training_data.csv --min-clean 500 --train-ratio 0.8Available environment parameters for stable operation without 429:
L2_GEMINI_MODELS— L2 model cascade (example:gemini-3-flash,gemini-2.5-flash,gemini-2.5-flash-lite).GEMINI_API_KEYS— list of Gemini keys separated by comma for hot-failover (if empty,GEMINI_API_KEYis used).GEMINI_KEY_COOLDOWN_SECONDS— key cooldown after 429/quota/503.GEMINI_AUTH_ERROR_COOLDOWN_SECONDS— key cooldown after auth/permission errors.GEMINI_LOCAL_QUOTA_SOFT_LIMIT_PCT— local threshold (0..1) for proactive switching BEFORE 429 (default0.92).L2_RPM_PER_MODEL,L2_TPM_PER_MODEL— requests/tokens per minute for each L2 model.L2_MODEL_PARSE_COOLDOWN_SECONDS— L2 model cooldown after malformed/non-JSON response.L3_RPM_PER_MODEL,L3_TPM_PER_MODEL— requests/tokens per minute for each L3 model.L3_USE_ANTHROPIC_FALLBACK— whether to use Anthropic as the last fallback for L3.L3_MODEL_COOLDOWN_SECONDS— model cooldown after 429/RateLimit.L3_ANTHROPIC_CREDIT_COOLDOWN_SECONDS— cooldown for Anthropic when insufficient credit error.ALT_SCAN_CONCURRENCY— maximum concurrency for altcoin scanning.
For Data Mining mode, the L3 circuit breaker is already disabled, and the F&G threshold is also runtime-controlled:
l3_circuit_breaker_enabledl3_circuit_breaker_fg_threshold