How gigabraingg/hypaper works
HyPaper is a HyperLiquid-compatible paper-trading backend. Bots submit exchange and account requests; the API routes them through order/account logic, while a market-data worker drives matching and funding. Redis is the live state store, with PostgreSQL receiving selected durable records; API queries and WebSocket subscriptions expose state and updates. The README documents proxied live-market queries and HL-compatible WebSocket channels. Edges reflect the shown route, worker, and event-sink wiring; unsampled route and WebSocket internals are represented only where documented or indexed.
Main entry points: order.ts Order Management · redis.ts Redis Live State · index.ts Worker Coordinator · info.ts Info Queries
Components 25
HTTP API
- API Router
src/api/server.ts - Exchange Actions
src/api/routes/exchange.ts - Info Queries
src/api/routes/info.ts - Paper Account API
src/api/routes/hypaper.ts - Account Initialization
src/api/middleware/auth.ts
Trading Engine
- Order Management
src/engine/order.ts - Positions and Margin
src/engine/position.ts - Margin Checks
src/engine/margin.ts - Fill Model
src/engine/fill.ts - Decimal Math
src/utils/math.ts - Fill Pricing
src/utils/slippage.ts
Market Workers
- Order Matching
src/worker/order-matcher.ts - Funding Worker
src/worker/funding-worker.ts - Worker Coordinator
src/worker/index.ts - Price Updates
src/worker/price-updater.ts - HL WebSocket Client
src/worker/ws-client.ts
State and Persistence
- Redis Live State
src/store/redis.ts - Postgres Event Sink
src/store/pg-sink.ts - Runtime Configuration
src/config.ts
Realtime Interface
- WebSocket Server
src/ws/server.ts - Event Bus
src/worker/index.ts
Other components
- Trading Bot
- HyperLiquid Feed
- PostgreSQL
- HyperLiquid Info API
Connections 37
- Trading Bot → API Router: sends requests
README.md - Trading Bot → WebSocket Server: subscribes
README.md - API Router → Exchange Actions: routes exchange
src/api/server.ts - API Router → Info Queries: routes queries
src/api/server.ts - API Router → Paper Account API: routes account
src/api/server.ts - Exchange Actions → Account Initialization: ensures account
src/api/routes/exchange.ts - Exchange Actions → Order Management: dispatches actions
src/api/routes/exchange.ts - Paper Account API → Account Initialization: ensures account
src/api/routes/hypaper.ts - Account Initialization → Redis Live State: creates account
src/api/middleware/auth.ts - Account Initialization → Postgres Event Sink: queues user sync
src/api/middleware/auth.ts - Order Management → Redis Live State: reads and writes
src/engine/order.ts - Order Management → Margin Checks: checks margin
src/engine/order.ts - Order Management → Order Matching: executes immediate fills
src/engine/order.ts - Order Management → Fill Pricing: computes fill price
src/engine/order.ts - Order Management → Decimal Math: compares prices
src/engine/order.ts - Worker Coordinator → HL WebSocket Client: connects and subscribes
src/worker/index.ts - Worker Coordinator → Price Updates: handles feed data
src/worker/index.ts - Worker Coordinator → Order Matching: matches on price updates
src/worker/index.ts - Worker Coordinator → Funding Worker: starts funding
src/worker/index.ts - HyperLiquid Feed → HL WebSocket Client: streams market data
README.md - HL WebSocket Client → Price Updates: delivers feed messages
src/worker/index.ts - Price Updates → Redis Live State: updates market state
src/worker/price-updater.ts - Order Matching → Redis Live State: reads and updates orders
src/worker/order-matcher.ts - Order Matching → Positions and Margin: updates positions
- Order Matching → Event Bus: emits fill events
src/worker/index.ts - Order Management → Event Bus: emits order updates
src/engine/order.ts - Event Bus → Postgres Event Sink: dispatches events
src/index.ts - Postgres Event Sink → PostgreSQL: persists records
src/store/pg-sink.ts - Info Queries → Redis Live State: reads paper state
src/api/routes/info.ts - Info Queries → Positions and Margin: builds account state
src/api/routes/info.ts - Info Queries → Fill Model: formats fill data
src/api/routes/info.ts - Info Queries → HyperLiquid Info API: proxies live queries
README.md - WebSocket Server → Redis Live State: serves market state
src/ws/server.ts - Event Bus → WebSocket Server: broadcasts updates
- Runtime Configuration → Redis Live State: configures connection
src/store/redis.ts - Worker Coordinator → HyperLiquid Info API: seeds market data
src/worker/index.ts - HyperLiquid Info API → Redis Live State: supplies initial data