feat: integrate TradingOrchestrator with 5-level signal dashboard

- Merge orchestrator module (Quant+LLM dual-track signal fusion)
- Replace ANALYSIS_SCRIPT_TEMPLATE to use TradingOrchestrator.get_combined_signal()
- Extend signal levels: BUY/OVERWEIGHT/HOLD/UNDERWEIGHT/SELL (direction × confidence≥0.7)
- Backend: parse SIGNAL_DETAIL: stdout line, populate quant_signal/llm_signal/confidence fields
- Backend: update _extract_decision() regex for 5-level signals
- Backend: add OVERWEIGHT/UNDERWEIGHT colors to PDF export
- Frontend: DecisionBadge classMap for all 5 signal levels
- Frontend: index.css color tokens --overweight/--underweight
- Frontend: AnalysisMonitor shows LLM signal, Quant signal, confidence% on completion
- Add orchestrator/cache/ to .gitignore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
陈少杰 2026-04-10 01:59:43 +08:00
parent 8960fdf321
commit 0cd40a9bab
12 changed files with 835 additions and 27 deletions

3
.gitignore vendored
View File

@ -220,3 +220,6 @@ __marimo__/
# Cache
**/data_cache/
# Orchestrator cache
orchestrator/cache/

98
CLAUDE.md Normal file
View File

@ -0,0 +1,98 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## 语言规则
- **用中文回答用户的问题**
## 项目概述
TradingAgents 是一个基于 LangGraph 的多智能体 LLM 金融交易框架,模拟真实交易公司的运作模式。通过部署专业化的 LLM 智能体(基本面分析师、情绪分析师、技术分析师、交易员、风险管理团队)协作评估市场状况并做出交易决策。
## 常用命令
```bash
# 激活环境
source env312/bin/activate
# SEPA筛选 + TradingAgents 完整流程
python sepa_v5.py
# 单股分析
python run_ningde.py # 宁德时代 (300750.SZ)
python run_312.py # 贵州茅台
# CLI 交互模式
python -m cli.main
```
## 核心架构
### 工作流程
```
SEPA筛选 (定量) → 分析师团队 → 研究员辩论 → 交易员 → 风险管理辩论 → 组合经理
```
### 关键组件 (`tradingagents/`)
| 目录 | 职责 |
|------|------|
| `agents/` | LLM智能体实现 (分析师、研究员、交易员、风控) |
| `dataflows/` | 数据源集成 (yfinance, alpha_vantage, china_data) |
| `graph/` | LangGraph 工作流编排 |
| `llm_clients/` | 多Provider LLM支持 (OpenAI, Anthropic, Google) |
### 数据流向
```
数据源 → dataflows/interface.py (路由) → 各智能体工具调用
```
## A股特定配置
- **数据源**: yfinance (akshare财务API已损坏)
- **股票代码格式**: `300750.SZ` (深圳), `603259.SS` (上海), `688256.SS` (科创板)
- **API**: MiniMax (Anthropic兼容), Base URL: `https://api.minimaxi.com/anthropic`
## 关键文件
| 文件 | 用途 |
|------|------|
| `tradingagents/graph/trading_graph.py` | 主协调器 TradingAgentsGraph |
| `tradingagents/graph/setup.py` | LangGraph 节点/边配置 |
| `dataflows/interface.py` | 数据供应商路由 |
| `sepa_v5.py` | SEPA筛选流程 |
| `default_config.py` | 默认配置 |
## 配置
默认配置在 `tradingagents/default_config.py`,运行时可覆盖:
- `llm_provider`: LLM提供商
- `deep_think_llm` / `quick_think_llm`: 模型选择
- `data_vendors`: 数据源路由
- `max_debate_rounds`: 辩论轮数
## 设计上下文 (Web Dashboard)
### 核心功能
- **股票筛选面板**: 输入股票代码运行SEPA筛选展示筛选结果表格
- **分析监控台**: 实时显示TradingAgents多智能体分析进度分析师→研究员→交易员→风控
- **历史报告查看**: 展示历史分析报告,支持搜索、筛选、导出
- **批量管理**: 批量提交股票分析任务,查看队列状态
### 界面风格
- **风格**: 数据可视化优先 - 图表驱动,实时更新
- **参考**: Grafana监控面板、彭博终端、币安交易界面
- **主题**: 深色主题为主,大量使用图表展示数据
### 设计原则
1. **实时性优先** - 所有状态变化即时反映,图表数据自动刷新
2. **数据可视化** - 数字指标用图表展示,不用纯文本堆砌
3. **清晰的状态层级** - 当前任务 > 队列任务 > 历史记录
4. **批量效率** - 支持多任务同时提交、统一管理
5. **专业金融感** - 深色主题、K线/折线图、数据表格
## 设计系统
Always read `DESIGN.md` before making any visual or UI decisions.
All font choices, colors, spacing, and aesthetic direction are defined there.
Do not deviate without explicit user approval.

313
DESIGN.md Normal file
View File

@ -0,0 +1,313 @@
# Design System: Apple
## 1. Visual Theme & Atmosphere
Apple's website is a masterclass in controlled drama — vast expanses of pure black and near-white serve as cinematic backdrops for products that are photographed as if they were sculptures in a gallery. The design philosophy is reductive to its core: every pixel exists in service of the product, and the interface itself retreats until it becomes invisible. This is not minimalism as aesthetic preference; it is minimalism as reverence for the object.
The typography anchors everything. San Francisco (SF Pro Display for large sizes, SF Pro Text for body) is Apple's proprietary typeface, engineered with optical sizing that automatically adjusts letterforms depending on point size. At display sizes (56px), weight 600 with a tight line-height of 1.07 and subtle negative letter-spacing (-0.28px) creates headlines that feel machined rather than typeset — precise, confident, and unapologetically direct. At body sizes (17px), the tracking loosens slightly (-0.374px) and line-height opens to 1.47, creating a reading rhythm that is comfortable without ever feeling slack.
The color story is starkly binary. Product sections alternate between pure black (`#000000`) backgrounds with white text and light gray (`#f5f5f7`) backgrounds with near-black text (`#1d1d1f`). This creates a cinematic pacing — dark sections feel immersive and premium, light sections feel open and informational. The only chromatic accent is Apple Blue (`#0071e3`), reserved exclusively for interactive elements: links, buttons, and focus states. This singular accent color in a sea of neutrals gives every clickable element unmistakable visibility.
**Key Characteristics:**
- SF Pro Display/Text with optical sizing — letterforms adapt automatically to size context
- Binary light/dark section rhythm: black (`#000000`) alternating with light gray (`#f5f5f7`)
- Single accent color: Apple Blue (`#0071e3`) reserved exclusively for interactive elements
- Product-as-hero photography on solid color fields — no gradients, no textures, no distractions
- Extremely tight headline line-heights (1.07-1.14) creating compressed, billboard-like impact
- Full-width section layout with centered content — the viewport IS the canvas
- Pill-shaped CTAs (980px radius) creating soft, approachable action buttons
- Generous whitespace between sections allowing each product moment to breathe
## 2. Color Palette & Roles
### Primary
- **Pure Black** (`#000000`): Hero section backgrounds, immersive product showcases. The darkest canvas for the brightest products.
- **Light Gray** (`#f5f5f7`): Alternate section backgrounds, informational areas. Not white — the slight blue-gray tint prevents sterility.
- **Near Black** (`#1d1d1f`): Primary text on light backgrounds, dark button fills. Slightly warmer than pure black for comfortable reading.
### Interactive
- **Apple Blue** (`#0071e3`): `--sk-focus-color`, primary CTA backgrounds, focus rings. The ONLY chromatic color in the interface.
- **Link Blue** (`#0066cc`): `--sk-body-link-color`, inline text links. Slightly darker than Apple Blue for text-level readability.
- **Bright Blue** (`#2997ff`): Links on dark backgrounds. Higher luminance for contrast on black sections.
### Text
- **White** (`#ffffff`): Text on dark backgrounds, button text on blue/dark CTAs.
- **Near Black** (`#1d1d1f`): Primary body text on light backgrounds.
- **Black 80%** (`rgba(0, 0, 0, 0.8)`): Secondary text, nav items on light backgrounds. Slightly softened.
- **Black 48%** (`rgba(0, 0, 0, 0.48)`): Tertiary text, disabled states, carousel controls.
### Surface & Dark Variants
- **Dark Surface 1** (`#272729`): Card backgrounds in dark sections.
- **Dark Surface 2** (`#262628`): Subtle surface variation in dark contexts.
- **Dark Surface 3** (`#28282a`): Elevated cards on dark backgrounds.
- **Dark Surface 4** (`#2a2a2d`): Highest dark surface elevation.
- **Dark Surface 5** (`#242426`): Deepest dark surface tone.
### Button States
- **Button Active** (`#ededf2`): Active/pressed state for light buttons.
- **Button Default Light** (`#fafafc`): Search/filter button backgrounds.
- **Overlay** (`rgba(210, 210, 215, 0.64)`): Media control scrims, overlays.
- **White 32%** (`rgba(255, 255, 255, 0.32)`): Hover state on dark modal close buttons.
### Shadows
- **Card Shadow** (`rgba(0, 0, 0, 0.22) 3px 5px 30px 0px`): Soft, diffused elevation for product cards. Offset and wide blur create a natural, photographic shadow.
## 3. Typography Rules
### Font Family
- **Display**: `SF Pro Display`, with fallbacks: `SF Pro Icons, Helvetica Neue, Helvetica, Arial, sans-serif`
- **Body**: `SF Pro Text`, with fallbacks: `SF Pro Icons, Helvetica Neue, Helvetica, Arial, sans-serif`
- SF Pro Display is used at 20px and above; SF Pro Text is optimized for 19px and below.
### Hierarchy
| Role | Font | Size | Weight | Line Height | Letter Spacing | Notes |
|------|------|------|--------|-------------|----------------|-------|
| Display Hero | SF Pro Display | 56px (3.50rem) | 600 | 1.07 (tight) | -0.28px | Product launch headlines, maximum impact |
| Section Heading | SF Pro Display | 40px (2.50rem) | 600 | 1.10 (tight) | normal | Feature section titles |
| Tile Heading | SF Pro Display | 28px (1.75rem) | 400 | 1.14 (tight) | 0.196px | Product tile headlines |
| Card Title | SF Pro Display | 21px (1.31rem) | 700 | 1.19 (tight) | 0.231px | Bold card headings |
| Sub-heading | SF Pro Display | 21px (1.31rem) | 400 | 1.19 (tight) | 0.231px | Regular card headings |
| Nav Heading | SF Pro Text | 34px (2.13rem) | 600 | 1.47 | -0.374px | Large navigation headings |
| Sub-nav | SF Pro Text | 24px (1.50rem) | 300 | 1.50 | normal | Light sub-navigation text |
| Body | SF Pro Text | 17px (1.06rem) | 400 | 1.47 | -0.374px | Standard reading text |
| Body Emphasis | SF Pro Text | 17px (1.06rem) | 600 | 1.24 (tight) | -0.374px | Emphasized body text, labels |
| Button Large | SF Pro Text | 18px (1.13rem) | 300 | 1.00 (tight) | normal | Large button text, light weight |
| Button | SF Pro Text | 17px (1.06rem) | 400 | 2.41 (relaxed) | normal | Standard button text |
| Link | SF Pro Text | 14px (0.88rem) | 400 | 1.43 | -0.224px | Body links, "Learn more" |
| Caption | SF Pro Text | 14px (0.88rem) | 400 | 1.29 (tight) | -0.224px | Secondary text, descriptions |
| Caption Bold | SF Pro Text | 14px (0.88rem) | 600 | 1.29 (tight) | -0.224px | Emphasized captions |
| Micro | SF Pro Text | 12px (0.75rem) | 400 | 1.33 | -0.12px | Fine print, footnotes |
| Micro Bold | SF Pro Text | 12px (0.75rem) | 600 | 1.33 | -0.12px | Bold fine print |
| Nano | SF Pro Text | 10px (0.63rem) | 400 | 1.47 | -0.08px | Legal text, smallest size |
### Principles
- **Optical sizing as philosophy**: SF Pro automatically switches between Display and Text optical sizes. Display versions have wider letter spacing and thinner strokes optimized for large sizes; Text versions are tighter and sturdier for small sizes. This means the font literally changes its DNA based on context.
- **Weight restraint**: The scale spans 300 (light) to 700 (bold) but most text lives at 400 (regular) and 600 (semibold). Weight 300 appears only on large decorative text. Weight 700 is rare, used only for bold card titles.
- **Negative tracking at all sizes**: Unlike most systems that only track headlines, Apple applies subtle negative letter-spacing even at body sizes (-0.374px at 17px, -0.224px at 14px, -0.12px at 12px). This creates universally tight, efficient text.
- **Extreme line-height range**: Headlines compress to 1.07 while body text opens to 1.47, and some button contexts stretch to 2.41. This dramatic range creates clear visual hierarchy through rhythm alone.
## 4. Component Stylings
### Buttons
**Primary Blue (CTA)**
- Background: `#0071e3` (Apple Blue)
- Text: `#ffffff`
- Padding: 8px 15px
- Radius: 8px
- Border: 1px solid transparent
- Font: SF Pro Text, 17px, weight 400
- Hover: background brightens slightly
- Active: `#ededf2` background shift
- Focus: `2px solid var(--sk-focus-color, #0071E3)` outline
- Use: Primary call-to-action ("Buy", "Shop iPhone")
**Primary Dark**
- Background: `#1d1d1f`
- Text: `#ffffff`
- Padding: 8px 15px
- Radius: 8px
- Font: SF Pro Text, 17px, weight 400
- Use: Secondary CTA, dark variant
**Pill Link (Learn More / Shop)**
- Background: transparent
- Text: `#0066cc` (light bg) or `#2997ff` (dark bg)
- Radius: 980px (full pill)
- Border: 1px solid `#0066cc`
- Font: SF Pro Text, 14px-17px
- Hover: underline decoration
- Use: "Learn more" and "Shop" links — the signature Apple inline CTA
**Filter / Search Button**
- Background: `#fafafc`
- Text: `rgba(0, 0, 0, 0.8)`
- Padding: 0px 14px
- Radius: 11px
- Border: 3px solid `rgba(0, 0, 0, 0.04)`
- Focus: `2px solid var(--sk-focus-color, #0071E3)` outline
- Use: Search bars, filter controls
**Media Control**
- Background: `rgba(210, 210, 215, 0.64)`
- Text: `rgba(0, 0, 0, 0.48)`
- Radius: 50% (circular)
- Active: scale(0.9), background shifts
- Focus: `2px solid var(--sk-focus-color, #0071e3)` outline, white bg, black text
- Use: Play/pause, carousel arrows
### Cards & Containers
- Background: `#f5f5f7` (light) or `#272729`-`#2a2a2d` (dark)
- Border: none (borders are rare in Apple's system)
- Radius: 5px-8px
- Shadow: `rgba(0, 0, 0, 0.22) 3px 5px 30px 0px` for elevated product cards
- Content: centered, generous padding
- Hover: no standard hover state — cards are static, links within them are interactive
### Navigation
- Background: `rgba(0, 0, 0, 0.8)` (translucent dark) with `backdrop-filter: saturate(180%) blur(20px)`
- Height: 48px (compact)
- Text: `#ffffff` at 12px, weight 400
- Active: underline on hover
- Logo: Apple logomark (SVG) centered or left-aligned, 17x48px viewport
- Mobile: collapses to hamburger with full-screen overlay menu
- The nav floats above content, maintaining its dark translucent glass regardless of section background
### Image Treatment
- Products on solid-color fields (black or white) — no backgrounds, no context, just the object
- Full-bleed section images that span the entire viewport width
- Product photography at extremely high resolution with subtle shadows
- Lifestyle images confined to rounded-corner containers (12px+ radius)
### Distinctive Components
**Product Hero Module**
- Full-viewport-width section with solid background (black or `#f5f5f7`)
- Product name as the primary headline (SF Pro Display, 56px, weight 600)
- One-line descriptor below in lighter weight
- Two pill CTAs side by side: "Learn more" (outline) and "Buy" / "Shop" (filled)
**Product Grid Tile**
- Square or near-square card on contrasting background
- Product image dominating 60-70% of the tile
- Product name + one-line description below
- "Learn more" and "Shop" link pair at bottom
**Feature Comparison Strip**
- Horizontal scroll of product variants
- Each variant as a vertical card with image, name, and key specs
- Minimal chrome — the products speak for themselves
## 5. Layout Principles
### Spacing System
- Base unit: 8px
- Scale: 2px, 4px, 5px, 6px, 7px, 8px, 9px, 10px, 11px, 14px, 15px, 17px, 20px, 24px
- Notable characteristic: the scale is dense at small sizes (2-11px) with granular 1px increments, then jumps in larger steps. This allows precise micro-adjustments for typography and icon alignment.
### Grid & Container
- Max content width: approximately 980px (the recurring "980px radius" in pill buttons echoes this width)
- Hero: full-viewport-width sections with centered content block
- Product grids: 2-3 column layouts within centered container
- Single-column for hero moments — one product, one message, full attention
- No visible grid lines or gutters — spacing creates implied structure
### Whitespace Philosophy
- **Cinematic breathing room**: Each product section occupies a full viewport height (or close to it). The whitespace between products is not empty — it is the pause between scenes in a film.
- **Vertical rhythm through color blocks**: Rather than using spacing alone to separate sections, Apple uses alternating background colors (black, `#f5f5f7`, white). Each color change signals a new "scene."
- **Compression within, expansion between**: Text blocks are tightly set (negative letter-spacing, tight line-heights) while the space surrounding them is vast. This creates a tension between density and openness.
### Border Radius Scale
- Micro (5px): Small containers, link tags
- Standard (8px): Buttons, product cards, image containers
- Comfortable (11px): Search inputs, filter buttons
- Large (12px): Feature panels, lifestyle image containers
- Full Pill (980px): CTA links ("Learn more", "Shop"), navigation pills
- Circle (50%): Media controls (play/pause, arrows)
## 6. Depth & Elevation
| Level | Treatment | Use |
|-------|-----------|-----|
| Flat (Level 0) | No shadow, solid background | Standard content sections, text blocks |
| Navigation Glass | `backdrop-filter: saturate(180%) blur(20px)` on `rgba(0,0,0,0.8)` | Sticky navigation bar — the glass effect |
| Subtle Lift (Level 1) | `rgba(0, 0, 0, 0.22) 3px 5px 30px 0px` | Product cards, floating elements |
| Media Control | `rgba(210, 210, 215, 0.64)` background with scale transforms | Play/pause buttons, carousel controls |
| Focus (Accessibility) | `2px solid #0071e3` outline | Keyboard focus on all interactive elements |
**Shadow Philosophy**: Apple uses shadow extremely sparingly. The primary shadow (`3px 5px 30px` with 0.22 opacity) is soft, wide, and offset — mimicking a diffused studio light casting a natural shadow beneath a physical object. This reinforces the "product as physical sculpture" metaphor. Most elements have NO shadow at all; elevation comes from background color contrast (dark card on darker background, or light card on slightly different gray).
### Decorative Depth
- Navigation glass: the translucent, blurred navigation bar is the most recognizable depth element, creating a sense of floating UI above scrolling content
- Section color transitions: depth is implied by the alternation between black and light gray sections rather than by shadows
- Product photography shadows: the products themselves cast shadows in their photography, so the UI doesn't need to add synthetic ones
## 7. Do's and Don'ts
### Do
- Use SF Pro Display at 20px+ and SF Pro Text below 20px — respect the optical sizing boundary
- Apply negative letter-spacing at all text sizes (not just headlines) — Apple tracks tight universally
- Use Apple Blue (`#0071e3`) ONLY for interactive elements — it must be the singular accent
- Alternate between black and light gray (`#f5f5f7`) section backgrounds for cinematic rhythm
- Use 980px pill radius for CTA links — the signature Apple link shape
- Keep product imagery on solid-color fields with no competing visual elements
- Use the translucent dark glass (`rgba(0,0,0,0.8)` + blur) for sticky navigation
- Compress headline line-heights to 1.07-1.14 — Apple headlines are famously tight
### Don't
- Don't introduce additional accent colors — the entire chromatic budget is spent on blue
- Don't use heavy shadows or multiple shadow layers — Apple's shadow system is one soft diffused shadow or nothing
- Don't use borders on cards or containers — Apple almost never uses visible borders (except on specific buttons)
- Don't apply wide letter-spacing to SF Pro — it is designed to run tight at every size
- Don't use weight 800 or 900 — the maximum is 700 (bold), and even that is rare
- Don't add textures, patterns, or gradients to backgrounds — solid colors only
- Don't make the navigation opaque — the glass blur effect is essential to the Apple UI identity
- Don't center-align body text — Apple body copy is left-aligned; only headlines center
- Don't use rounded corners larger than 12px on rectangular elements (980px is for pills only)
## 8. Responsive Behavior
### Breakpoints
| Name | Width | Key Changes |
|------|-------|-------------|
| Small Mobile | <360px | Minimum supported, single column |
| Mobile | 360-480px | Standard mobile layout |
| Mobile Large | 480-640px | Wider single column, larger images |
| Tablet Small | 640-834px | 2-column product grids begin |
| Tablet | 834-1024px | Full tablet layout, expanded nav |
| Desktop Small | 1024-1070px | Standard desktop layout begins |
| Desktop | 1070-1440px | Full layout, max content width |
| Large Desktop | >1440px | Centered with generous margins |
### Touch Targets
- Primary CTAs: 8px 15px padding creating ~44px touch height
- Navigation links: 48px height with adequate spacing
- Media controls: 50% radius circular buttons, minimum 44x44px
- "Learn more" pills: generous padding for comfortable tapping
### Collapsing Strategy
- Hero headlines: 56px Display → 40px → 28px on mobile, maintaining tight line-height proportionally
- Product grids: 3-column → 2-column → single column stacked
- Navigation: full horizontal nav → compact mobile menu (hamburger)
- Product hero modules: full-bleed maintained at all sizes, text scales down
- Section backgrounds: maintain full-width color blocks at all breakpoints — the cinematic rhythm never breaks
- Image sizing: products scale proportionally, never crop — the product silhouette is sacred
### Image Behavior
- Product photography maintains aspect ratio at all breakpoints
- Hero product images scale down but stay centered
- Full-bleed section backgrounds persist at every size
- Lifestyle images may crop on mobile but maintain their rounded corners
- Lazy loading for below-fold product images
## 9. Agent Prompt Guide
### Quick Color Reference
- Primary CTA: Apple Blue (`#0071e3`)
- Page background (light): `#f5f5f7`
- Page background (dark): `#000000`
- Heading text (light): `#1d1d1f`
- Heading text (dark): `#ffffff`
- Body text: `rgba(0, 0, 0, 0.8)` on light, `#ffffff` on dark
- Link (light bg): `#0066cc`
- Link (dark bg): `#2997ff`
- Focus ring: `#0071e3`
- Card shadow: `rgba(0, 0, 0, 0.22) 3px 5px 30px 0px`
### Example Component Prompts
- "Create a hero section on black background. Headline at 56px SF Pro Display weight 600, line-height 1.07, letter-spacing -0.28px, color white. One-line subtitle at 21px SF Pro Display weight 400, line-height 1.19, color white. Two pill CTAs: 'Learn more' (transparent bg, white text, 1px solid white border, 980px radius) and 'Buy' (Apple Blue #0071e3 bg, white text, 8px radius, 8px 15px padding)."
- "Design a product card: #f5f5f7 background, 8px border-radius, no border, no shadow. Product image top 60% of card on solid background. Title at 28px SF Pro Display weight 400, letter-spacing 0.196px, line-height 1.14. Description at 14px SF Pro Text weight 400, color rgba(0,0,0,0.8). 'Learn more' and 'Shop' links in #0066cc at 14px."
- "Build the Apple navigation: sticky, 48px height, background rgba(0,0,0,0.8) with backdrop-filter: saturate(180%) blur(20px). Links at 12px SF Pro Text weight 400, white text. Apple logo left, links centered, search and bag icons right."
- "Create an alternating section layout: first section black bg with white text and centered product image, second section #f5f5f7 bg with #1d1d1f text. Each section near full-viewport height with 56px headline and two pill CTAs below."
- "Design a 'Learn more' link: text #0066cc on light bg or #2997ff on dark bg, 14px SF Pro Text, underline on hover. After the text, include a right-arrow chevron character (>). Wrap in a container with 980px border-radius for pill shape when used as a standalone CTA."
### Iteration Guide
1. Every interactive element gets Apple Blue (`#0071e3`) — no other accent colors
2. Section backgrounds alternate: black for immersive moments, `#f5f5f7` for informational moments
3. Typography optical sizing: SF Pro Display at 20px+, SF Pro Text below — never mix
4. Negative letter-spacing at all sizes: -0.28px at 56px, -0.374px at 17px, -0.224px at 14px, -0.12px at 12px
5. The navigation glass effect (translucent dark + blur) is non-negotiable — it defines the Apple web experience
6. Products always appear on solid color fields — never on gradients, textures, or lifestyle backgrounds in hero modules
7. Shadow is rare and always soft: `3px 5px 30px 0.22 opacity` or nothing at all
8. Pill CTAs use 980px radius — this creates the signature Apple rounded-rectangle-that-looks-like-a-capsule shape

87
PROJECT_HANDOVER.md Normal file
View File

@ -0,0 +1,87 @@
# TradingAgents A股分析项目 - 交接文档
## 项目位置
```
/Users/chenshaojie/Downloads/autoresearch/TradingAgents/
```
## 环境配置
- **Python 版本**: 3.12 (非系统默认)
- **环境路径**: `env312/`
- **激活命令**: `source env312/bin/activate`
## 运行方式
### 方式1: 完整流程 (SEPA筛选 + TradingAgents分析)
```bash
cd /Users/chenshaojie/Downloads/autoresearch/TradingAgents
source env312/bin/activate
python sepa_v5.py
```
### 方式2: 单股分析
```bash
cd /Users/chenshaojie/Downloads/autoresearch/TradingAgents
source env312/bin/activate
python run_ningde.py # 宁德时代
```
## 关键文件
| 文件 | 说明 |
|------|------|
| `sepa_v5.py` | SEPA筛选 + TradingAgents 工作流 |
| `run_ningde.py` | 宁德时代单股分析 |
| `run_312.py` | 贵州茅台分析 (原演示脚本) |
## 当前进度
- ✅ TradingAgents 部署完成
- ✅ Python 3.12 环境配置完成
- ✅ MiniMax API (Anthropic兼容) 配置完成
- ✅ SEPA筛选流程完成 (yfinance数据源)
- ⚠️ 只完成1只股票分析 (宁德时代)
## 当前发现
1. **SEPA筛选结果**: 5只基本面达标
- 宁德时代 (300750.SZ): ROE=23.8%, 营收=36.6%, 利润=50.1%
- 药明康德 (603259.SS): ROE=25.8%, 营收=18.2%, 利润=128.7%
- 立讯精密 (002475.SZ): ROE=19.6%, 营收=31.0%, 利润=29.1%
- 寒武纪 (688256.SS): ROE=23.8%, 营收=91.0%, 利润=61.7%
- 澜起科技 (688008.SS): ROE=17.6%, 营收=31.0%, 利润=39.9%
2. **问题**: 这些股票目前都在均线下方调整期SEPA技术条件未通过
3. **TradingAgents运行缓慢**: 建议一次只分析1-2只股票
4. **akshare财务API已损坏**: 使用yfinance替代
## 宁德时代分析结果
**最终交易建议**: HOLD / WAIT FOR PULLBACK
| 指标 | 数值 | 信号 |
|------|------|------|
| 当前价格 | ¥397.00 | - |
| 50日均线 | ¥360.51 | 🟢 价格在线上 |
| 200日均线 | ¥329.40 | 🟢 均线之上 (强势) |
| RSI (14) | 70.14 | 🔴 超买 |
| MACD | 金叉看涨 | 🟢 强势 |
| ATR | 12.43 | 🟡 高波动 |
**建议**: 持有现有仓位 / 新资金等待回调至¥360-365再入场
## 建议任务
1. 继续分析剩余4只股票
2. 优化SEPA参数中国市场更宽松的阈值
3. 添加ST股和次新股过滤
4. 批量分析100+只股票
## API配置
- API Key: Read from a local environment variable; do not commit secrets
- Base URL: `https://api.minimaxi.com/anthropic`
- Model: `MiniMax-M2.7-highspeed`

View File

@ -60,7 +60,7 @@ class Propagator:
callbacks: Optional list of callback handlers for tool execution tracking.
Note: LLM callbacks are handled separately via LLM constructor.
"""
config = {"recursion_limit": self.max_recur_limit}
config = {"recursion_limit": self.max_recur_limit, "max_concurrency": 1}
if callbacks:
config["callbacks"] = callbacks
return {

View File

@ -147,6 +147,9 @@ class TradingAgentsGraph:
reasoning_effort = self.config.get("openai_reasoning_effort")
if reasoning_effort:
kwargs["reasoning_effort"] = reasoning_effort
# Allow disabling Responses API for third-party OpenAI-compatible providers
if "use_responses_api" in self.config:
kwargs["use_responses_api"] = self.config["use_responses_api"]
elif provider == "anthropic":
effort = self.config.get("anthropic_effort")

View File

@ -76,8 +76,10 @@ class OpenAIClient(BaseLLMClient):
# Native OpenAI: use Responses API for consistent behavior across
# all model families. Third-party providers use Chat Completions.
# Allow override via kwargs (e.g. use_responses_api=False for MiniMax)
if self.provider == "openai":
llm_kwargs["use_responses_api"] = True
use_resp = self.kwargs.get("use_responses_api", True)
llm_kwargs["use_responses_api"] = use_resp
return NormalizedChatOpenAI(**llm_kwargs)

View File

@ -19,8 +19,10 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException, WebSocket, WebSocketDisconnect, Query, Header
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import Response, FileResponse
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
from fastapi.responses import Response
import os
# Path to TradingAgents repo root
REPO_ROOT = Path(__file__).parent.parent.parent
@ -80,6 +82,35 @@ class ScreenRequest(BaseModel):
mode: str = "china_strict"
# ============== Config Commands (Tauri IPC) ==============
@app.get("/api/config/check")
async def check_config():
"""Check if the app is configured (API key is set).
The FastAPI backend receives ANTHROPIC_API_KEY as an env var when spawned by Tauri.
"""
configured = bool(os.environ.get("ANTHROPIC_API_KEY"))
return {"configured": configured}
@app.post("/api/config/apikey")
async def save_apikey(body: dict = None, api_key: Optional[str] = Header(None)):
"""Save API key via Tauri command. Used by the setup wizard."""
if not body or "api_key" not in body:
raise HTTPException(status_code=400, detail="api_key is required")
apikey = body["api_key"].strip()
if not apikey:
raise HTTPException(status_code=400, detail="api_key cannot be empty")
try:
result = _tauri_invoke("set_config", {"key": "api_key", "value": apikey})
# If we get here without error, the key was saved
return {"ok": True, "saved": True}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to save API key: {e}")
# ============== Cache Helpers ==============
CACHE_DIR = Path(__file__).parent.parent / "cache"
@ -201,6 +232,7 @@ async def screen_stocks(mode: str = Query("china_strict"), refresh: bool = Query
ANALYSIS_SCRIPT_TEMPLATE = """
import sys
import os
import json
ticker = sys.argv[1]
date = sys.argv[2]
repo_root = sys.argv[3]
@ -209,49 +241,71 @@ sys.path.insert(0, repo_root)
os.environ["ANTHROPIC_BASE_URL"] = "https://api.minimaxi.com/anthropic"
import py_mini_racer
sys.modules["mini_racer"] = py_mini_racer
from tradingagents.graph.trading_graph import TradingAgentsGraph
from tradingagents.default_config import DEFAULT_CONFIG
from pathlib import Path
print("STAGE:analysts", flush=True)
config = DEFAULT_CONFIG.copy()
config["llm_provider"] = "anthropic"
config["deep_think_llm"] = "MiniMax-M2.7-highspeed"
config["quick_think_llm"] = "MiniMax-M2.7-highspeed"
config["backend_url"] = "https://api.minimaxi.com/anthropic"
config["max_debate_rounds"] = 1
config["max_risk_discuss_rounds"] = 1
from orchestrator.config import OrchestratorConfig
from orchestrator.orchestrator import TradingOrchestrator
config = OrchestratorConfig(
quant_backtest_path=os.environ.get("QUANT_BACKTEST_PATH", ""),
trading_agents_config={
"llm_provider": "anthropic",
"deep_think_llm": "MiniMax-M2.7-highspeed",
"quick_think_llm": "MiniMax-M2.7-highspeed",
"backend_url": "https://api.minimaxi.com/anthropic",
"max_debate_rounds": 1,
"max_risk_discuss_rounds": 1,
}
)
print("STAGE:research", flush=True)
ta = TradingAgentsGraph(debug=False, config=config)
orchestrator = TradingOrchestrator(config)
print("STAGE:trading", flush=True)
final_state, decision = ta.propagate(ticker, date)
result = orchestrator.get_combined_signal(ticker, date)
print("STAGE:risk", flush=True)
# Map direction + confidence to 5-level signal
direction = result.get("direction", 0)
confidence = result.get("confidence", 0.0)
llm_signal = result.get("llm_signal", "HOLD")
quant_signal = result.get("quant_signal", "HOLD")
if direction == 1:
signal = "BUY" if confidence >= 0.7 else "OVERWEIGHT"
elif direction == -1:
signal = "SELL" if confidence >= 0.7 else "UNDERWEIGHT"
else:
signal = "HOLD"
results_dir = Path(repo_root) / "results" / ticker / date
results_dir.mkdir(parents=True, exist_ok=True)
signal = decision if isinstance(decision, str) else decision.get("signal", "HOLD")
report_content = (
"# TradingAgents 分析报告\\n\\n"
"**股票**: " + ticker + "\\n"
"**日期**: " + date + "\\n\\n"
"## 最终决策\\n\\n"
"**" + signal + "**\\n\\n"
"## 信号详情\\n\\n"
"- LLM 信号: " + llm_signal + "\\n"
"- Quant 信号: " + quant_signal + "\\n"
"- 置信度: " + f"{confidence:.1%}" + "\\n\\n"
"## 分析摘要\\n\\n"
+ final_state.get("market_report", "N/A") + "\\n\\n"
"## 基本面\\n\\n"
+ final_state.get("fundamentals_report", "N/A") + "\\n"
+ result.get("summary", "N/A") + "\\n"
)
report_path = results_dir / "complete_report.md"
report_path.write_text(report_content)
print("STAGE:portfolio", flush=True)
signal_detail = json.dumps({"llm_signal": llm_signal, "quant_signal": quant_signal, "confidence": confidence})
print("SIGNAL_DETAIL:" + signal_detail, flush=True)
print("ANALYSIS_COMPLETE:" + signal, flush=True)
"""
@ -291,6 +345,9 @@ async def start_analysis(request: AnalysisRequest, api_key: Optional[str] = Head
],
"logs": [],
"decision": None,
"quant_signal": None,
"llm_signal": None,
"confidence": None,
"error": None,
}
await broadcast_progress(task_id, app.state.task_results[task_id])
@ -403,6 +460,14 @@ async def start_analysis(request: AnalysisRequest, api_key: Optional[str] = Head
output = stdout.decode()
decision = "HOLD"
for line in output.splitlines():
if line.startswith("SIGNAL_DETAIL:"):
try:
detail = json.loads(line.split(":", 1)[1].strip())
app.state.task_results[task_id]["quant_signal"] = detail.get("quant_signal")
app.state.task_results[task_id]["llm_signal"] = detail.get("llm_signal")
app.state.task_results[task_id]["confidence"] = detail.get("confidence")
except Exception:
pass
if line.startswith("ANALYSIS_COMPLETE:"):
decision = line.split(":", 1)[1].strip()
@ -657,8 +722,8 @@ from fpdf import FPDF
def _extract_decision(markdown_text: str) -> str:
"""Extract BUY/SELL/HOLD from markdown bold text."""
match = re.search(r'\*\*(BUY|SELL|HOLD)\*\*', markdown_text)
"""Extract BUY/OVERWEIGHT/SELL/UNDERWEIGHT/HOLD from markdown bold text."""
match = re.search(r'\*\*(BUY|SELL|HOLD|OVERWEIGHT|UNDERWEIGHT)\*\*', markdown_text)
return match.group(1) if match else 'UNKNOWN'
@ -768,8 +833,12 @@ async def export_report_pdf(ticker: str, date: str, api_key: Optional[str] = Hea
pdf.set_font(font_bold, "B", 14)
if decision == "BUY":
pdf.set_text_color(34, 197, 94)
elif decision == "OVERWEIGHT":
pdf.set_text_color(134, 239, 172)
elif decision == "SELL":
pdf.set_text_color(220, 38, 38)
elif decision == "UNDERWEIGHT":
pdf.set_text_color(252, 165, 165)
else:
pdf.set_text_color(245, 158, 11)
pdf.cell(0, 10, f"决策: {decision}", ln=True)
@ -1031,7 +1100,18 @@ async def start_portfolio_analysis(api_key: Optional[str] = Header(None)):
if proc.returncode == 0:
output = stdout.decode()
decision = "HOLD"
quant_signal = None
llm_signal = None
confidence = None
for line in output.splitlines():
if line.startswith("SIGNAL_DETAIL:"):
try:
detail = json.loads(line.split(":", 1)[1].strip())
quant_signal = detail.get("quant_signal")
llm_signal = detail.get("llm_signal")
confidence = detail.get("confidence")
except Exception:
pass
if line.startswith("ANALYSIS_COMPLETE:"):
decision = line.split(":", 1)[1].strip()
rec = {
@ -1039,6 +1119,9 @@ async def start_portfolio_analysis(api_key: Optional[str] = Header(None)):
"name": stock.get("name", ticker),
"analysis_date": date,
"decision": decision,
"quant_signal": quant_signal,
"llm_signal": llm_signal,
"confidence": confidence,
"created_at": datetime.now().isoformat(),
}
save_recommendation(date, ticker, rec)
@ -1100,6 +1183,10 @@ async def start_portfolio_analysis(api_key: Optional[str] = Header(None)):
@app.get("/")
async def root():
# Production mode: serve the built React frontend
frontend_dist = Path(__file__).parent.parent / "frontend" / "dist" / "index.html"
if frontend_dist.exists():
return FileResponse(str(frontend_dist))
return {"message": "TradingAgents Web Dashboard API", "version": "0.1.0"}
@ -1142,8 +1229,17 @@ async def ws_orchestrator(websocket: WebSocket, api_key: Optional[str] = None):
pass
@app.get("/health")
async def health():
return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
# Run with: cd web_dashboard && ../env312/bin/python -m uvicorn main:app --reload
# Or: cd web_dashboard/backend && python3 main.py (requires env312 in PATH)
uvicorn.run(app, host="0.0.0.0", port=8000)
host = os.environ.get("HOST", "0.0.0.0")
port = int(os.environ.get("PORT", "8000"))
# Production mode: serve the built React frontend
frontend_dist = Path(__file__).parent.parent / "frontend" / "dist"
if frontend_dist.exists():
app.mount("/assets", StaticFiles(directory=str(frontend_dist / "assets")), name="assets")
uvicorn.run(app, host=host, port=port)

View File

@ -15,6 +15,7 @@ const AnalysisMonitor = lazy(() => import('./pages/AnalysisMonitor'))
const ReportsViewer = lazy(() => import('./pages/ReportsViewer'))
const BatchManager = lazy(() => import('./pages/BatchManager'))
const PortfolioPanel = lazy(() => import('./pages/PortfolioPanel'))
const SetupWizard = lazy(() => import('./pages/SetupWizard'))
const navItems = [
{ path: '/', icon: <FundOutlined />, label: '筛选', key: '1' },
@ -127,6 +128,30 @@ function Layout({ children }) {
export default function App() {
const navigate = useNavigate()
const [configured, setConfigured] = useState(null) // null = checking, true/false
// Check if API key is configured on mount
useEffect(() => {
const checkConfig = async () => {
try {
// Check via Tauri command first (desktop app)
if (window.__TAURI__) {
const { invoke } = window.__TAURI__.core
const isConfigured = await invoke('is_configured')
setConfigured(isConfigured)
} else {
// Fallback: call backend API
const res = await fetch('/api/config/check')
const data = await res.json()
setConfigured(data.configured)
}
} catch (e) {
// Backend might not be ready yet, assume not configured
setConfigured(false)
}
}
checkConfig()
}, [])
useEffect(() => {
const handleKeyDown = (e) => {
@ -150,6 +175,28 @@ export default function App() {
return () => window.removeEventListener('keydown', handleKeyDown)
}, [navigate])
// Still checking config
if (configured === null) {
return (
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100vh', background: 'var(--bg-primary)' }}>
<div className="loading-pulse">加载中...</div>
</div>
)
}
// Not configured - show setup wizard
if (!configured) {
return (
<Suspense fallback={
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100vh', background: 'var(--bg-primary)' }}>
<div className="loading-pulse">加载中...</div>
</div>
}>
<SetupWizard onComplete={() => setConfigured(true)} />
</Suspense>
)
}
return (
<Layout>
<Suspense fallback={

View File

@ -1,5 +1,12 @@
export default function DecisionBadge({ decision }) {
if (!decision) return null
const cls = decision === 'BUY' ? 'badge-buy' : decision === 'SELL' ? 'badge-sell' : 'badge-hold'
const classMap = {
BUY: 'badge-buy',
OVERWEIGHT: 'badge-overweight',
HOLD: 'badge-hold',
UNDERWEIGHT: 'badge-underweight',
SELL: 'badge-sell',
}
const cls = classMap[decision] || 'badge-hold'
return <span className={cls}>{decision}</span>
}

View File

@ -23,8 +23,12 @@
/* Semantic — trading signals */
--buy: #00E676;
--buy-dim: rgba(0, 230, 118, 0.12);
--overweight: #69F0AE;
--overweight-dim: rgba(105, 240, 174, 0.12);
--sell: #FF5252;
--sell-dim: rgba(255, 82, 82, 0.12);
--underweight: #FF8A80;
--underweight-dim: rgba(255, 138, 128, 0.12);
--hold: #FFB300;
--hold-dim: rgba(255, 179, 0, 0.12);
--running: #7c3aed;
@ -346,9 +350,11 @@ body {
}
/* === Decision Badges === */
.badge-buy { background: var(--buy-dim); color: var(--buy); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-sell { background: var(--sell-dim); color: var(--sell); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-hold { background: var(--hold-dim); color: var(--hold); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-buy { background: var(--buy-dim); color: var(--buy); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-overweight { background: var(--overweight-dim); color: var(--overweight); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-sell { background: var(--sell-dim); color: var(--sell); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-underweight { background: var(--underweight-dim); color: var(--underweight); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-hold { background: var(--hold-dim); color: var(--hold); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
.badge-running{ background: var(--running-dim); color: var(--running); padding: 2px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-ui); }
/* === Stage Pills === */
@ -585,3 +591,134 @@ body {
transition-duration: 0.01ms !important;
}
}
/* === Setup Wizard === */
.setup-wizard {
min-height: 100vh;
background: var(--bg-base);
display: flex;
align-items: center;
justify-content: center;
padding: var(--space-6);
background-image:
radial-gradient(ellipse at 50% 0%, rgba(0, 212, 255, 0.08) 0%, transparent 60%),
radial-gradient(ellipse at 80% 80%, rgba(0, 230, 118, 0.05) 0%, transparent 50%);
}
.setup-wizard-card {
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-lg);
padding: var(--space-10);
max-width: 480px;
width: 100%;
box-shadow: var(--shadow-lg);
}
.setup-wizard-logo {
text-align: center;
margin-bottom: var(--space-8);
}
.setup-logo-icon {
width: 64px;
height: 64px;
background: var(--accent-dim);
border: 1px solid rgba(0, 212, 255, 0.3);
border-radius: var(--radius-lg);
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto var(--space-4);
font-size: 28px;
color: var(--accent);
}
.setup-wizard-logo h1 {
font-size: var(--text-2xl);
font-weight: var(--weight-bold);
color: var(--text-primary);
margin-bottom: var(--space-2);
letter-spacing: -0.02em;
}
.setup-wizard-logo p {
font-size: var(--text-base);
color: var(--text-secondary);
}
.setup-wizard-body {
display: flex;
flex-direction: column;
gap: var(--space-6);
}
.setup-wizard-step {
display: flex;
gap: var(--space-4);
align-items: flex-start;
}
.step-number {
width: 28px;
height: 28px;
min-width: 28px;
background: var(--accent-dim);
border: 1px solid rgba(0, 212, 255, 0.3);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: var(--text-sm);
font-weight: var(--weight-semibold);
color: var(--accent);
margin-top: 2px;
}
.step-content h3 {
font-size: var(--text-base);
font-weight: var(--weight-semibold);
color: var(--text-primary);
margin-bottom: var(--space-1);
}
.step-content p {
font-size: var(--text-sm);
color: var(--text-secondary);
line-height: 1.5;
}
.step-content a {
color: var(--accent);
text-decoration: none;
}
.step-content a:hover {
text-decoration: underline;
}
.setup-wizard-body .ant-btn-primary {
background: var(--accent) !important;
border-color: var(--accent) !important;
color: var(--bg-base) !important;
font-weight: var(--weight-semibold);
height: auto;
padding: var(--space-3) var(--space-6);
font-size: var(--text-base);
}
.setup-wizard-body .ant-btn-primary:hover {
background: #00b8e0 !important;
border-color: #00b8e0 !important;
}
.setup-wizard-body .ant-input-textarea textarea {
font-family: var(--font-data);
background: var(--bg-base) !important;
border-color: var(--border-strong) !important;
color: var(--text-primary) !important;
}
.setup-wizard-body .ant-input-textarea textarea::placeholder {
color: var(--text-muted) !important;
}

View File

@ -158,6 +158,21 @@ export default function AnalysisMonitor() {
<DecisionBadge decision={task.decision} />
</div>
{/* Signal Detail Row */}
{task.status === 'completed' && (task.llm_signal || task.quant_signal || task.confidence != null) && (
<div style={{ display: 'flex', gap: 24, marginBottom: 12, fontSize: 'var(--text-sm)', fontFamily: 'var(--font-ui)', color: 'var(--text-secondary)' }}>
{task.llm_signal && (
<span>LLM: <DecisionBadge decision={task.llm_signal} /></span>
)}
{task.quant_signal && (
<span>Quant: <DecisionBadge decision={task.quant_signal} /></span>
)}
{task.confidence != null && (
<span>置信度: <strong style={{ color: 'var(--text-primary)' }}>{(task.confidence * 100).toFixed(0)}%</strong></span>
)}
</div>
)}
{/* Progress */}
<div style={{ display: 'flex', alignItems: 'center', gap: 16, marginBottom: 16 }}>
<div className="progress-bar" style={{ flex: 1, height: 6 }}>