Files
gavindiazandClaude Code 7e50a0fef6 feat(llm): provider-agnostic OpenAI-compatible client; FinBERT warm-up off the event loop
Replace the Google Gemini lock-in with a unified chat client usable with any
OpenAI-compatible /v1 endpoint (OpenAI, OpenRouter, DeepSeek, Moonshot, Qwen,
Ollama, Gemini-via-compat...). Switch provider purely via AI_BASE_URL/AI_MODEL.

- ai/llm_client.py (new): lazy openai SDK, per-candidate 429/503/timeout
  failover across AI_MODEL_FAILOVER, robust JSON extraction, reasoning-budget
  retry, image analysis via base64 data URI, singleton get_llm_client()
- settings.py: GeminiSettings -> LLMSettings (api_key/base_url/model/failover/
  vision_model), keeps GEMINI_API_KEY fallback so existing .env keeps working
- news_analyzer.py: analyze_with_gemini -> analyze_with_llm (same output keys);
  FinBERT now loads in a daemon warm-up thread with lexicon fallback - the
  transformers first import was blocking the asyncio main loop 15-45s
  (importlib.metadata full package scan); HF_ENDPOINT hf-mirror setdefault
- telegram_bot.py: news digest + AI-vision chart analysis via the LLM client
- requirements: google-genai -> openai>=1.0; docs/.env.example/README updated
  for the new provider-agnostic setup; dashboard meta updated

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-21 20:56:52 +08:00

45 lines
1.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================
# XAUUSD AI 交易机器人 - 环境变量
# ============================================
# 将此文件复制为 .env 并填入你的配置值
# 切勿将 .env 文件提交到版本控制!
# --- MetaTrader 5 / Exness ---
MT5_LOGIN=your_mt5_login_number
MT5_PASSWORD=your_mt5_password
MT5_SERVER=Exness-MT5Real
MT5_PATH=C:\Program Files\MetaTrader 5\terminal64.exe
# --- OpenAI 兼容大模型 (OpenAI / OpenRouter / DeepSeek / Moonshot / Qwen / Ollama...) ---
# 只需将 AI_BASE_URL 指向任意兼容 OpenAI 的 /v1 端点即可切换服务商。
AI_API_KEY=your_openai_compatible_api_key
AI_BASE_URL=https://openrouter.ai/api/v1
AI_MODEL=openrouter/auto
# AI_VISION_MODEL — 可选;留空 = 复用 AI_MODEL
AI_VISION_MODEL=
# AI_MODEL_FAILOVER — 可选;逗号分隔的备用模型列表
AI_MODEL_FAILOVER=
# 向后兼容:如果 AI_API_KEY 为空,机器人将回退使用旧的
# GEMINI_API_KEY 值。要通过 OpenAI 兼容端点使用 Google Gemini:
# AI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/
# (或保留下方原生密钥,配合 /v1/chat/completions 模型名称使用)
GEMINI_API_KEY=you_can_leave_this_blank
# --- Finnhub (财经新闻) ---
FINNHUB_API_KEY=your_finnhub_api_key
# --- Alpha Vantage (新闻与数据) ---
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key
# --- Telegram 机器人 ---
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_CHAT_ID=your_telegram_chat_id
# --- 仪表盘 ---
DASHBOARD_SECRET_KEY=generate_a_random_secret_key_here
DASHBOARD_USERNAME=admin
DASHBOARD_PASSWORD=your_dashboard_password
# --- 数据库 ---
DATABASE_URL=sqlite:///./data/trading_bot.db