feat: Pattern Explorer — taxonomy tree + 23 historical patterns + instrument lens

- PatternExplorer.tsx: new page with two views:
    • Tree View — 6-root taxonomy (geopolitical, monetary_policy, economic,
      commodity, risk_off, market_structure) with collapsible sub-nodes;
      pattern cards appear on node selection
    • Instrument Lens — search any ticker (e.g. GLD, FXE) to see every
      pattern + scenario that references it, with matching trades highlighted
- geo_analyzer.py: PATTERN_TAXONOMY tree constant + taxonomy_path on all
  patterns; 15 new documented patterns P009-P023 (BoJ YCC, SVB crisis,
  Taiwan semis, OPEC cuts, Fed pivot, Debt ceiling, Iran nuclear, DPRK,
  VIX backwardation, ECB surprise, Extreme Fear contrarian, S. China Sea,
  European energy, CPI hot print, Flash crash)
- patterns.py: GET /api/patterns/taxonomy, GET /api/patterns/by-instrument
- database.py: taxonomy_path migration + seed_builtin_patterns updates path
- App.tsx: /patterns → PatternExplorer, /patterns/edit → PatternEditor

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OpenSquared
2026-06-22 16:42:45 +02:00
parent acc8bef29d
commit 10ffc345d6
6 changed files with 1148 additions and 5 deletions

View File

@@ -1,9 +1,10 @@
from fastapi import APIRouter, HTTPException
from fastapi import APIRouter, HTTPException, Query
from pydantic import BaseModel
from typing import Optional, List, Dict, Any
from services.database import (
save_custom_pattern, get_custom_patterns, delete_custom_pattern, toggle_pattern_active
)
from services.geo_analyzer import PATTERN_TAXONOMY
router = APIRouter(prefix="/api/patterns", tags=["patterns"])
@@ -71,3 +72,26 @@ def toggle_pattern(pat_id: str):
"""Enable or disable a pattern (works for builtin and custom)."""
new_state = toggle_pattern_active(pat_id)
return {"id": pat_id, "is_active": new_state}
@router.get("/taxonomy")
def get_taxonomy():
"""Return the taxonomy tree + all patterns (frontend builds node→pattern mapping)."""
patterns = get_custom_patterns()
return {"tree": PATTERN_TAXONOMY, "patterns": patterns}
@router.get("/by-instrument")
def get_by_instrument(ticker: str = Query(..., description="Ticker / underlying to search")):
"""Return all patterns that have a suggested_trade matching the given ticker."""
ticker_lower = ticker.strip().lower()
result = []
for p in get_custom_patterns():
trades = p.get("suggested_trades") or []
matching = [
t for t in trades
if ticker_lower in (t.get("underlying") or "").lower()
]
if matching:
result.append({**p, "matching_trades": matching})
return result