-
Notifications
You must be signed in to change notification settings - Fork 0
Proposal
PCBZ edited this page May 9, 2026
·
2 revisions
trade-compass is a personal US stock investment decision assistant. It connects to the user's Futu brokerage account, fetches real-time holdings, and uses a LangGraph multi-agent AI system to deliver clear, actionable verdicts: Buy, Hold, or Sell β with full reasoning.
Users interact exclusively through Telegram.
flowchart TD
User([π± User\nTelegram])
subgraph GCP Cloud Run
APP["βοΈ Container 1\ntrade-compass-app\nβββββββββββββββββ\nLangGraph Agents\nTelegram Bot Handler\n(Webhook mode)"]
API["βοΈ Container 2\ntrade-compass-api\nβββββββββββββββββ\nFastAPI REST API\nMongoDB client"]
end
subgraph GCP Compute Engine e2-micro FREE
VM["π₯οΈ VM\ntrade-compass-vm\nβββββββββββββββββ\nFutu OpenD\nSync Script (every 5min)\nDaily Brief Cron"]
end
subgraph MongoDB Atlas FREE
DB[(M0 Cluster\nholdings\ndecisions\npreferences)]
end
User <-->|Webhook| APP
APP <-->|REST| API
API <-->|Driver| DB
VM -->|POST /holdings| API
VM -->|POST Cloud Run URL\n9:25 AM ET daily| APP
Summary:
- 2 Cloud Run containers β app (AI + Telegram) and api (data layer)
- 1 Compute Engine VM β Futu sync + cron (free tier, us-west1)
- 1 MongoDB Atlas cluster β free tier M0
flowchart TD
START([User Command\n/decide /choose\n/portfolio /review]) --> ROUTE{Intent\nRouter}
ROUTE -->|single stock| DA
ROUTE -->|portfolio| PA
DA["π‘ data_agent\nβββββββββββββ\nFetch Yahoo Finance\nFetch holdings API\nPopulate shared state"]
DA --> FA & SA
FA["π fundamental_agent\nβββββββββββββββββ\nValuation P/E vs peers\nGrowth revenueΒ·EPS\nQuality FCFΒ·margins"]
SA["π° sentiment_agent\nβββββββββββββββββ\nNews search Brave\nAnalyst ratings\nPrice targets"]
FA --> DCA
SA --> DCA
DCA["π― decision_agent\nβββββββββββββββββ\nSynthesize 5-dim score\nWeight by user prefs\nOutput BUYΒ·HOLDΒ·SELL\nSave to MongoDB"]
PA["π portfolio_agent\nβββββββββββββββββ\nRead all holdings\nLoop β decision_agent\nConcentration risk"]
PA --> DCA
DCA --> END([Telegram Response])
5 nodes total:
| Node | Runs | Parallel |
|---|---|---|
data_agent |
Fetch market data + holdings | β |
fundamental_agent |
Valuation / Growth / Quality | β with sentiment |
sentiment_agent |
News / Analyst ratings | β with fundamental |
decision_agent |
Synthesize β BUY/HOLD/SELL | β |
portfolio_agent |
Loop holdings β decision_agent | β |
Routing logic lives in conditional edges, not a separate node.
sequenceDiagram
participant U as User (Telegram)
participant APP as Cloud Run: app
participant API as Cloud Run: api
participant DB as MongoDB Atlas
participant YF as Yahoo Finance
participant VM as Compute Engine
U->>APP: /decide NVDA
APP->>API: GET /preferences
API->>DB: query
DB-->>API: {style, horizon, risk}
API-->>APP: preferences
APP->>YF: fetch quote + financials + news
YF-->>APP: raw market data
Note over APP: fundamental_agent β sentiment_agent (parallel)
APP->>APP: decision_agent synthesizes
APP->>API: POST /decisions
API->>DB: insert decision record
APP-->>U: BUY/HOLD/SELL + thesis
VM->>API: POST /holdings (every 5min)
API->>DB: upsert holdings snapshot
Every analysis runs through the same framework. Weights adjust based on user preferences.
| Dimension | Agent | Data Source |
|---|---|---|
| Valuation | fundamental_agent | Yahoo Finance (P/E, EV/EBITDA) |
| Growth | fundamental_agent | Yahoo Finance Financials |
| Quality | fundamental_agent | Yahoo Finance / SEC EDGAR |
| Sentiment | sentiment_agent | Brave Search / Yahoo Finance |
| Timing | sentiment_agent | Yahoo Finance (52w range, trend) |
| Method | Endpoint | Caller | Purpose |
|---|---|---|---|
| GET | /holdings |
data_agent | Current Futu positions |
| POST | /holdings |
Sync script | Push holdings snapshot |
| GET | /decisions |
decision_agent | History for thesis tracking |
| POST | /decisions |
decision_agent | Persist verdict |
| GET | /preferences |
Orchestrator edge | User preferences |
| PUT | /preferences |
One-time setup | Write preferences |
{
"synced_at": "2026-05-08T09:25:00Z",
"positions": [
{
"ticker": "NVDA",
"qty": 100,
"cost_price": 650.00,
"market_price": 892.00,
"unrealized_pl": 24200.00,
"unrealized_pl_ratio": 0.372
}
]
}{
"ticker": "NVDA",
"date": "2026-05-08",
"verdict": "BUY",
"confidence": "medium-high",
"thesis": "Blackwell supply ramp + cloud capex upcycle",
"key_assumptions": [
"Blackwell shipments on track",
"China export restrictions stabilize"
],
"stop_loss": 820.00,
"target_price": 1024.00
}{
"style": "growth",
"horizon": "medium",
"risk": "moderate"
}trade-compass/
βββ app/ # Cloud Run: LangGraph + Telegram bot
β βββ agents/
β β βββ data.py
β β βββ fundamental.py
β β βββ sentiment.py
β β βββ decision.py
β β βββ portfolio.py
β βββ graph/
β β βββ workflow.py # LangGraph topology + conditional edges
β βββ tools/
β β βββ market_data.py # Yahoo Finance fetch tools
β β βββ portfolio_api.py # REST API client
β βββ telegram/
β β βββ bot.py # Webhook handler
β βββ Dockerfile
β βββ main.py
βββ api/ # Cloud Run: FastAPI REST API
β βββ routes/
β βββ models/
β βββ Dockerfile
β βββ main.py
βββ sync/ # Compute Engine: Futu sync script
β βββ sync.py
βββ terraform/
βββ bootstrap/ # GCS bucket for tfstate
βββ compute_engine/ # e2-micro VM
βββ atlas/ # MongoDB Atlas M0
βββ cloud_run/ # Both Cloud Run services
| Layer | Technology |
|---|---|
| Agent orchestration | LangGraph |
| LLM connectors | LangChain (langchain-anthropic) |
| LLM | Claude Sonnet via OpenRouter |
| Telegram bot | python-telegram-bot (webhook mode) |
| REST API | FastAPI + Motor (async MongoDB driver) |
| Brokerage sync | futu-api (Python) |
| Database | MongoDB Atlas M0 (free) |
| Infrastructure | Terraform + GCP |
| Component | Cost |
|---|---|
| Cloud Run (app + api) | $0 β scale to zero, personal usage within free tier |
| Compute Engine e2-micro (us-west1) | $0 β GCP always-free tier |
| MongoDB Atlas M0 | $0 β free tier |
| GCS tfstate bucket | < $0.01/month |
| Total | ~$0/month |