Skip to main content
ExchangeOrderBookFactory (interface: IExchangeOrderBookFactory) creates locally-maintained ISymbolOrderBook instances that stay in sync with an exchange’s order book in real time via WebSocket. Inject IExchangeOrderBookFactory through dependency injection or resolve it from the service container after calling services.AddCryptoClients().

Methods

Create(SharedSymbol, ...)

Create a live order book for a symbol across all exchanges (or a specified subset) that support that symbol.
symbol
SharedSymbol
required
The symbol to create order books for. Use TradingMode.Spot, TradingMode.PerpetualLinear, etc. to specify the market.
minimalDepth
int?
Minimum number of price levels to maintain on each side. The factory selects the smallest depth tier supported by the exchange that satisfies this requirement. If the requested depth exceeds all supported tiers, the largest available tier is used. Pass null for the exchange default.
exchanges
IEnumerable<string>?
Optional list of exchange names to restrict the result to. When omitted, order books are created for every exchange that supports the symbol.
exchangeParameters
ExchangeParameters?
Exchange-specific parameters. For example, Bitget requires a ProductType parameter ("UsdtFutures" or "UsdcFutures").
Returns ISymbolOrderBook[] — one entry per supporting exchange.
// BTC/USDT order book on every supporting exchange, at least 20 levels deep
ISymbolOrderBook[] books = factory.Create(
    new SharedSymbol(TradingMode.Spot, "BTC", "USDT"),
    minimalDepth: 20);

foreach (var book in books)
{
    await book.StartAsync();
    Console.WriteLine($"{book.Symbol}  bid={book.BestBid?.Price}  ask={book.BestAsk?.Price}");
}

Create(string exchange, SharedSymbol, ...)

Create a live order book for a symbol on a specific exchange.
exchange
string
required
The exchange name (e.g. "Binance", "Bybit", "OKX").
symbol
SharedSymbol
required
The symbol to subscribe to.
minimalDepth
int?
Minimum order book depth. See the description above.
exchangeParameters
ExchangeParameters?
Exchange-specific parameters.
Returns ISymbolOrderBook?null if the exchange does not support the symbol or trading mode.
ISymbolOrderBook? book = factory.Create("Binance",
    new SharedSymbol(TradingMode.Spot, "ETH", "USDT"),
    minimalDepth: 10);

if (book != null)
{
    await book.StartAsync();

    // Access the order book
    Console.WriteLine($"Best bid: {book.BestBid?.Price}");
    Console.WriteLine($"Best ask: {book.BestAsk?.Price}");

    // Or iterate all levels
    foreach (var bid in book.Bids)
        Console.WriteLine($"  {bid.Price} x {bid.Quantity}");
}

Exchange-specific factories

Each exchange has a dedicated factory property with exchange-native Create methods that expose exchange-specific options not available through the shared API.
PropertyType
AsterIAsterOrderBookFactory
BinanceIBinanceOrderBookFactory
BingXIBingXOrderBookFactory
BitfinexIBitfinexOrderBookFactory
BitgetIBitgetOrderBookFactory
BitMartIBitMartOrderBookFactory
BitMEXIBitMEXOrderBookFactory
BitstampIBitstampOrderBookFactory
BloFinIBloFinOrderBookFactory
BybitIBybitOrderBookFactory
CoinbaseICoinbaseOrderBookFactory
CoinExICoinExOrderBookFactory
CoinWICoinWOrderBookFactory
CryptoComICryptoComOrderBookFactory
DeepCoinIDeepCoinOrderBookFactory
GateIoIGateIoOrderBookFactory
HTXIHTXOrderBookFactory
HyperLiquidIHyperLiquidOrderBookFactory
KrakenIKrakenOrderBookFactory
KucoinIKucoinOrderBookFactory
MexcIMexcOrderBookFactory
OKXIOKXOrderBookFactory
PolymarketIPolymarketOrderBookFactory
ToobitIToobitOrderBookFactory
UpbitIUpbitOrderBookFactory
WhiteBitIWhiteBitOrderBookFactory
XTIXTOrderBookFactory
Example — exchange-native factory
// Binance spot order book with exchange-native options
var book = factory.Binance.Create(
    new SharedSymbol(TradingMode.Spot, "BTC", "USDT"),
    opts =>
    {
        opts.Limit = 20;
        opts.UpdateInterval = 100; // ms
    });

await book.StartAsync();

Supported depths by exchange

The minimalDepth parameter is mapped to the nearest supported tier for each exchange. The table below shows supported levels; null indicates the full order book is available.
ExchangeSupported depth levels
Aster5, 10, 20 (or full)
Binance5, 10, 20 (or full)
BingX5, 10, 20, 50, 100
Bitfinex1, 25, 100, 250
Bitget5, 15 (or full)
BitMart5, 20, 50 (or full)
BitMEX25 (or full)
BitstampFull
BloFin5, 400
Bybit1, 50, 200, 1000
CoinbaseFull
CoinEx5, 10, 20, 50
CoinWFull
CryptoCom10, 50
DeepCoinFull
GateIo20, 50, 100 (or full)
HTX5, 20, 150, 400 (or full)
HyperLiquidFull
Kraken10, 25, 100, 500, 1000
Kucoin5, 50 (or full)
Mexc5, 10, 20 (or full)
OKX1, 5, 400 (or full)
ToobitFull
Upbit1, 5, 15, 30
WhiteBit1, 5, 10, 20, 30, 50, 100 (or full)
XT5, 10, 20, 50 (or full)
When minimalDepth is set higher than all supported levels, the largest fixed tier is used unless the exchange supports a full order book, in which case null (full) is used.

Full usage example

using CryptoClients.Net;
using CryptoExchange.Net.SharedApis;

// Via dependency injection
var factory = serviceProvider.GetRequiredService<IExchangeOrderBookFactory>();

var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT");

// Create and start order books on Binance and Bybit
var books = factory.Create(symbol, minimalDepth: 10,
    exchanges: ["Binance", "Bybit"]);

foreach (var book in books)
    await book.StartAsync();

// Wait for initial snapshot
await Task.Delay(2000);

foreach (var book in books)
{
    Console.WriteLine($"[{book.Symbol}]");
    Console.WriteLine($"  Best bid: {book.BestBid?.Price}");
    Console.WriteLine($"  Best ask: {book.BestAsk?.Price}");
    Console.WriteLine($"  Spread:   {book.BestAsk?.Price - book.BestBid?.Price}");
}

// Clean up
foreach (var book in books)
    await book.StopAsync();

Build docs developers (and LLMs) love