How anuranpaul/kalshi-mispricing-arbitrage-engine works
KalshiEngine is a paper-only Kalshi market observer: its principal workflow ingests demo WebSocket snapshots and deltas, reconstructs fresh YES/NO books, detects and deduplicates estimated complementary mispricing, then publishes observed events for persistence and live display. Separate read-only REST commands support smoke checks; the product does not execute orders. The README documents the major flow and capabilities, while sampled excerpts confirm key book, WebSocket, deduplication, storage, gateway, and UI behavior; some subsystem wiring is therefore based on that documentation.
Main entry points: main.go CLI Orchestrator · ws/client.go WebSocket Client · server.go SSE / REST Gateway · rest/client.go Read-only REST
Components 24
Market Ingestion
- RSA-PSS Signer
internal/kalshi/auth/auth.go - Read-only REST
internal/kalshi/rest/client.go - WebSocket Client
internal/kalshi/ws/client.go - Book Registry
internal/book/registry.go - Market State
internal/book/market.go - YES/NO Ladders
internal/book/ladder.go - Redis Cache
internal/book/redis.go
Detection Engine
- Mispricing Detector
internal/detect/detect.go - Depth Walk
internal/detect/depth.go - Fee Model
internal/detect/fee.go - Opportunity Dedup
internal/detect/dedup.go - Event Publisher
internal/detect/publisher.go
Event Persistence
- NATS JetStream
- Pull Consumer
internal/consume/consumer.go - TimescaleDB Store
internal/store/store.go
Monitoring UI
- SSE / REST Gateway
internal/gateway/server.go - Health / Metrics
internal/health/health.go - Dashboard
web/src/App.tsx
Runtime Support
- CLI Orchestrator
cmd/kalshiengine/main.go - Configuration
internal/config/config.go - Exact Decimal
internal/money/amount.go - Order Safety Guard
internal/guard/guard.go
Other components
- Operator
- Kalshi Demo
Connections 31
- Operator → CLI Orchestrator: runs command
- CLI Orchestrator → Configuration: loads settings
- CLI Orchestrator → RSA-PSS Signer: loads signer
- CLI Orchestrator → Read-only REST: runs smoke checks
- Read-only REST → RSA-PSS Signer: signs requests
- Read-only REST → Order Safety Guard: checks paths
- Read-only REST → Kalshi Demo: GET requests
- CLI Orchestrator → WebSocket Client: starts ingestion
- WebSocket Client → RSA-PSS Signer: signs connection
- WebSocket Client → Kalshi Demo: connects / subscribes
- Kalshi Demo → WebSocket Client: sends book frames
- WebSocket Client → Book Registry: updates books
- Book Registry → Market State: ensures markets
- Market State → YES/NO Ladders: updates levels
- Market State → Redis Cache: caches snapshots
- CLI Orchestrator → Exact Decimal: uses exact amounts
- WebSocket Client → Mispricing Detector: evaluates live books
- Mispricing Detector → Depth Walk: walks liquidity
- Mispricing Detector → Fee Model: estimates fees
- WebSocket Client → Opportunity Dedup: evaluates results
- WebSocket Client → Event Publisher: publishes decisions
- Event Publisher → NATS JetStream: sends events
- CLI Orchestrator → Pull Consumer: starts consumer
- NATS JetStream → Pull Consumer: delivers events
- Pull Consumer → TimescaleDB Store: persists records
- WebSocket Client → SSE / REST Gateway: broadcasts events
- SSE / REST Gateway → Book Registry: reads book views
- SSE / REST Gateway → TimescaleDB Store: queries records
- CLI Orchestrator → SSE / REST Gateway: starts server
- CLI Orchestrator → Health / Metrics: starts endpoints
- Dashboard → SSE / REST Gateway: fetches / streams