# pkjoshi23/moomoo-paper-python architecture

> Architecture diagram of the GitHub repository pkjoshi23/moomoo-paper-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pkjoshi23/moomoo-paper-python
- Repository: https://github.com/pkjoshi23/moomoo-paper-python

## Overview

Moomoo Pilot is a paper-only US-stock trading system with two execution paths: a scheduled Cloud Agent and a local event-driven runtime. The local path receives OpenD market events, evaluates exits and entries, applies synchronous risk checks, and submits simulated orders; offline replay reuses the runtime. A separate deterministic fixture pipeline produces inspectable intents without a broker. The read-only dashboard monitors account and market data. Edges follow excerpts and README statements; unsampled dashboard wiring is represented conservatively.

Main entry points: [`moomoo_pilot/runtime/engine.py`](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/engine.py) (Trading engine), [`moomoo_pilot/daemon.py`](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/daemon.py) (Runtime launcher), [`moomoo_pilot/pipeline.py`](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/pipeline.py) (Fixture pipeline), [`moomoo_pilot/runtime/gateway.py`](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/gateway.py) (OpenD gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_pilot["Pilot decisions"]
  node_fixtures["Fixture inputs<br/>[fixtures.py]"]
  node_selector["Universe selector<br/>[universe.py]"]
  node_strategy["Entry strategy<br/>[strategy.py]"]
  node_exit["Exit evaluator<br/>[exit.py]"]
  node_risk["Risk gate<br/>[risk.py]"]
  node_config["Paper rules<br/>[config.py]"]
  node_intents["Order intents<br/>[models.py]"]
  node_cli["Fixture pipeline<br/>[pipeline.py]"]
end

subgraph group_runtime["Event runtime"]
  node_daemon["Runtime launcher<br/>[daemon.py]"]
  node_gateway["OpenD gateway<br/>[gateway.py]"]
  node_events["Event types<br/>[events.py]"]
  node_normalize["Event normalization<br/>[normalize.py]"]
  node_bus["Async event bus<br/>[bus.py]"]
  node_clock["Runtime clock<br/>[clock.py]"]
  node_engine["Trading engine<br/>[engine.py]"]
  node_recorder["Session recorder<br/>[recorder.py]"]
  node_replay["Session replay<br/>[replay.py]"]
end

subgraph group_agent["Managed agent"]
  node_cloud["Managed Cloud Agent<br/>[cloud-agents.mjs]"]
end

subgraph group_dashboard["Monitoring dashboard"]
  node_dashboard["Read-only dashboard<br/>[app.js]"]
  node_routes["Dashboard functions<br/>[handler.mjs]"]
  node_live["Live data endpoint<br/>[live.mjs]"]
  node_status["Agent status endpoint<br/>[status.mjs]"]
end

node_operator(("Operator"))
node_mcp{{"Moomoo MCP"}}
node_opend{{"Local OpenD"}}
node_account[("Paper account")]
node_web(("Dashboard viewer"))

node_operator -->|"runs fixtures"| node_cli
node_cli -->|"checks paper mode"| node_config
node_cli -->|"loads quotes"| node_fixtures
node_cli -->|"selects candidates"| node_selector
node_cli -->|"evaluates entries"| node_strategy
node_strategy -.->|"returns intents"| node_intents
node_daemon -->|"starts live gateway"| node_gateway
node_gateway -->|"subscribes and trades"| node_opend
node_gateway -->|"normalizes pushes"| node_normalize
node_normalize -->|"creates events"| node_events
node_gateway -->|"publishes events"| node_bus
node_daemon -->|"runs event loop"| node_bus
node_daemon -->|"configures clock"| node_clock
node_daemon -->|"constructs engine"| node_engine
node_daemon -->|"configures recording"| node_recorder
node_engine -->|"consumes events"| node_bus
node_engine -->|"evaluates exits"| node_exit
node_engine -->|"checks orders inline"| node_risk
node_engine -.->|"submits intents"| node_intents
node_engine -.->|"sends orders"| node_gateway
node_recorder -->|"shares log format"| node_replay
node_replay -->|"publishes replay events"| node_bus
node_replay -->|"advances virtual time"| node_clock
node_replay -->|"drives same engine"| node_engine
node_cloud -->|"submits simulated orders"| node_mcp
node_mcp -->|"acts on paper account"| node_account
node_operator -->|"views monitoring"| node_dashboard
node_dashboard -.->|"requests live data"| node_live
node_routes -->|"routes requests"| node_live
node_routes -->|"routes requests"| node_status
node_status -->|"reads agent status"| node_cloud

click node_fixtures "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/fixtures.py"
click node_selector "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/universe.py"
click node_strategy "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/strategy.py"
click node_exit "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/exit.py"
click node_risk "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/risk.py"
click node_config "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/config.py"
click node_intents "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/models.py"
click node_cli "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/pipeline.py"
click node_daemon "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/daemon.py"
click node_gateway "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/gateway.py"
click node_events "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/events.py"
click node_normalize "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/normalize.py"
click node_bus "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/bus.py"
click node_clock "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/clock.py"
click node_engine "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/engine.py"
click node_recorder "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/recorder.py"
click node_replay "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/replay.py"
click node_cloud "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/cloud-agents.mjs"
click node_dashboard "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/app.js"
click node_routes "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/handler.mjs"
click node_live "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/live.mjs"
click node_status "https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/status.mjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_fixtures,node_selector,node_strategy,node_exit,node_risk,node_config,node_intents,node_cli,node_web toneBlue
class node_daemon,node_gateway,node_events,node_normalize,node_bus,node_clock,node_engine,node_recorder,node_replay,node_account toneAmber
class node_cloud toneMint
class node_dashboard,node_routes,node_live,node_status toneRose
class node_operator,node_mcp,node_opend toneIndigo
```

## Components

### Pilot decisions

- [Fixture inputs](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/fixtures.py): `moomoo_pilot/fixtures.py`
- [Universe selector](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/universe.py): `moomoo_pilot/universe.py`
- [Entry strategy](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/strategy.py): `moomoo_pilot/strategy.py`
- [Exit evaluator](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/exit.py): `moomoo_pilot/exit.py`
- [Risk gate](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/risk.py): `moomoo_pilot/risk.py`
- [Paper rules](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/config.py): `moomoo_pilot/config.py`
- [Order intents](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/models.py): `moomoo_pilot/models.py`
- [Fixture pipeline](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/pipeline.py): `moomoo_pilot/pipeline.py`

### Event runtime

- [Runtime launcher](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/daemon.py): `moomoo_pilot/daemon.py`
- [OpenD gateway](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/gateway.py): `moomoo_pilot/runtime/gateway.py`
- [Event types](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/events.py): `moomoo_pilot/runtime/events.py`
- [Event normalization](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/normalize.py): `moomoo_pilot/runtime/normalize.py`
- [Async event bus](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/bus.py): `moomoo_pilot/runtime/bus.py`
- [Runtime clock](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/clock.py): `moomoo_pilot/runtime/clock.py`
- [Trading engine](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/engine.py): `moomoo_pilot/runtime/engine.py`
- [Session recorder](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/recorder.py): `moomoo_pilot/runtime/recorder.py`
- [Session replay](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/moomoo_pilot/runtime/replay.py): `moomoo_pilot/runtime/replay.py`

### Managed agent

- [Managed Cloud Agent](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/cloud-agents.mjs): `dashboard/functions/cloud-agents.mjs`

### Monitoring dashboard

- [Read-only dashboard](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/app.js): `dashboard/app.js`
- [Dashboard functions](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/handler.mjs): `dashboard/functions/handler.mjs`
- [Live data endpoint](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/live.mjs): `dashboard/functions/live.mjs`
- [Agent status endpoint](https://github.com/pkjoshi23/moomoo-paper-python/blob/main/dashboard/functions/status.mjs): `dashboard/functions/status.mjs`

### Other components

- **Operator**
- **Moomoo MCP**
- **Local OpenD**
- **Paper account**
- **Dashboard viewer**

## Connections

- Operator → Fixture pipeline: runs fixtures (evidence: `README.md`)
- Fixture pipeline → Paper rules: checks paper mode (evidence: `moomoo_pilot/pipeline.py`)
- Fixture pipeline → Fixture inputs: loads quotes (evidence: `moomoo_pilot/pipeline.py`)
- Fixture pipeline → Universe selector: selects candidates (evidence: `moomoo_pilot/pipeline.py`)
- Fixture pipeline → Entry strategy: evaluates entries (evidence: `moomoo_pilot/pipeline.py`)
- Entry strategy → Order intents: returns intents (evidence: `moomoo_pilot/strategy.py`)
- Runtime launcher → OpenD gateway: starts live gateway (evidence: `moomoo_pilot/daemon.py`)
- OpenD gateway → Local OpenD: subscribes and trades (evidence: `moomoo_pilot/runtime/gateway.py`)
- OpenD gateway → Event normalization: normalizes pushes (evidence: `moomoo_pilot/runtime/gateway.py`)
- Event normalization → Event types: creates events (evidence: `moomoo_pilot/runtime/normalize.py`)
- OpenD gateway → Async event bus: publishes events (evidence: `moomoo_pilot/runtime/gateway.py`)
- Runtime launcher → Async event bus: runs event loop (evidence: `moomoo_pilot/daemon.py`)
- Runtime launcher → Runtime clock: configures clock (evidence: `moomoo_pilot/daemon.py`)
- Runtime launcher → Trading engine: constructs engine (evidence: `moomoo_pilot/daemon.py`)
- Runtime launcher → Session recorder: configures recording (evidence: `moomoo_pilot/daemon.py`)
- Trading engine → Async event bus: consumes events (evidence: `moomoo_pilot/runtime/engine.py`)
- Trading engine → Exit evaluator: evaluates exits (evidence: `moomoo_pilot/runtime/engine.py`)
- Trading engine → Risk gate: checks orders inline (evidence: `moomoo_pilot/runtime/engine.py`)
- Trading engine → Order intents: submits intents (evidence: `moomoo_pilot/runtime/engine.py`)
- Trading engine → OpenD gateway: sends orders
- Session recorder → Session replay: shares log format (evidence: `moomoo_pilot/runtime/recorder.py`)
- Session replay → Async event bus: publishes replay events (evidence: `moomoo_pilot/runtime/replay.py`)
- Session replay → Runtime clock: advances virtual time (evidence: `moomoo_pilot/runtime/replay.py`)
- Session replay → Trading engine: drives same engine (evidence: `moomoo_pilot/runtime/replay.py`)
- Managed Cloud Agent → Moomoo MCP: submits simulated orders (evidence: `README.md`)
- Moomoo MCP → Paper account: acts on paper account (evidence: `README.md`)
- Operator → Read-only dashboard: views monitoring (evidence: `README.md`)
- Read-only dashboard → Live data endpoint: requests live data
- Dashboard functions → Live data endpoint: routes requests (evidence: `dashboard/functions/index.ts`)
- Dashboard functions → Agent status endpoint: routes requests (evidence: `dashboard/functions/index.ts`)
- Agent status endpoint → Managed Cloud Agent: reads agent status (evidence: `dashboard/functions/status.mjs`)
