From da1686d95c2fd88a4228a4d31e0b762385e77d1f Mon Sep 17 00:00:00 2001 From: JKorf Date: Fri, 9 Feb 2024 19:55:26 +0100 Subject: [PATCH] docs --- docs/index.html | 1047 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1038 insertions(+), 9 deletions(-) diff --git a/docs/index.html b/docs/index.html index 6f04a6a..bff0ad3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -262,7 +262,421 @@ ============================ -->

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

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IBinanceRestClientThe client for accessing the Binance REST API
IBinanceSocketClientThe client for accessing the Binance Websocket API
IBinanceOrderBookFactoryA factory for creating SymbolOrderBook instances for the Binance API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Binance. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IBitfinexRestClientThe client for accessing the Bitfinex REST API
IBitfinexSocketClientThe client for accessing the Bitfinex Websocket API
IBitfinexOrderBookFactoryA factory for creating SymbolOrderBook instances for the Bitfinex API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Bitfinex. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IBitgetRestClientThe client for accessing the Bitget REST API
IBitgetSocketClientThe client for accessing the Bitget Websocket API
IBitgetOrderBookFactoryA factory for creating SymbolOrderBook instances for the Bitget API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Bitget. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IBybitRestClientThe client for accessing the Bybit REST API
IBybitSocketClientThe client for accessing the Bybit Websocket API
IBybitOrderBookFactoryA factory for creating SymbolOrderBook instances for the Bybit API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Bybit. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + +
InterfaceDescription
ICoinGeckoRestClientThe client for accessing the CoinGecko REST API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
ICoinExRestClientThe client for accessing the CoinEx REST API
ICoinExSocketClientThe client for accessing the CoinEx Websocket API
ICoinExOrderBookFactoryA factory for creating SymbolOrderBook instances for the CoinEx API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for CoinEx. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IHuobiRestClientThe client for accessing the Huobi REST API
IHuobiSocketClientThe client for accessing the Huobi Websocket API
IHuobiOrderBookFactoryA factory for creating SymbolOrderBook instances for the Huobi API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Huobi. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IKrakenRestClientThe client for accessing the Kraken REST API
IKrakenSocketClientThe client for accessing the Kraken Websocket API
IKrakenOrderBookFactoryA factory for creating SymbolOrderBook instances for the Kraken API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Kraken. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IKucoinRestClientThe client for accessing the Kucoin REST API
IKucoinSocketClientThe client for accessing the Kucoin Websocket API
IKucoinOrderBookFactoryA factory for creating SymbolOrderBook instances for the Kucoin API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Kucoin. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IMexcRestClientThe client for accessing the Mexc REST API
IMexcSocketClientThe client for accessing the Mexc Websocket API
IMexcOrderBookFactoryA factory for creating SymbolOrderBook instances for the Mexc API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for Mexc. The ISpotClient offers basic Spot API functionality in a combined interface
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
InterfaceDescription
IOKXRestClientThe client for accessing the OKX REST API
IOKXSocketClientThe client for accessing the OKX Websocket API
IOKXOrderBookFactoryA factory for creating SymbolOrderBook instances for the OKX API
ICryptoRestClientAn aggregating client from which multiple different library REST clients can be accessed
ICryptoSocketClientAn aggregating client from which multiple different library Websocket clients can be accessed
ISpotClientAn implementation of the ISpotClient interface for OKX. The ISpotClient offers basic Spot API functionality in a combined interface
+
+

@@ -271,8 +685,234 @@ ============================ -->

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:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
SuccessWhether or not the call was completed successfully
DataThe parsed response object, only available when Success is true
ErrorError information, only available when Success is false
OriginalDataThe raw response data, only filled when the OutputOriginalData is enabled in the client options
RequestMethodThe HTTP method that was used for the request
RequestHeadersThe list of headers which were send with the request
RequestIdA unique request id
RequestUrlThe full urls which was called
RequestBodyThe request body send with the request
ResponseLengthThe length of the response in bytes
ResponseHeadersThe list of headers send along with the response
ResponseTimeThe time it took from sending the request to receiving the response
+ +
@@ -280,8 +920,261 @@ ============================ -->

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:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
SuccessWhether or not the subscription was completed successfully
ErrorError information, only available when Success is false
DataThe UpdateSubscription object, only available when Success is true
Data.IdUnique id of the subscription
Data.SocketIdThe id of the underlying websocket
Data.ConnectionLostEvent which will be invoked whenever the connection to the server is lost and reconnecting will be started
Data.ConnectionRestoredEvent which will be invoked when the connection to the server is restored after being disconnected
Data.ActivityPausedEvent which will be invoked when the server has indicated that currently no operations will be accepted
Data.ActivityUnpausedEvent which will be invoked when the server has indicated that operations will be accepted again after a previous ActivityPaused event
Data.ExceptionEvent 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:

+ + + + + + + + + + + + + + + + + + + + + + +
PropertyDescription
TimestampThe timestamp the data was received
TopicThe topic of the update, typically the symbol or stream name
OriginalDataThe raw update data, only filled when the OutputOriginalData is enabled in the client options
UpdateTypeThe 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
DataThe 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();
+

+ +
@@ -587,7 +1480,7 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY SetDefaultOptions -

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

+

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