Skip to content

makverip/quant-traders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Trade Bot (SMC Core)

This project implements the core of a trading bot based on the Smart Money Concepts (SMC) strategy.

Project Structure

  • 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).

Installation

  1. Create a virtual environment:

    python -m venv venv
    .\venv\Scripts\activate
  2. Install dependencies:

    pip install -r requirements.txt
  3. Create a .env file (or copy .env.example if available) and add your keys:

    EXCHANGE_ID=binance
    API_KEY=your_key
    API_SECRET=your_secret
    IS_SANDBOX=True
    

Running

Start the server:

python src/main.py

The server will be available at http://localhost:8000.

For production (bot + API in a single run) use:

python run.py

Windows: 21-Day Autonomous Run (Task Scheduler)

Auto-start/auto-restart scripts are located in scripts/windows/:

  • start_bot.ps1 — starts python run.py in the background and saves the PID in logs/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-StartOnBoot
    • AITradeBot-Watchdog (every 2 minutes)
  • uninstall_tasks.ps1 — removes tasks.

1) One-Time Task Setup

Run PowerShell as Administrator:

Set-ExecutionPolicy -Scope Process Bypass
.\scripts\windows\install_tasks.ps1

If you need to explicitly specify Python from .venv:

.\scripts\windows\install_tasks.ps1 -PythonExe ".\.venv\Scripts\python.exe"

2) Manual Control

.\scripts\windows\start_bot.ps1
.\scripts\windows\stop_bot.ps1
.\scripts\windows\restart_bot.ps1

3) Verification After Reboot

  • Ensure there is a Python process (run.py) and a logs/bot.pid file.
  • Check the API: http://127.0.0.1:8000/api/stats.
  • Check the watchdog log: logs/watchdog.log.

4) Remove Tasks

.\scripts\windows\uninstall_tasks.ps1

API

  • GET /analyze/{symbol}: Get analysis and signal for a specific pair (e.g., BTC/USDT).
  • POST /scan: Start background scanning of all configured pairs.

Logging

Logs are written to logs/app.log.

ML Dataset and Training

  • The collector src/ml_data_collector.py only saves EXECUTE signals 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.8

Tuning L2/L3 Within API Limits

Available 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_KEY is 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 (default 0.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_enabled
  • l3_circuit_breaker_fg_threshold

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors