Skip to main content

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:
  1. High-level: Use streamQuotes / streamQuotesByTicker convenience methods on MakerClient
  2. Low-level: Use WSClient directly with event-based message handling

Enabling WebSocket

Before streaming quotes, enable the WebSocket connection:
The URL includes a client ID for session tracking. The 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.
Options:

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 the WSClient directly.

Connection

Events

Subscribe to events using on / 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

Subscribe to disconnected and reconnecting events. The WSClient automatically reconnects with exponential backoff, but you should handle the case where max attempts are exceeded.
streamQuotesByTicker handles route discovery, connection management, and quote routing for you. Only use the low-level WSClient when you need custom control.
Always call the unsubscribe function returned by streamQuotes / streamQuotesByTicker when you no longer need quotes. This prevents memory leaks and unnecessary network traffic.
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