Overview
The SDK provides WebSocket support for real-time quote streaming. The WebSocket client handles connection management, automatic reconnection with exponential backoff, and ping/pong keep-alive. There are two ways to use WebSocket:- High-level: Use
streamQuotes/streamQuotesByTickerconvenience methods onMakerClient - Low-level: Use
WSClientdirectly with event-based message handling
Enabling WebSocket
Before streaming quotes, enable the WebSocket connection:enableWebSocket method returns a WSClient instance.
The examples on this page use Signet, which is also the SDK default. Match the WebSocket URL to the environment your
baseUrl points at. See Available Environments.High-Level API
streamQuotesByTicker / stream_quotes_by_ticker
The simplest way to stream quotes. Automatically discovers routes and starts streaming.
streamQuotes / stream_quotes
Stream quotes for a specific route (tickers and layers).
streamQuotesForAllRoutes / stream_quotes_for_all_routes
Stream quotes for all available routes between two tickers simultaneously.
getAvailableRoutes / get_available_routes
Discover available routes for a pair before streaming.
Low-Level WSClient API
For full control, use theWSClient directly.
Connection
Events
Subscribe to events usingon / off:
Requesting Quotes
Ping / Keep-Alive
The WSClient automatically pings the server at the configured interval. You can also ping manually:Configuration
The WSClient accepts configuration options:
Reconnection uses exponential backoff:
delay * 2^attempt.
WebSocket Protocol
The WebSocket uses a JSON message protocol:Message Types
QuoteResponse Fields
Each
SwapLegData object describes one leg of the swap:
Best Practices
Handle disconnections gracefully
Handle disconnections gracefully
Subscribe to
disconnected and reconnecting events. The WSClient automatically reconnects with exponential backoff, but you should handle the case where max attempts are exceeded.Use the high-level API when possible
Use the high-level API when possible
streamQuotesByTicker handles route discovery, connection management, and quote routing for you. Only use the low-level WSClient when you need custom control.Unsubscribe when done
Unsubscribe when done
Always call the unsubscribe function returned by
streamQuotes / streamQuotesByTicker when you no longer need quotes. This prevents memory leaks and unnecessary network traffic.Use rfq_id from quotes to initiate swaps
Use rfq_id from quotes to initiate swaps
The
rfq_id in each quote response is what you pass to initSwap (POST /api/v1/swaps/init). Use the most recent quote to ensure the rate is still valid.Next Steps
Examples
See WebSocket streaming in complete end-to-end examples
Client Reference
Full reference for all streaming methods on MakerClient
Types
QuoteResponse, QuoteRequest, and other WebSocket type definitions
Best Practices
Reconnection strategies and production patterns