Skip to main content
AddCryptoClients is an extension method on IServiceCollection that registers all exchange clients plus the aggregation interfaces (IExchangeRestClient, IExchangeSocketClient, etc.) in a single call.

Setup

1

Install the package

dotnet add package CryptoClients.Net
2

Register services

Call AddCryptoClients during application startup. Choose one of the two configuration styles below.
Load all settings from appsettings.json (or any other configuration source). The section name passed here must match the key in your configuration file.
// Program.cs
builder.Services.AddCryptoClients(
    builder.Configuration.GetSection("CryptoClients"));
// appsettings.json
{
  "CryptoClients": {
    "OutputOriginalData": false,
    "RateLimiterEnabled": true,
    "Binance": {
      "ApiCredentials": {
        "HMAC": { "Key": "...", "Secret": "..." }
      }
    }
  }
}
3

Inject and use

Inject IExchangeRestClient or IExchangeSocketClient into your services through the constructor.
public class TradingBot
{
    private readonly IExchangeRestClient _restClient;
    private readonly IExchangeSocketClient _socketClient;

    public TradingBot(
        IExchangeRestClient restClient,
        IExchangeSocketClient socketClient)
    {
        _restClient  = restClient;
        _socketClient = socketClient;
    }
}

Registered services

AddCryptoClients registers the following interfaces:
InterfaceImplementationLifetime
IExchangeRestClientExchangeRestClientTransient
IExchangeSocketClientExchangeSocketClientSingleton (default)
IExchangeOrderBookFactoryExchangeOrderBookFactoryTransient
IExchangeTrackerFactoryExchangeTrackerFactoryTransient
IExchangeUserClientProviderExchangeUserClientProviderTransient
All individual exchange REST clients (e.g. 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:
builder.Services.AddCryptoClients(
    globalOptions => { },
    socketClientLifetime: ServiceLifetime.Scoped);

Injecting factory and tracker services

Use IExchangeOrderBookFactory to create live order books and IExchangeTrackerFactory to create price and funding-rate trackers:
public class MarketDataService
{
    private readonly IExchangeOrderBookFactory _orderBookFactory;
    private readonly IExchangeTrackerFactory _trackerFactory;

    public MarketDataService(
        IExchangeOrderBookFactory orderBookFactory,
        IExchangeTrackerFactory trackerFactory)
    {
        _orderBookFactory = orderBookFactory;
        _trackerFactory   = trackerFactory;
    }
}

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 single AddCryptoClients call:
using CryptoClients.Net.Interfaces;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.SharedApis;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCryptoClients();

var app = builder.Build();

app.MapGet("Ticker/{exchange}/{baseAsset}/{quoteAsset}",
    async ([FromServices] IExchangeRestClient client,
           string exchange,
           string baseAsset,
           string quoteAsset) =>
    {
        var spotClient = client.GetSpotTickerClient(exchange)!;
        var result = await spotClient.GetSpotTickerAsync(
            new GetTickerRequest(
                new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset)));

        return result.Data;
    });

app.Run();
Example requests:
  • GET /Ticker/Kraken/ETH/BTC
  • GET /Ticker/Kucoin/BTC/USDT

Build docs developers (and LLMs) love