Using ExchangeRestClient to access exchange REST APIs
ExchangeRestClient is the main entry point for all REST API interactions across the 26+ supported exchanges. It exposes every exchange-specific client as a property, while also providing shared cross-exchange interfaces and unified multi-exchange request methods.
// Default construction — all exchange clients are created with default optionsIExchangeRestClient client = new ExchangeRestClient();
// Configure global and per-exchange options at construction timeIExchangeRestClient client = new ExchangeRestClient( globalOptions: options => { options.OutputOriginalData = true; options.RequestTimeout = TimeSpan.FromSeconds(10); }, binanceRestOptions: options => { options.ApiCredentials = new BinanceCredentials("key", "secret"); });
// Register all clients in one callbuilder.Services.AddCryptoClients(options =>{ options.ApiCredentials = new ExchangeCredentials { Binance = new BinanceCredentials("BinanceKey", "BinanceSecret"), Kucoin = new KucoinCredentials("KucoinKey", "KucoinSecret", "KucoinPassphrase"), OKX = new OKXCredentials("OKXKey", "OKXSecret", "OKXPassphrase") };});// Inject IExchangeRestClient wherever neededpublic class TradingBot{ public TradingBot(IExchangeRestClient restClient) { }}
Always depend on IExchangeRestClient rather than the concrete ExchangeRestClient class to keep your code testable and DI-friendly.
ExchangeRestClient supports four distinct usage patterns, each suited to different scenarios.
1
Exchange-specific clients (direct)
Use the individual exchange libraries directly when you need access to the full exchange-specific API surface — proprietary endpoints, exchange-specific models, or features not covered by the shared interfaces.
var kucoinClient = new KucoinRestClient();var binanceClient = new BinanceRestClient();var binanceTicker = await binanceClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");var kucoinTicker = await kucoinClient.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT");
2
Exchange clients through the main client
Use ExchangeRestClient as a single entry point when you need exchange-specific clients but want a single object to manage them all. Each exchange property returns the full, unabstracted client for that exchange.
var client = new ExchangeRestClient();var binanceTicker = await client.Binance.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");var kucoinTicker = await client.Kucoin.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT");var bybitTicker = await client.Bybit.V5Api.ExchangeData.GetSpotTickerAsync("ETHUSDT");
All 26 exchanges are accessible as typed properties: client.Binance, client.Bybit, client.OKX, client.Kraken, client.HTX, client.GateIo, and so on.
3
Shared client interfaces
Use the shared CryptoExchange.Net interfaces to write exchange-agnostic logic. A method that accepts ISpotTickerRestClient works the same way regardless of which exchange backs it.
async Task<ExchangeWebResult<SharedSpotTicker>> GetTickerAsync( ISpotTickerRestClient client, SharedSymbol symbol) => await client.GetSpotTickerAsync(new GetTickerRequest(symbol));var client = new ExchangeRestClient();var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT");// The same method works for any exchangevar binanceResult = await GetTickerAsync(client.Binance.SpotApi.SharedClient, symbol);var kucoinResult = await GetTickerAsync(client.Kucoin.SpotApi.SharedClient, symbol);
Query the same data from multiple exchanges in a single call. ExchangeRestClient dispatches the requests concurrently and collects the results.
var client = new ExchangeRestClient();var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT");var tickers = await client.GetSpotTickerAsync( new GetTickerRequest(symbol), [Exchange.Binance, Exchange.Kucoin, Exchange.OKX]);foreach (var result in tickers){ if (!result.Success) Console.WriteLine($"{result.Exchange} error: {result.Error}"); else Console.WriteLine($"{result.Exchange} last price: {result.Data.LastPrice}");}
IExchangeRestClient exposes unified request methods that work across all exchanges. Each method has three variants — single exchange, Task array (all results at once), and IAsyncEnumerable (streaming as results arrive).
// Total REST requests made across all underlying clientsint total = client.TotalRequestsMade;// Translate a SharedSymbol into an exchange-native symbol namestring? symbol = client.GetSymbolName("Binance", new SharedSymbol(TradingMode.Spot, "ETH", "USDT"));// Generate a client order id for a specific exchange and trading modestring? orderId = client.GenerateClientOrderId(TradingMode.Spot, "Bybit");// Get all shared-interface clients for one exchange (optionally filtered by trading mode)IEnumerable<ISharedClient> shared = client.GetExchangeSharedClients("Kraken", TradingMode.Spot);
// Set credentials for multiple exchanges at onceclient.SetApiCredentials(new ExchangeCredentials{ Binance = new BinanceCredentials("key", "secret"), OKX = new OKXCredentials("key", "secret", "passphrase")});// Set credentials for one exchange using dynamic credentialsclient.SetApiCredentials("Bybit", new DynamicCredentials(TradingMode.Spot, "key", "secret"));