Files
DinQuant/backend_api_python
TIANHE d8e093bd60 new
Signed-off-by: TIANHE <TIANHE@GMAIL.COM>
2025-12-30 18:47:42 +08:00
..
new
2025-12-30 18:47:42 +08:00
2025-12-29 03:06:49 +08:00
2025-12-29 19:05:17 +08:00
new
2025-12-30 16:00:59 +08:00
new
2025-12-30 18:02:32 +08:00
new
2025-12-30 18:27:55 +08:00
2025-12-29 03:06:49 +08:00
2025-12-29 03:12:20 +08:00
2025-12-29 03:06:49 +08:00
2025-12-29 03:06:49 +08:00
2025-12-29 03:06:49 +08:00

QuantDinger Python API (backend)

Flask-based local-first backend for QuantDinger: market data, indicators, AI analysis, backtesting, and a strategy runtime (with an optional pending-order worker).

This repository is intentionally simple: no external database is required by default. Data is stored in a local SQLite file (quantdinger.db) created/updated automatically on startup.

What you get

  • Multi-market data layer: factory-based providers (crypto / US stocks / CN&HK stocks / futures, etc.)
  • Indicators + backtesting: persisted runs/history in SQLite
  • AI multi-agent analysis: optional web search + OpenRouter LLM integration
  • Strategy runtime: thread-based executor, with optional auto-restore on startup
  • Pending orders worker (optional): polls queued orders and dispatches signals (webhook/notifications)
  • Local auth (single-user): /login with env-configured admin credentials (JWT)

Project layout

backend_api_python/
├─ app/
│  ├─ __init__.py                 # Flask app factory + startup hooks
│  ├─ config/                     # Settings (env-driven)
│  ├─ data_sources/               # Data sources + factory
│  ├─ routes/                     # REST endpoints
│  ├─ services/                   # Analysis, agents, strategies, search, ...
│  └─ utils/                      # SQLite helpers, config loader, logging, HTTP utils
├─ env.example                    # Copy to .env for local config
├─ requirements.txt
├─ run.py                         # Entrypoint (loads .env, applies proxy env, starts Flask)
├─ gunicorn_config.py             # Optional production config
└─ README.md

Quick start (local development)

Prerequisites

  • Python 3.10+ recommended

1) Install dependencies

cd backend_api_python
pip install -r requirements.txt

2) Create your local .env

Windows (CMD):

copy env.example .env

Windows (PowerShell):

Copy-Item env.example .env

Then edit .env and set at least:

  • SECRET_KEY
  • ADMIN_USER
  • ADMIN_PASSWORD

Optional but common:

  • OPENROUTER_API_KEY (for AI analysis)
  • FINNHUB_API_KEY / SEARCH_GOOGLE_* / SEARCH_BING_API_KEY (for richer data/search)
  • PROXY_PORT or PROXY_URL (if your network blocks some providers)

3) Start the API server

python run.py

Default address: http://localhost:5000

Database (SQLite)

  • Default file: backend_api_python/quantdinger.db (override via SQLITE_DATABASE_FILE)
  • Tables are created/updated automatically on startup (see app/utils/db.py)
  • qd_addon_config exists for backward compatibility, but this backend reads secrets from .env / OS env, not from the database (see app/utils/config_loader.py)

Frontend integration (Vue dev server)

The Vue dev server proxies /api/* to this backend by default:

  • Frontend: http://localhost:8000
  • Backend: http://localhost:5000

Proxy config: quantdinger_vue/vue.config.js

Useful endpoints

GET  /health
POST /login
GET  /info
GET  /api/indicator/kline
POST /api/analysis/multi

Production (optional)

Gunicorn example:

gunicorn -c gunicorn_config.py "run:app"

Troubleshooting

  • If outbound data/search requests fail, configure PROXY_PORT (or PROXY_URL) in .env.
  • If you dont want strategies to auto-restore on startup, set DISABLE_RESTORE_RUNNING_STRATEGIES=true.
  • If you dont want the pending-order worker, set ENABLE_PENDING_ORDER_WORKER=false.

License

Apache License 2.0. See repository root LICENSE.