Skip to main content

DeepBook Flux Stream

The Deepbook Flux Stream delivers real-time trade executions and order book updates directly from DeepBook, Sui's decentralized Central Limit Order Book (CLOB). Built on Surflux's DeepBook indexer, these streams provide sub-second latency for live market data, enabling instant visualization and analysis of trading activity.

Unlike the Deepbook Indexing API which provides historical snapshots, Flux Streams push live events as they occur on-chain—no polling, no delays.

What You Can Build

Deepbook Flux Streams power real-time DeFi applications:

  • Live Trading Dashboards — Display trade feeds, order book depth, and price updates in real-time
  • Market Monitoring Tools — Track liquidity changes, spread movements, and trading volume instantly
  • Trading Bots — Trigger automated strategies based on live order fills and book updates
  • Analytics Pipelines — Ingest streaming data for real-time metrics and historical analysis
  • Price Charts — Build live candlestick charts and technical indicators from trade streams

Stream Types

Live Trades

Real-time stream of completed order fills from a Deepbook pool. Each event includes:

  • Trade execution details (price, quantities, maker/taker)
  • Fee information and order IDs
  • Transaction metadata and timestamps

View Live Trades Documentation →

Order Book Depth

Real-time updates to the order book state. Each event includes:

  • Current bid and ask levels with prices
  • Total quantity available at each level
  • Order count per price level

View Order Book Depth Documentation →

How It Works

Deepbook Flux Streams use Server-Sent Events (SSE), a standard HTTP-based protocol for real-time push notifications.

Connection Flow

  1. Connect — Open SSE connection to /deepbook/{poolName}/live-trades with your API key
  2. Stream — Receive events as trades execute and order books update on-chain
  3. Process — Handle events in your application to update UI or trigger logic

Latency

Events are emitted with 1-2 second latency from on-chain finalization. This includes:

  • Blockchain confirmation time
  • Indexer processing
  • Event delivery via SSE

For most trading interfaces and analytics tools, this latency is more than sufficient for real-time user experiences.

Pool Scoping

Each stream is scoped to a specific trading pool. Connect to different pools by changing the poolName path parameter:

# SUI/USDC pool
https://flux.surflux.dev/deepbook/SUI_USDC/live-trades

# NS/SUI pool
https://flux.surflux.dev/deepbook/NS_SUI/live-trades

Use the Get Pools endpoint to retrieve all available pool names.

Quick Start

Connect to Live Stream

const poolName = 'SUI_USDC';
const apiKey = 'YOUR_API_KEY';

const eventSource = new EventSource(
`https://flux.surflux.dev/deepbook/${poolName}/live-trades?api-key=${apiKey}`
);

eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);

if (data.type === 'deepbook_live_trades') {
console.log('Trade executed:', {
price: data.data.price,
baseQuantity: data.data.base_quantity,
takerIsBid: data.data.taker_is_bid
});
}

if (data.type === 'deepbook_order_book_depth') {
console.log('Order book updated:', {
bids: data.data.bids.length,
asks: data.data.asks.length
});
}
};

eventSource.onerror = (error) => {
console.error('Connection error:', error);
// Implement reconnection logic
};

Handle Both Event Types

The /live-trades endpoint streams both trade executions and order book depth updates. Filter by the type field:

  • deepbook_live_trades — Trade execution events
  • deepbook_order_book_depth — Order book state updates

Why SSE Instead of WebSockets?

Server-Sent Events offer several advantages for streaming market data:

  • Simpler Implementation — Native browser support via EventSource API, no library needed
  • Automatic Reconnection — Built-in reconnection handling in the browser
  • Firewall-Friendly — Uses standard HTTP/HTTPS ports and protocols
  • Lower Overhead — One-way push is more efficient than bidirectional WebSockets for read-only streams

For more details on SSE, see What are Server-Sent Events?

Authentication

All Deepbook Flux Streams require authentication via API key. Include your key as a query parameter:

?api-key=YOUR_API_KEY

Don't have an API key yet? Create your Surflux account to get started.

Base URLs

Mainnet:

https://flux.surflux.dev/

Testnet:

https://testnet-flux.surflux.dev/

Best Practices

  • Handle Both Event Types — The stream includes both trades and order book updates. Check the type field to route events correctly.
  • Implement Reconnection Logic — SSE connections can drop. Use exponential backoff to reconnect automatically.
  • Process Events Asynchronously — Don't block the event stream with heavy processing. Use background workers or queues.
  • Cache Pool Metadata — Fetch pool decimals once from Get Pools and reuse for price conversions.
  • Combine with Historical Data — Use Deepbook Indexing API to backfill historical data, then switch to Flux Streams for live updates.

Next Steps

Choose the event type you need:


Additional Resources