Cross-post. Original: stellarbytecapital.com/blog/exchange-api-integration
Every trading system eventually meets an exchange API, and that's where clean architecture meets messy reality. The strategy is deterministic and testable; the exchange connection is asynchronous, rate-limited, occasionally down, and the sole authority on whether your order actually exists. Most "the bot lost money" incidents trace back not to the strategy but to this seam — a dropped WebSocket, a throttled cancel, an order placed twice.
REST and WebSocket: two channels, two jobs
REST is request/response: place and cancel orders, query balances/positions, fetch history. Authoritative but slower and rate-limited. Use it for actions and reconciliation queries.
WebSocket is a push stream: real-time market data and private order/balance updates. Use it to stay current, not to place orders. Fast but unreliable — it will drop, and messages get missed.






