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
All client libraries support and encourage usage via the Dotnet dependency injection system. Add all necesary services by calling the Add[Library]();
extension method on the service collection. Options for the clients can be passed as parameters.
builder.Services.AddBinance();
builder.Services.AddBitfinex();
builder.Services.AddBitget();
builder.Services.AddBybit();
builder.Services.AddCoinGecko();
builder.Services.AddCoinEx();
builder.Services.AddHuobi();
builder.Services.AddKraken();
builder.Services.AddKucoin();
builder.Services.AddMexc();
builder.Services.AddOKX();
This registers the following interfaces which can then be injected
Interface | Description |
---|---|
IBinanceRestClient |
The client for accessing the Binance REST API |
IBinanceSocketClient |
The client for accessing the Binance Websocket API |
IBinanceOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Binance API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Binance. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IBitfinexRestClient |
The client for accessing the Bitfinex REST API |
IBitfinexSocketClient |
The client for accessing the Bitfinex Websocket API |
IBitfinexOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Bitfinex API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Bitfinex. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IBitgetRestClient |
The client for accessing the Bitget REST API |
IBitgetSocketClient |
The client for accessing the Bitget Websocket API |
IBitgetOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Bitget API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Bitget. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IBybitRestClient |
The client for accessing the Bybit REST API |
IBybitSocketClient |
The client for accessing the Bybit Websocket API |
IBybitOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Bybit API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Bybit. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
ICoinGeckoRestClient |
The client for accessing the CoinGecko REST API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
Interface | Description |
---|---|
ICoinExRestClient |
The client for accessing the CoinEx REST API |
ICoinExSocketClient |
The client for accessing the CoinEx Websocket API |
ICoinExOrderBookFactory |
A factory for creating SymbolOrderBook instances for the CoinEx API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for CoinEx. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IHuobiRestClient |
The client for accessing the Huobi REST API |
IHuobiSocketClient |
The client for accessing the Huobi Websocket API |
IHuobiOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Huobi API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Huobi. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IKrakenRestClient |
The client for accessing the Kraken REST API |
IKrakenSocketClient |
The client for accessing the Kraken Websocket API |
IKrakenOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Kraken API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Kraken. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IKucoinRestClient |
The client for accessing the Kucoin REST API |
IKucoinSocketClient |
The client for accessing the Kucoin Websocket API |
IKucoinOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Kucoin API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Kucoin. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IMexcRestClient |
The client for accessing the Mexc REST API |
IMexcSocketClient |
The client for accessing the Mexc Websocket API |
IMexcOrderBookFactory |
A factory for creating SymbolOrderBook instances for the Mexc API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for Mexc. The ISpotClient offers basic Spot API functionality in a combined interface |
Interface | Description |
---|---|
IOKXRestClient |
The client for accessing the OKX REST API |
IOKXSocketClient |
The client for accessing the OKX Websocket API |
IOKXOrderBookFactory |
A factory for creating SymbolOrderBook instances for the OKX API |
ICryptoRestClient |
An aggregating client from which multiple different library REST clients can be accessed |
ICryptoSocketClient |
An aggregating client from which multiple different library Websocket clients can be accessed |
ISpotClient |
An implementation of the ISpotClient interface for OKX. The ISpotClient offers basic Spot API functionality in a combined interface |
REST API client
Each library provides a REST API client. This client follows the following naming convention: [Library]RestClient
. The REST API client is split into different sub-API access clients, which in turn are split into different topics. This structure is the same for each library, which makes it easier to navigate the clients.
The client can be injected via dependency injection, or constructed manually.
var client = new BinanceRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new BitfinexRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new BitgetRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new BybitRestClient();
var tickersResult = await client.V5Api.ExchangeData.GetSpotTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new CoinGeckoRestClient();
var assetsResult = await client.Api.GetAssetsAsync();
if (!assetsResult.Success)
{
// Handle error, assetsResult.Error contains more information
}
else
{
// Handle data, assetsResult.Data will contain the actual data
}
var client = new CoinExRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new HuobiRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new KrakenRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new KucoinRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new MexcRestClient();
var tickersResult = await client.SpotApi.ExchangeData.GetTickersAsync();
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
var client = new OKXRestClient();
var tickersResult = await client.UnifiedApi.ExchangeData.GetTickersAsync(OKXInstrumentType.Spot);
if (!tickersResult.Success)
{
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}
The response object
Calls made with the REST API client will return a WebCallResult
object. This object contains information about both the request that was send and the response that was received. The WebCallResult
object exposes the following properties:
Property | Description |
---|---|
Success | Whether or not the call was completed successfully |
Data | The parsed response object, only available when Success is true |
Error | Error information, only available when Success is false |
OriginalData | The raw response data, only filled when the OutputOriginalData is enabled in the client options |
RequestMethod | The HTTP method that was used for the request |
RequestHeaders | The list of headers which were send with the request |
RequestId | A unique request id |
RequestUrl | The full urls which was called |
RequestBody | The request body send with the request |
ResponseLength | The length of the response in bytes |
ResponseHeaders | The list of headers send along with the response |
ResponseTime | The time it took from sending the request to receiving the response |
Websocket API client
If the API supports websocket connections then the library provides a Websocket API client. This client follows the following naming convention: [Library]SocketClient
. The Websocket API client is split into different sub-API access clients, which in turn are sometimes split into different topics. This structure is the same for each library, which makes it easier to navigate the clients.
The client can be injected via dependency injection, or constructed manually. When constructing manually keep in mind that when the client is disposed all connections will get closed as well.
Subscribing
var client = new BinanceSocketClient();
var subscribeResult = await client.SpotApi.ExchangeData.SubscribeToAllTickerUpdatesAsync(update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new BitfinexSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdatesAsync("tETHUST", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new BitgetSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new BybitSocketClient();
var subscribeResult = await client.V5SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new CoinExSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new HuobiSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdatesAsync(update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new KrakenSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdatesAsync("ETH/USD", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new KucoinSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToAllTickerUpdatesAsync(update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new MexcSocketClient();
var subscribeResult = await client.SpotApi.SubscribeToMiniTickerUpdatesAsync(update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
var client = new OKXSocketClient();
var subscribeResult = await client.UnifiedApi.ExchangeData.SubscribeToTickerUpdatesAsync("ETH-USDT", update => {
// Handle the data update, update.Data will contain the actual data
});
if (!subscribeResult.Success)
{
// Handle error, subscribeResult.Error contains more information on why the subscription failed
}
// Subscribing was successfull, the data will now be streamed into the data handler
The subscription result object
Subscriptions calls will return a CallResult<UpdateSubscription>
object. This object contains information about the status of the intial subscription, and the UpdateSubscription data object exposes events for status changes and methods for managing the subscription. The CallResult<UpdateSubscription>
object exposes the following properties:
Property | Description |
---|---|
Success | Whether or not the subscription was completed successfully |
Error | Error information, only available when Success is false |
Data | The UpdateSubscription object, only available when Success is true |
Data.Id | Unique id of the subscription |
Data.SocketId | The id of the underlying websocket |
Data.ConnectionLost | Event which will be invoked whenever the connection to the server is lost and reconnecting will be started |
Data.ConnectionRestored | Event which will be invoked when the connection to the server is restored after being disconnected |
Data.ActivityPaused | Event which will be invoked when the server has indicated that currently no operations will be accepted |
Data.ActivityUnpaused | Event which will be invoked when the server has indicated that operations will be accepted again after a previous ActivityPaused event |
Data.Exception | Event which will be invoked when the data handler of the subscription throws an exception |
The subscription update event object
Whenever new data is received for a subscription the data handler will be called with a DataEvent<T>
object. This object contains information about the event and the actual update data. The DataEvent<T>
object exposes the following properties:
Property | Description |
---|---|
Timestamp | The timestamp the data was received |
Topic | The topic of the update, typically the symbol or stream name |
OriginalData | The raw update data, only filled when the OutputOriginalData is enabled in the client options |
UpdateType | The type of update. SocketUpdateType.Snapshot means the update is a snapshot, not an incremental update. SocketUpdateType.Update means it's an update with new data |
Data | The data received in the update |
Unsubscribing
When no longer interested in updates from a specific subscription it can be unsubscribed. This can be done in one of the following ways:
Unsubscribe via UpdateSubscription object
When you have the reference to the UpdateSubscription object received from the Subscribe method you can call the CloseAsync()
method on that to unsubscribe
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdates(data => {});
await subscribeResult.Data.CloseAsync();
Unsubscribe via CancellationToken
Passing in a CancellationToken
as parameter in the subscribe method will allow you to cancel subscriptions by canceling the token. This can be useful when you need to cancel some streams but not others. In this example, both BTCUSDT
and ETHUSDT
streams get canceled, while the XRPUSDT
stream remains active.
var cts = new CancellationTokenSource();
var subscriptionResult1 = await client.SpotApi.SubscribeToTickerUpdatesAsync("BTCUSDT", DataHandler, cts.Token);
var subscriptionResult2 = await client.SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", DataHandler, cts.Token);
var subscriptionResult3 = await client.SpotApi.SubscribeToTickerUpdatesAsync("XRPUSDT", DataHandler);
cts.Cancel();
Unsubscribe via the websocket client
The Websocket client has multiple ways of unsubscribing one or more subscriptions:
var subscribeResult = await client.SpotApi.SubscribeToTickerUpdates(data => {});
// Unsubscribe by passing the UpdateSubscription
await client.UnsubscribeAsync(subscribeResult.Data);
// OR store the ID and pass that
var subId = subscribeResult.Data.Id;
await client.UnsubscribeAsync(subId);
// OR unsubscribe all subscriptions at the same time
await client.UnsubscribeAllAsync();
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 using 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
General options
Options available for all clients
Option | Description | Default value |
---|---|---|
RequestTimeout | The time to wait for an answer from the server on a request | TimeSpan.FromSeconds(20) |
ApiCredentials | The credentials to use for private endpoints and streams. See Authorization for more info | null |
Proxy | The proxy to use for connecting to the API | null |
OutputOriginalData | When enabled the originally received string data will be available as well as the deserialized object. For REST API client calls the data will be in the WebCallResult property, for Websocket API client subscriptions the data will be available in the DataEvent property when receiving an update. |
false |
Environment | The environment the library should connect to. Some exchanges have testnet/sandbox environments which can be used instead of the real exchange. The environment option can be used to switch between different trade environments | Live environment |
REST client options
Options available for REST clients
Option | Description | Default value |
---|---|---|
AutoTimestamp | Whether or not the client should attempt to sync the time between the client and server. If the time between server and client is not in sync authentication errors might occur. This option should be disabled when the client time sure is to be in sync | true |
TimestampRecalculationInterval | The interval of how often the time synchronization between client and server should be executed | TimeSpan.FromHours(1) |
[API].RateLimiters | A list of IRateLimiter s to use |
Dependent on the library |
[API].RateLimitingBehaviour | What should happen when a rate limit is reached | RateLimitingBehaviour.Wait |
[API].ApiCredentials | Same as the in the base options, allows overriding per sub-API | null |
[API].OutputOriginalData | Same as the in the base options, allows overriding per sub-API | null |
[API].AutoTimestamp | Same as the in the base REST options, allows overriding per sub-API | null |
[API].TimestampRecalculationInterval | Same as the in the base REST options, allows overriding per sub-API | null |
Websocket client options
Options available for websocket clients
Option | Description | Default value |
---|---|---|
AutoReconnect | Whether or not the socket should attempt to automatically reconnect when disconnected | true |
ReconnectInterval | The time to wait between connection tries when reconnecting | TimeSpan.FromSeconds(5) |
SocketNoDataTimeout | If no data is received during this timespan the connection is assumed to be dropped. This is mainly used for API's which have some sort of ping/keepalive system. For example; the Bitfinex API will sent a heartbeat message every 15 seconds, so the `SocketNoDataTimeout` could be set to 20 seconds. On API's without such a mechanism this might not work because there just might not be any update while still being fully connected | default(TimeSpan) |
SocketSubscriptionsCombineTarget | The number of subscriptions that should be made on a single socket connection before setting up a new connection. Not all exchanges support multiple subscriptions on a single socket and some have limits on the amount of connections. Setting this to a higher number increases subscription speed because not every subscription needs to connect to the server, but having more subscriptions on a single connection will also increase the amount of traffic on that single connection, potentially leading to delays in updates if the data isn't handled quickly enough | Dependent on the library |
MaxConcurrentResubscriptionsPerSocket | The maximum number of concurrent resubscriptions per socket when resubscribing after reconnecting | 5 |
MaxSocketConnections | The maximum number of distinct socket connections | null |
DelayAfterConnect | The time to wait before sending messages after connecting to the server | null |
[API].RateLimiters | A list of IRateLimiter s to use |
Dependent on the library |
[API].SocketNoDataTimeout | Same as the in the base websocket client options, allows overriding per sub-API | null |
[API].MaxSocketConnections | Same as the in the base websocket client options, allows overriding per sub-API | null |
Features
Orderbooks
Logging
Ratelimiting
Examples
using Binance.Net;
var client = new BinanceRestClient();
client.SpotApi.Exchange.GetExchangeInfoAsync();