AddCryptoClients is an extension method on IServiceCollection that registers all exchange clients plus the aggregation interfaces (IExchangeRestClient, IExchangeSocketClient, etc.) in a single call.
Setup
Register services
Call
AddCryptoClients during application startup. Choose one of the two
configuration styles below.- From IConfiguration
- From code
Load all settings from
appsettings.json (or any other configuration
source). The section name passed here must match the key in your
configuration file.Registered services
AddCryptoClients registers the following interfaces:
| Interface | Implementation | Lifetime |
|---|---|---|
IExchangeRestClient | ExchangeRestClient | Transient |
IExchangeSocketClient | ExchangeSocketClient | Singleton (default) |
IExchangeOrderBookFactory | ExchangeOrderBookFactory | Transient |
IExchangeTrackerFactory | ExchangeTrackerFactory | Transient |
IExchangeUserClientProvider | ExchangeUserClientProvider | Transient |
IBinanceRestClient) and socket clients (e.g. IBybitSocketClient) are also registered by each exchange’s own AddXxx call, and are available for injection directly.
Changing socket client lifetime
By default socket clients are registered as singletons so a single connection is shared across the application. You can change this:Injecting factory and tracker services
UseIExchangeOrderBookFactory to create live order books and IExchangeTrackerFactory to create price and funding-rate trackers:
Complete minimal API example
The following is a complete ASP.NET Core minimal API that exposes a cross-exchange ticker endpoint. No additional setup is required beyond the singleAddCryptoClients call:
GET /Ticker/Kraken/ETH/BTCGET /Ticker/Kucoin/BTC/USDT