Skip to main content

Architecture Overview

Operating modes

The bridge runs in three modes controlled by --mode:
Only one --mode both process should run. Multiple instances running background jobs (auto-flatten, Holly watcher, scheduler) will duplicate market orders.

Data flow

Market data

  1. TWS streams quotes via @stoqey/ib
  2. Bridge caches and serves via REST (/api/quote/:symbol)
  3. Frontend polls via React Query hooks (5–60s intervals)
  4. WebSocket broadcasts push real-time updates to open pages

Order execution

  1. User (or MCP tool) calls place_advanced_bracket
  2. Bridge builds Contract + Order objects via @stoqey/ib
  3. TWS executes, streams back orderStatus events
  4. Bridge writes to event store + broadcasts via WebSocket
  5. Frontend invalidates order cache on WS message

Holly AI pipeline

  1. Trade Ideas sends Holly alerts via CSV import or watcher
  2. Bridge stores in holly_alerts table
  3. Auto-eval pipeline scores each alert through 3 AI models
  4. Signals above threshold appear on /signals page
  5. User reviews and executes via bracket order

Database

Single SQLite file at data/bridge.db using an event-sourced architecture:

Key directories

Client ID management

Multiple processes can connect to TWS simultaneously using PID-based client ID slotting: Formula: base + modeOffset + (pid % 5) * 3