Introduction
In the world of automated crypto trading, the reliability of market data is fundamental to the success of any market making bot. Whether you are supporting a new token launch or maintaining healthy liquidity on established pairs, your bot’s ability to accurately interpret and act on real-time market data directly impacts its effectiveness. This post explores the engineering considerations and best practices for handling WebSocket and REST data streams in market making bots, with a focus on spot markets and genuine liquidity provision.
Why Data Handling Matters in Market Making
Market making bots operate by continuously placing and adjusting limit orders based on the latest market conditions. To do this effectively, they must:
- Receive timely and accurate ticker and order book data
- Detect and respond to stale or inconsistent data
- Maintain a resilient connection to the exchange, even during network hiccups
- Avoid acting on crossed or out-of-date order books
Failures in any of these areas can lead to mispriced orders, missed opportunities, or in the worst case, unintended trading losses.
WebSocket vs. REST: The Two Pillars of Exchange Data
Most centralized crypto exchanges provide two primary ways to access market data:
- WebSocket Streams: Deliver real-time updates for tickers, order books, trades, and more. Ideal for low-latency, high-frequency trading bots.
- REST APIs: Allow bots to request the latest snapshot of market data on demand. Useful as a fallback or for periodic verification.
A robust market making bot leverages both, using WebSocket for primary data and REST as a backup or verification layer.
WebSocket Advantages
- Low latency: Updates arrive as soon as the market changes.
- Efficient: Reduces the need for frequent polling.
- Supports event-driven logic (e.g., reacting instantly to a new trade or price move).
REST Advantages
- Simplicity: Easy to implement and debug.
- Reliability: Useful for recovering from WebSocket disconnects or verifying data integrity.
- Completeness: Can fetch full order book snapshots or account states.
Engineering for Data Reliability: Best Practices
1. Data Freshness Checks
Every tick, the bot should verify that the received ticker and order book data are fresh. For example, Atlas LP’s bot skips a tick if the data is stale or shows a crossed order book. This prevents acting on outdated or inconsistent information.
Checklist:
- Validate timestamps or sequence numbers on incoming data
- Discard or ignore data that is too old or out of order
- Monitor for crossed order books (bid price ≥ ask price)
2. WebSocket Connection Management
WebSocket connections can drop due to network issues, exchange maintenance, or API rate limits. A resilient bot:
- Detects disconnects and attempts automatic reconnection
- Falls back to REST API to fill data gaps during reconnection
- Resubscribes to relevant channels after reconnecting
Tip: Implement exponential backoff for reconnection attempts to avoid overwhelming the exchange.
3. REST Fallbacks and Verification
Even with a stable WebSocket connection, periodic REST calls are valuable for:
- Verifying that the bot’s local order book matches the exchange’s current state
- Detecting missed updates or dropped messages
- Seeding the order book when the market has no quotes (placing the first buy and sell orders around the base price)
Example: If the WebSocket stream lags or drops, the bot can fetch a fresh order book snapshot via REST and reconcile any discrepancies.
4. Tick Scheduling and Data Synchronization
Bots must balance responsiveness with API rate limits. Atlas LP, for example, allows tick intervals from 0.5 seconds (default 3 seconds), ensuring frequent updates without overloading the exchange.
Best Practices:
- Schedule ticks at a configurable interval, respecting exchange rate limits
- On each tick, synchronize open orders, recent fills, balances, and bot events
- Skip ticks if data is stale or inconsistent
5. Handling Exchange-Specific Edge Cases
Every exchange has unique API behaviors, such as symbol rules, minimum order sizes, or event sequencing. Robust bots:
- Validate all settings and symbol rules before starting
- Perform detailed API verification (tickers, order books, balances, open orders, trades)
- Optionally place and cancel a test limit order far from the market to verify trading permissions
6. Secure and Compliant Data Handling
Security is paramount when dealing with exchange APIs. Bots should:
- Encrypt API keys and secrets (e.g., AES-256-GCM as used by Atlas LP)
- Never request withdrawal permissions
- Only decrypt secrets when necessary for API calls
- Prohibit wash trading, self-trading, or any form of volume manipulation
Putting It All Together: A Typical Data Handling Cycle
Here’s how a well-engineered market making bot processes data each tick:
- Receive Data: Fetch the latest ticker and order book via WebSocket (or REST if needed)
- Validate: Check for freshness, consistency, and non-crossed order books
- Compute Ladder: Calculate the desired spread band and order levels based on the current market
- Order Management: Place missing limit orders, cancel excess or mispriced orders
- Sync State: Update open orders, recent fills, balances, and log events
- Alerting: Optionally send Telegram alerts if no fills occur for a set period
This cycle repeats at the configured tick interval, ensuring the bot remains in sync with the market and maintains genuine, tradable liquidity.
Table: WebSocket vs. REST in Market Making Bots
| Feature | WebSocket | REST API |
|---|
| Latency | Low (real-time) | Higher (on request) |
| Data Volume | Continuous stream | Per-request |
| Use Case | Live updates | Snapshots, verification |
| Failure Handling | Needs reconnection | Retry on error |
| Rate Limit Impact | Lower (if managed) | Higher (frequent calls) |
Conclusion
Reliable data handling is the backbone of effective market making in crypto spot markets. By engineering bots to combine real-time WebSocket streams with REST API verification, and by rigorously validating data before acting, teams can ensure accurate order placement and resilient uptime. These principles are core to Atlas LP’s approach to spot market making across supported exchanges.
To learn more about Atlas LP’s approach to secure, reliable market making, visit [/liquidity-bot].
Atlas LP does not guarantee returns, prices, trading volume, or token listings.
Crypto trading involves risk. Atlas LP is software for placing and managing limit orders; it does not guarantee returns, prices, volume or listings. Follow the rules of each exchange and applicable law.