Home

Awesome

.CryptoClients.Net CryptoClients.Net

.NET License

CryptoClients.Net is a collection of different cryptocurrency exchange client libraries based on the same base library. CryptoClients.Net bundles the different client libraries in a single package and adds some additional tools to make use of them.

Features

For more information on what CryptoExchange.Net and its client libraries offers see the Documentation.

Supported Frameworks

The library is targeting both .NET Standard 2.0 and .NET Standard 2.1 for optimal compatibility

.NET implementationVersion Support
.NET Core2.0 and higher
.NET Framework4.6.1 and higher
Mono5.4 and higher
Xamarin.iOS10.14 and higher
Xamarin.Android8.0 and higher
UWP10.0.16299 and higher
Unity2018.1 and higher

Supported Exchanges

The following API's are included in CryptoClients.Net:

ExchangeRepositoryNuget
BinanceJKorf/Binance.NetNuget version
BingXJKorf/BingX.NetNuget version
BitfinexJKorf/Bitfinex.NetNuget version
BitgetJKorf/Bitget.NetNuget version
BitMartJKorf/BitMart.NetNuget version
BybitJKorf/Bybit.NetNuget version
CoinbaseJKorf/Coinbase.NetNuget version
CoinExJKorf/CoinEx.NetNuget version
CoinGeckoJKorf/CoinGecko.NetNuget version
Gate.ioJKorf/GateIo.NetNuget version
HTXJKorf/HTX.NetNuget version
KrakenJKorf/Kraken.NetNuget version
KucoinJKorf/Kucoin.NetNuget version
MexcJKorf/Mexc.NetNuget version
OKXJKorf/OKX.NetNuget version

Install the library

NuGet

NuGet version Nuget downloads

dotnet add package CryptoClients.Net

GitHub packages

CryptoClients.Net is available on GitHub packages. You'll need to add https://nuget.pkg.github.com/JKorf/index.json as a NuGet package source.

Download release

GitHub Release

The NuGet package files are added along side the source with the latest GitHub release which can found here.

How to use

Get a client

There are 2 main clients, the ExchangeRestClient and ExchangeSocketClient, for accessing the REST and Websocket API respectively. All exchange API's are available via these clients.
Alternatively exchange specific clients can be used, for example BinanceRestClient or KucoinSocketClient. Either create new clients directly or use Dotnet dependency injection.

Dependency injection

// Dependency injection, allows the injection of `IExchangeRestClient`, `IExchangeSocketClient` and `IExchangeOrderBookFactory` interfaces
// as well as for all exchanges the `I[ExchangeName]RestClient`, `I[ExchangeName]SocketClient` and `I[ExchangeName]OrderBookFactory` types
services.AddCryptoClients();

Construction

// Client for accessing all exchanges
IExchangeRestClient restClient = new ExchangeRestClient();
IExchangeSocketClient socketClient = new ExchangeSocketClient();

// Exchange specific clients
IBinanceRestClient binanceRestClient = new BinanceRestClient();
IKucoinSocketClient kucoinSocketClient = new KucoinSocketClient();

Configuration

Clients can be configured during the dependency injection registration, or when constructing the clients. Configuration can be done for all exchanges/clients, can be set per exchange or a combination:

builder.Services.AddCryptoClients(globalOptions =>
{
    // Global options apply to each exchange/client
    globalOptions.OutputOriginalData = true;
	// Set credentials for the different exchanges, will be applied to both REST and socket clients
    globalOptions.ApiCredentials = new CryptoClients.Net.Models.ExchangeCredentials
    {
        Binance = new ApiCredentials("BinanceKey", "BinanceSecret"),
        Kucoin = new KucoinApiCredentials("KucoinKey", "KucoinSecret", "KucoinPassphrase"),
        OKX = new OKXApiCredentials("OKXKey", "OKXSecret", "OKXPassphrase")
    };
},
bybitRestOptions: bybitOptions =>
{
    // Specify options specifically for a specific exchange and client, in this case the Bybit REST client
    bybitOptions.Environment = Bybit.Net.BybitEnvironment.Netherlands;
    bybitOptions.ApiCredentials = new ApiCredentials("BybitKey", "BybitSecret");
});

More info on options available for each client can be found in the CryptoExchange.Net documentation.

Usage

There are multiple ways to access exchange API's. Options 1 and 2 allow access to the full exchange API while option 3 uses a common interface which allows exchange agnostic requesting, but is therefor limited in functionality.

<b>Option 1</b>
Using the exchange specific clients directly. This offers full functionality of the exchange API's.

var kucoinClient1 = new KucoinRestClient();
var binanceClient1 = new BinanceRestClient();
var binanceResult1 = await binanceClient1.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
var kucoinResult1 = await kucoinClient1.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT");

<b>Option 2</b>
Using the exchange clients via the main client, also allows for full functionality of the exchange API's.

var restClient2 = new ExchangeRestClient();
var binanceResult2 = await restClient2.Binance.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
var kucoinResult2 = await restClient2.Kucoin.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT");

<b>Option 3</b>
Using the shared client interfaces to access exchanges. This is the most generic and exchange agnostic way, but might not support all functionality the full API offers.

// Define functionality based on shared interface
async Task<ExchangeWebResult<SharedSpotTicker>> GetTickerAsync(ISpotTickerRestClient client, SharedSymbol symbol)
    => await client.GetSpotTickerAsync(new GetTickerRequest(symbol));
	
// Execute for multiple exchanges
var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT");
var binanceResult3 = await GetTickerAsync(restClient3.Binance.SpotApi.SharedClient, symbol);
var kucoinResult3 = await GetTickerAsync(restClient3.Kucoin.SpotApi.SharedClient, symbol);

<b>Option 4</b>
Using the shared client interfaces thought the main client. For this the same limitation applies as option 3.

var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT");
var tickers = await restClient.GetSpotTickerAsync(new GetTickerRequest(symbol), [Exchange.Binance, Exchange.Kucoin]);

For information on the specific exchange clients, dependency injection, response processing and more see the CryptoExchange.Net documentation or have a look at the examples here. See the CryptoExchange.Net examples for client examples which also apply to CryptoClients.Net

Example

An API allowing the requesting of any ticker on any (supported) exchange in 14 lines;
For example GET /Ticker/Kraken/ETH/BTC or GET /Ticker/Kucoin/BTC/USDT

using CryptoClients.Net.Interfaces;
using CryptoExchange.Net.SharedApis;
using CryptoExchange.Net.Objects;
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();

Discord

Nuget version
A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.

Support the project

Any support is greatly appreciated.

Donate

Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.

Btc: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX) TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd

Sponsor

Alternatively, sponsor me on Github using Github Sponsors.

Release notes