# QuantDinger local configuration (copy to `.env` and edit)
# `run.py` will load `backend_api_python/.env` automatically if present.

# =========================
# Auth (local login)
# =========================
SECRET_KEY=quantdinger-secret-key-change-me
ADMIN_USER=quantdinger
ADMIN_PASSWORD=123456
ADMIN_EMAIL=

# =========================
# Demo Mode
# =========================
# Set to true to enable read-only mode for public demo.
# Blocks all POST/PUT/DELETE requests except login.
IS_DEMO_MODE=false

# =========================
# Network / App
# =========================
PYTHON_API_HOST=0.0.0.0
PYTHON_API_PORT=5000
PYTHON_API_DEBUG=False

# =========================
# Database Configuration (PostgreSQL)
# =========================
# PostgreSQL connection URL (required for multi-user mode)
# Format: postgresql://user:password@host:port/dbname
# Docker: uses this default, no changes needed
# Local: change 'postgres' to 'localhost' and update password
DATABASE_URL=postgresql://quantdinger:quantdinger123@postgres:5432/quantdinger

# =========================
# Pending orders worker (optional)
# =========================
# Paper mode default: disabled. If enabled, it will consume `pending_orders` and dispatch signals via webhook.
# Poll and dispatch orders from `pending_orders` (live/signal).
# Local mode default is enabled in code, but you can override here.
ENABLE_PENDING_ORDER_WORKER=true

# =========================
# Portfolio monitor (optional)
# =========================
# Background service that runs scheduled AI analysis on manual positions
# and sends notifications (email/telegram/browser).
# Default: enabled. Set to false to disable.
ENABLE_PORTFOLIO_MONITOR=true

# Reclaim orders stuck in status=processing after worker crashes (seconds).
PENDING_ORDER_STALE_SEC=90

# =========================
# Live trading order execution settings
# =========================
# Order execution mode:
#   - "maker": Limit order first, then market order for remaining (default, lower fees)
#   - "market": Market order only (immediate execution, higher fees)
ORDER_MODE=maker

# How long to wait for limit order to fill before switching to market order (seconds)
MAKER_WAIT_SEC=10

# Price offset for limit orders in basis points (1 bps = 0.01%)
# Buy orders: price = market_price * (1 - offset)
# Sell orders: price = market_price * (1 + offset)
MAKER_OFFSET_BPS=2

# =========================
# Strategy signal notifications (optional)
# =========================
# The frontend stores per-strategy notification_config.targets.*, but you can also set
# a global fallback webhook URL used when a strategy enables "webhook" channel but
# doesn't provide targets.webhook.
SIGNAL_WEBHOOK_URL=
SIGNAL_WEBHOOK_TOKEN=

# HTTP timeout for outbound notification requests (seconds).
SIGNAL_NOTIFY_TIMEOUT_SEC=6

# Telegram (required if you enable telegram channel)
TELEGRAM_BOT_TOKEN=

# Email / SMTP (required if you enable email channel)
SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASSWORD=
SMTP_FROM=
SMTP_USE_TLS=true
SMTP_USE_SSL=false

# Phone / SMS (optional; Twilio REST, required if you enable phone channel)
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_FROM_NUMBER=

# Restore strategies with status='running' on backend startup.
# Set to true to disable auto-restore.
DISABLE_RESTORE_RUNNING_STRATEGIES=false

# =========================
# Strategy execution loop (tick interval)
# =========================
# Default tick interval for strategy monitoring loop (seconds).
# The strategy thread will fetch current price and evaluate triggers once per tick.
STRATEGY_TICK_INTERVAL_SEC=10

# In-memory price cache TTL (seconds). Normally doesn't matter when tick interval is >= TTL.
PRICE_CACHE_TTL_SEC=10

# =========================
# Outbound Proxy (optional, recommended if your network blocks data providers)
# =========================
# If you use a local proxy (common ports: 7890/7891/10808), set PROXY_PORT only.
# Default scheme is socks5h and host is 127.0.0.1.
# For Docker deployment: set PROXY_HOST=host.docker.internal to access host's proxy
PROXY_PORT=
PROXY_HOST=127.0.0.1
PROXY_SCHEME=socks5h
PROXY_URL=

# You can also set standard variables directly (advanced):
# ALL_PROXY=socks5h://127.0.0.1:10808
# HTTP_PROXY=socks5h://127.0.0.1:10808
# HTTPS_PROXY=socks5h://127.0.0.1:10808

# Allow frontend dev server
CORS_ORIGINS=*

# Request rate limit (per minute)
RATE_LIMIT=100

ENABLE_CACHE=False
ENABLE_REQUEST_LOG=True
ENABLE_AI_ANALYSIS=True

# =========================
# Agent memory & reflection (optional)
# =========================
# Toggle agent memory usage in multi-agent analysis
ENABLE_AGENT_MEMORY=true

# Memory retrieval settings
AGENT_MEMORY_ENABLE_VECTOR=true
AGENT_MEMORY_EMBEDDING_DIM=256
AGENT_MEMORY_TOP_K=5
AGENT_MEMORY_CANDIDATE_LIMIT=500
AGENT_MEMORY_HALF_LIFE_DAYS=30
AGENT_MEMORY_W_SIM=0.75
AGENT_MEMORY_W_RECENCY=0.20
AGENT_MEMORY_W_RETURNS=0.05

# Automated verification loop (replaces cron)
ENABLE_REFLECTION_WORKER=false
REFLECTION_WORKER_INTERVAL_SEC=86400

# =========================
# OpenRouter / LLM
# =========================
OPENROUTER_API_KEY=
OPENROUTER_API_URL=https://openrouter.ai/api/v1/chat/completions
OPENROUTER_MODEL=openai/gpt-4o
OPENROUTER_TEMPERATURE=0.7
OPENROUTER_MAX_TOKENS=4000
OPENROUTER_TIMEOUT=300
OPENROUTER_CONNECT_TIMEOUT=30

# Optional: override model list shown in UI (JSON object: {"model_id":"Display Name", ...})
AI_MODELS_JSON={}

# =========================
# Market presets (optional)
# =========================
# Optional: override market types shown in UI (JSON array)
MARKET_TYPES_JSON=[]

# Optional: supported crypto symbols list (JSON array)
TRADING_SUPPORTED_SYMBOLS_JSON=[]

# =========================
# Data sources (Kline / pricing)
# =========================
DATA_SOURCE_TIMEOUT=30
DATA_SOURCE_RETRY=3
DATA_SOURCE_RETRY_BACKOFF=0.5

# Finnhub (US stocks / forex helpers depending on implementation)
FINNHUB_API_KEY=
FINNHUB_TIMEOUT=10
FINNHUB_RATE_LIMIT=60

# CCXT (crypto via Binance by default)
CCXT_DEFAULT_EXCHANGE=coinbase
CCXT_TIMEOUT=10000
CCXT_PROXY=

# Akshare (CN/HK stocks if enabled)
AKSHARE_TIMEOUT=30

# YFinance
YFINANCE_TIMEOUT=30

# Tiingo (optional)
TIINGO_API_KEY=
TIINGO_TIMEOUT=10

# =========================
# Web Search (optional)
# =========================
SEARCH_PROVIDER=google
SEARCH_MAX_RESULTS=10
SEARCH_GOOGLE_API_KEY=
SEARCH_GOOGLE_CX=
SEARCH_BING_API_KEY=

# Internal API key (optional, if you add internal-service auth later)
INTERNAL_API_KEY=

# =========================
# Registration & Security (注册与安全)
# =========================
# Enable user registration (允许用户注册)
ENABLE_REGISTRATION=true

# Cloudflare Turnstile (人机验证)
# Get your keys at: https://dash.cloudflare.com/?to=/:account/turnstile
TURNSTILE_SITE_KEY=
TURNSTILE_SECRET_KEY=

# Frontend URL (for OAuth redirects)
FRONTEND_URL=http://localhost:8080

# Google OAuth
# Get your credentials at: https://console.cloud.google.com/apis/credentials
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=http://localhost:5000/api/auth/oauth/google/callback

# GitHub OAuth
# Get your credentials at: https://github.com/settings/developers
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
GITHUB_REDIRECT_URI=http://localhost:5000/api/auth/oauth/github/callback

# Security: IP rate limit (防爆破 - IP维度)
# Block IP after N failed attempts within M minutes for X minutes
SECURITY_IP_MAX_ATTEMPTS=10
SECURITY_IP_WINDOW_MINUTES=5
SECURITY_IP_BLOCK_MINUTES=15

# Security: Account rate limit (防爆破 - 账户维度)
SECURITY_ACCOUNT_MAX_ATTEMPTS=5
SECURITY_ACCOUNT_WINDOW_MINUTES=60
SECURITY_ACCOUNT_BLOCK_MINUTES=30

# Verification code settings (验证码设置)
VERIFICATION_CODE_EXPIRE_MINUTES=10
VERIFICATION_CODE_RATE_LIMIT=60
VERIFICATION_CODE_IP_HOURLY_LIMIT=10
VERIFICATION_CODE_MAX_ATTEMPTS=5
VERIFICATION_CODE_LOCK_MINUTES=30

# =========================
# Billing & Credits (积分计费系统)
# =========================
# Enable billing system (启用计费系统)
BILLING_ENABLED=False

# VIP users can use all paid features for free (VIP用户免费)
BILLING_VIP_BYPASS=True

# Credits consumed per feature (各功能消耗积分数)
BILLING_COST_AI_ANALYSIS=10
BILLING_COST_STRATEGY_RUN=5
BILLING_COST_BACKTEST=3
BILLING_COST_PORTFOLIO_MONITOR=8

# Telegram customer service URL for recharge (充值跳转的Telegram链接)
RECHARGE_TELEGRAM_URL=https://t.me/quantdinger

# New user registration bonus credits (新用户注册赠送积分)
CREDITS_REGISTER_BONUS=100

# Referral bonus credits (邀请用户赠送积分，邀请人获得)
CREDITS_REFERRAL_BONUS=50

# History K-Line ticket get number （策略中默认获取历史K线数量）
K_LINE_HISTORY_GET_NUMBER=500
