CryptoExchange.Net
CryptoExchange.Net is a base library which is used to implement different cryptocurrency (exchange) API's. It provides a standardized way of implementing different API's, which results in a very similar experience for users of the API implementations.
The following API's are directly supported. Note that there are 3rd party implementations going around, but only these are created and supported by me
Exchange | Repository | Nuget |
---|---|---|
Binance | JKorf/Binance.Net | |
Bitfinex | JKorf/Bitfinex.Net | |
Bitget | JKorf/Bitget.Net | |
Bybit | JKorf/Bybit.Net | |
CoinEx | JKorf/CoinEx.Net | |
CoinGecko | JKorf/CoinGecko.Net | |
Huobi | JKorf/Huobi.Net | |
Kraken | JKorf/Kraken.Net | |
Kucoin | JKorf/Kucoin.Net | |
Mexc | JKorf/Mexc.Net | |
OKX | JKorf/OKX.Net |
Discord
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
DonateMake 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: bc1qz0jv0my7fc60rxeupr23e75x95qmlq6489n8gh
Eth: 0x8E21C4d955975cB645589745ac0c46ECA8FAE504
Alternatively, sponsor me on Github using Github Sponsors.
Getting Started
All packages are available on Nuget. After installing the package the API is available by using one of the library clients, or through the ICrypoRestClient
, ICryptoSocketClient
or ISpotClient
interfaces.
Installation
Add the package via dotnet, or add it via the package manager
dotnet add package Binance.Net

dotnet add package Bitfinex.Net

dotnet add package JK.Bitget.Net

dotnet add package Bybit.Net

dotnet add package CoinGecko.Net

dotnet add package CoinEx.Net

dotnet add package Huobi.Net

dotnet add package KrakenExchange.Net

dotnet add package Kucoin.Net

dotnet add package JK.Mexc.Net

dotnet add package JK.OKX.Net

Dependency Injection
REST API client
Websocket API client
Common Clients
Options & Authorization
Options for the clients can be provided in a couple of different ways. If no options are configured the default options will be used. For accessing private endpoints and streams API credentials have to be provided.
Authorization
For private endpoints and data streams the clients will need to know the API credentials of the user accessing the API. API credentials are a way of identifying the user and validating that the user is who he says he is. You can compare it to a username and password login.
API credentials van be provided via the client options, see next section on how to set these options. There are currently 2 variants of API credentials supported, HMAC and RSA.
HMAC
HMAC authentication involves 2 values, the API key and API secret. The combination of the two gives access to the account. HMAC is the default authentication method and can be configured as such:
options.ApiCredentials = new ApiCredentials("YOUR API KEY", "YOUR API SECRET");
RSA
RSA authentication involves generating a private and public key and then uploading the public key to the server. After using the private key to sign the request the server can validate the request by comparing the signature using the public key. Not every exchange supports this authentication method.
Depending on the version of dotnet used there are 2 ways of configuring the RSA authentication.
When running Dotnet version 3.0 or later the easiest way is to use the RsaPem type. This allows you to use the Private key directly. When running from an older Dotnet/.NET framework version you're forced to use the RsaXml type due to framework limitations. This means you'll have to convert the private key to XML format before using it.
RsaXml// when using the .netstandard2.0 compiled version, from .NET framework or Dotnet core 2.2 or lower
// Private key should look something like this: <RSAKeyValue><Modulus>...</RSAKeyValue>
options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY", ApiCredentialsType.RsaXml);
RsaPem
// when using the .netstandard2.1 compiled version, from Dotnet core 3.0 or later
// Private key should look something like this: -----BEGIN PRIVATE KEY----- .. -----END PRIVATE KEY-----, or just a long random character string
options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY", ApiCredentialsType.RsaPem);
Setting options
Dependency injectionWhen adding a library to the service collection (see Dependency Injection) the options for the clients can be provided as argument to the calls. Options are split between the REST and the websocket client.
builder.Services.AddBinance(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddBitfinex(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddBitget(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddBybit(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddCoinGecko(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
});
builder.Services.AddCoinEx(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddHuobi(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddKraken(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddKucoin(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddMexc(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
builder.Services.AddOKX(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});
When creating a client via the constructor options can be provided as parameters
var binanceRestClient = new BinanceRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BitfinexRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BitgetRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BybitRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new CoinGeckoRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new CoinExRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new HuobiRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new KrakenRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new KucoinRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new MexcRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new OKXRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});
The options can be defined in the static SetDefaultOptions method on the client BEFORE creating the client. Any client created after this call will use the specified options
BinanceRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BinanceRestClient();
BitfinexRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BitfinexRestClient();
BitgetRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BitgetRestClient();
BybitRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BybitRestClient();
CoinGeckoRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new CoinGeckoRestClient();
CoinExRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new CoinExRestClient();
HuobiRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new HuobiRestClient();
KrakenRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new KrakenRestClient();
KucoinRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new KucoinRestClient();
MexcRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new MexcRestClient();
OKXRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new OKXRestClient();
Option definitions
List of options:
- Generic Options
- Options per library
Features
Orderbooks
Logging
Ratelimiting
Examples
using Binance.Net;
var client = new BinanceRestClient();
client.SpotApi.Exchange.GetExchangeInfoAsync();