How tnar/coincheck-rust works
Main Components
From the file tree and README, split the system into these top-level building blocks:
• Configuration Loader (src/config.rs)
• Runtime & Orchestration (src/main.rs + Tokio)
• WebSocket Client (real-time data ingestion)
• REST Client (order management via HTTP)
• Order Book & Trade Data Handler
• Trading Strategy / Decision Engine
• Order Manager (place, cancel, track active orders)
• Balance Manager (get/update balances)
• Graceful Shutdown/Signal Handler
• Logging / Metrics
Relationships and Data Flows
a. Startup Sequence:
– Config Loader reads Config struct (env variables + defaults).
– Main initializes Tokio runtime, logger, and signal listener.
b. Data Ingestion Path:
– WebSocket Client ➔ connects to Coincheck’s WS API
– Incoming messages (order book snapshots, trades) ➔ dispatched to Order Book & Trade Data Handler
– Processed data ➔ sent to Trading Strategy Engine
c. Decision Path:
– Strategy Engine uses best bid/ask and config parameters ➔ decides “BUY” or “SELL” orders
– Sends order requests to Order Manager
d. Order Management Path:
– Order Manager invokes REST Client (via reqwest) to place/cancel orders
– REST responses ➔ updates Balance Manager & active-orders list
– Balance Manager may call REST Client to fetch latest balances
e. Graceful Shutdown Path:
– Signal Handler traps SIGINT/SIGTERM ➔ informs Order Manager to cancel all active orders ➔ waits for confirmations ➔ exits
Architectural Patterns & Design Principles
• Asynchronous, event-driven: uses Tokio for concurrency.
• Separation of concerns: distinct modules for config, data ingestion, strategy, order management.
• Layered design:
– Infrastructure Layer (WS & HTTP clients)
– Domain Layer (order book, strategy, manager)
– Application Layer (main startup & shutdown coordination)
• Dependency injection via module boundaries (each src/exchanges/coincheck/*.rs file encapsulates one API call).
Technologies & Libraries
– Tokio (async runtime, WebSocket streams)
– Reqwest (HTTP client)
– Serde / serde_json (JSON serialization)
– Env_logger (logging, controlled by RUST_LOG)
– Signal Hook (graceful shutdown)