mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 08:22:53 +00:00
Docs
+30
@@ -151,4 +151,34 @@ await kucoinSocketClient.UnsubscribeAsync(subscriptionResult.Data.Id);
|
||||
When you need to unsubscribe all current subscriptions on a client you can call `UnsubscribeAllAsync` on the client to unsubscribe all streams and close all connections.
|
||||
|
||||
|
||||
## Dependency injection
|
||||
Each library offers a `Add[Library]` extension method for `IServiceCollection`, which allows you to add the clients to the service collection. It also provides a callback for setting the client options. See this example for adding the `BinanceClient`:
|
||||
````C#
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddBinance((restClientOptions, socketClientOptions) => {
|
||||
restClientOptions.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
||||
restClientOptions.LogLevel = LogLevel.Trace;
|
||||
|
||||
socketClientOptions.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
||||
});
|
||||
}
|
||||
````
|
||||
Doing client registration this way will add the `IBinanceClient` as a transient service, and the `IBinanceSocketClient` as a scoped service.
|
||||
|
||||
Alternatively, the clients can be registered manually:
|
||||
````C#
|
||||
BinanceClient.SetDefaultOptions(new BinanceClientOptions
|
||||
{
|
||||
ApiCredentials = new ApiCredentials("KEY", "SECRET"),
|
||||
LogLevel = LogLevel.Trace
|
||||
});
|
||||
|
||||
BinanceSocketClient.SetDefaultOptions(new BinanceSocketClientOptions
|
||||
{
|
||||
ApiCredentials = new ApiCredentials("KEY", "SECRET"),
|
||||
});
|
||||
|
||||
services.AddTransient<IBinanceClient, BinanceClient>();
|
||||
services.AddScoped<IBinanceSocketClient, BinanceSocketClient>();
|
||||
````
|
||||
|
||||
+12
-11
@@ -1,17 +1,18 @@
|
||||
|Definition|Synonyms|Meaning|
|
||||
|----------|--------|-------|
|
||||
|Asset|Currency, Coin||
|
||||
|Symbol|Market||
|
||||
|Trade|Execution, fill||
|
||||
|Quantity|Amount, Size||
|
||||
|Fee|Commission||
|
||||
|Kline|Candlestick, OHLC||
|
||||
|Symbol|Market|An asset pair, for example `BTC-ETH`|
|
||||
|Asset|Currency, Coin|A coin for which you can hold balance and which makes up Symbols. For example both `BTC`, `ETH` or `USD`|
|
||||
|Trade|Execution, fill|The (partial) execution of an order. Orders can have multiple trades|
|
||||
|Quantity|Amount, Size|The amount of asset|
|
||||
|Fee|Commission|The fee paid for an order or trade|
|
||||
|Kline|Candlestick, OHLC|K-line data, used for candlestick charts. Contains Open/High/Low/Close/Volume|
|
||||
|KlineInterval|The time period of a single kline|
|
||||
|Open order|Active order, Unexecuted order||
|
||||
|Closed order|Completed order, executed order||
|
||||
|Network|Chain||
|
||||
|Order book|Market depth||
|
||||
|Ticker|Stats||
|
||||
|Open order|Active order, Unexecuted order|An order which has not yet been fully filled|
|
||||
|Closed order|Completed order, executed order|An order which is no longer active. Can be canceled or fully filled|
|
||||
|Network|Chain|The network of an asset. For example `ETH` allows multiple networks like `ERC20` and `BEP2`|
|
||||
|Order book|Market depth|A list of (the top rows of) the current best bids and asks|
|
||||
|Ticker|Stats|Statistics over the last 24 hours|
|
||||
|Client implementation|Library|An implementation of the `CrytpoExchange.Net` library. For example `Binance.Net` or `FTX.Net`|
|
||||
|
||||
### Other naming constraints
|
||||
#### PlaceOrderAsync
|
||||
|
||||
+5
-2
@@ -1,2 +1,5 @@
|
||||
## IExchangeClient
|
||||
TODO
|
||||
## ISpotClient
|
||||
TODO
|
||||
|
||||
## IFuturesClient
|
||||
TODO
|
||||
+77
-2
@@ -1,4 +1,4 @@
|
||||
The library offers extensive logging, for which you can supply your own logging implementation. The logging can be configured via the client options (see XXX). The examples here are using the `BinanceClient` but they should be the same for each implementation.
|
||||
The library offers extensive logging, for which you can supply your own logging implementation. The logging can be configured via the client options (see [Client options](https://github.com/JKorf/CryptoExchange.Net/wiki/Options)). The examples here are using the `BinanceClient` but they should be the same for each implementation.
|
||||
|
||||
Logging is based on the `Microsoft.Extensions.Logging.ILogger` interface. This should provide ease of use when connecting the library logging to your existing logging implementation.
|
||||
|
||||
@@ -6,7 +6,16 @@ Logging is based on the `Microsoft.Extensions.Logging.ILogger` interface. This s
|
||||
To make the CryptoExchange.Net logging write to the Serilog logger you can use the following methods, depending on the type of project you're using. The following examples assume that the `Serilog.Sinks.Console` package is already installed.
|
||||
|
||||
#### Dotnet hosting
|
||||
With for example an ASP.Net Core or Blazor project the logging can be added to the dependency container, which you can then use to inject it into the client. Make sure to install the `Serilog.AspNetCore` package (https://github.com/serilog/serilog-aspnetcore). Adding `UseSerilog()` in the `CreateHostBuilder` will add the Serilog logging implementation as an ILogger which you can inject into implementations.
|
||||
|
||||
With for example an ASP.Net Core or Blazor project the logging can be added to the dependency container, which you can then use to inject it into the client. Make sure to install the `Serilog.AspNetCore` package (https://github.com/serilog/serilog-aspnetcore).
|
||||
|
||||
<Details>
|
||||
<Summary>
|
||||
<b>Using ILogger injection</b>
|
||||
|
||||
</Summary>
|
||||
<BlockQuote>
|
||||
Adding `UseSerilog()` in the `CreateHostBuilder` will add the Serilog logging implementation as an ILogger which you can inject into implementations.
|
||||
|
||||
*Configuring Serilog as ILogger:*
|
||||
````C#
|
||||
@@ -52,6 +61,72 @@ public class BinanceDataProvider
|
||||
|
||||
````
|
||||
|
||||
</BlockQuote>
|
||||
</Details>
|
||||
|
||||
<Details>
|
||||
<Summary>
|
||||
<b>Using Add[Library] extension method</b>
|
||||
|
||||
</Summary>
|
||||
<BlockQuote>
|
||||
When using the `Add[Library]` extension method, for instance `AddBinance()`, there is a small issue that there is no available `ILogger<>` yet when adding the library. This can be solved as follows:
|
||||
|
||||
*Configuring Serilog as ILogger:*
|
||||
````C#
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger();
|
||||
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup(
|
||||
context => new Startup(context.Configuration, LoggerFactory.Create(config => config.AddSerilog()) )); // <- this allows us to use ILoggerFactory in the Startup.cs
|
||||
});
|
||||
|
||||
````
|
||||
|
||||
|
||||
*Injecting ILogger:*
|
||||
````C#
|
||||
|
||||
public class Startup
|
||||
{
|
||||
private ILoggerFactory _loggerFactory;
|
||||
|
||||
public Startup(IConfiguration configuration, ILoggerFactory loggerFactory)
|
||||
{
|
||||
Configuration = configuration;
|
||||
_loggerFactory = loggerFactory;
|
||||
}
|
||||
|
||||
/* .. rest of class .. */
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddBinance((restClientOptions, socketClientOptions) => {
|
||||
// Point the logging to use the ILogger configuration
|
||||
restClientOptions.LogWriters = new List<ILogger> { _loggerFactory.CreateLogger<IBinanceClient>() };
|
||||
});
|
||||
|
||||
// Rest of service registrations
|
||||
}
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
</BlockQuote>
|
||||
</Details>
|
||||
|
||||
#### Console application
|
||||
If you don't have a dependency injection service available because you are for example working on a simple console application you can use a slightly different approach.
|
||||
|
||||
|
||||
+72
-19
@@ -1,22 +1,75 @@
|
||||
Changes from 4.x to 5.x:
|
||||
|
||||
Client structure
|
||||
binanceClient.Spot.Market.GetTickersAsync(), binanceClient.Spot.System.GetExchangeInfoAsync() => binanceClient.SpotApi.ExchangeData.XXX
|
||||
binanceSocketClient.Spot.Subscribe => binanceSocketClient.SpotStreams.Subscribe
|
||||
Options
|
||||
BaseAddress -> ApiOptions.BaseAddress
|
||||
|
||||
IExchangeClient
|
||||
IKline
|
||||
CommonHigh => CommonHighPrice
|
||||
CommonLow => CommonLowPrice
|
||||
CommonOpen => CommonOpenPrice
|
||||
CommonClose => CommonClosePrice
|
||||
ISymbol
|
||||
CommonMinimumTradeSize => CommonMinimumTradeQuantity
|
||||
ITicker
|
||||
CommonHigh => CommonHighPrice
|
||||
CommonLow => CommonLowPrice
|
||||
## Client structure
|
||||
The client structure has been changed to make clients more consistent across different implementations. Where before clients could either have `client.Method() (bittrexClient.GetTickersAsync())`, `client.[Api].Method() (kcuoinClient.Spot.GetTickersAsync())` or `client.[Api].[Topic].Method() (binanceClient.Spot.Market.GetTickersAsync())`. This has been unified to be `client.[Api]Api.[Topic].Method()`:
|
||||
`bittrexClient.SpotApi.ExchangeData.GetTickersAsync()`
|
||||
`kucoinClient.SpotApi.ExchangeData.GetTickersAsync()`
|
||||
`binanceClient.SpotApi.ExchangeData.GetTickersAsync()`
|
||||
|
||||
ISymbolOrderBook.LastOrderBookUpdate => UpdateTime
|
||||
Rate limiter
|
||||
Socket clients are restructured as `client.[Api]Streams.Method()`:
|
||||
`bittrexClient.SpotStreams.SubscribeToTickerUpdatesAsync()`
|
||||
`kucoinClient.SpotStreams.SubscribeToTickerUpdatesAsync()`
|
||||
`binanceClient.SpotStreams.SubscribeToAllTickerUpdatesAsync()`
|
||||
|
||||
|
||||
## Options structure
|
||||
The options have been changed in 2 categories, options for the whole client, and options only for a specific sub Api. Some options might no longer be available on the base level and should be set on the Api options instead, for example the `BaseAddress`.
|
||||
The following example sets some basic options, and specifically overwrites the USD futures Api options to use the test net address and different Api credentials:
|
||||
````C#
|
||||
var binanceClient = new BinanceClient(new BinanceClientOptions()
|
||||
{
|
||||
//
|
||||
LogLevel = LogLevel.Trace,
|
||||
RequestTimeout = TimeSpan.FromSeconds(60),
|
||||
ApiCredentials = new ApiCredentials("API KEY", "API SECRET"),
|
||||
|
||||
// Set options specifically for the USD futures API
|
||||
UsdFuturesApiOptions = new BinanceApiClientOptions
|
||||
{
|
||||
BaseAddress = BinanceApiAddresses.TestNet.UsdFuturesRestClientAddress,
|
||||
ApiCredentials = new ApiCredentials("OTHER API KEY ONLY FOR USD FUTURES", "OTHER API SECRET ONLY FOR USD FUTURES")
|
||||
}
|
||||
});
|
||||
````
|
||||
|
||||
## IExchangeClient
|
||||
The `IExchangeClient` has been replaced by the `ISpotClient` and `IFuturesClient`. Where previously the `IExchangeClient` was implemented on the base client level, the `ISpotClient`/`IFuturesClient` have been implemented on the sub-Api level.
|
||||
This, in combination with the client restructuring, allows for more logically implemented interfaces, see this example:
|
||||
*V4*
|
||||
````C#
|
||||
var spotClients = new [] {
|
||||
(IExhangeClient)binanceClient,
|
||||
(IExchangeClient)bittrexClient,
|
||||
(IExchangeClient)kucoinClient.Spot
|
||||
};
|
||||
|
||||
// There was no common implementation for futures client
|
||||
````
|
||||
|
||||
*V5*
|
||||
````C#
|
||||
var spotClients = new [] {
|
||||
binanceClient.SpotApi.ComonSpotClient,
|
||||
bittrexClient.SpotApi.ComonSpotClient,
|
||||
kucoinClient.SpotApi.ComonSpotClient
|
||||
};
|
||||
|
||||
var futuresClients = new [] {
|
||||
binanceClient.UsdFuturesApi.ComonFuturesClient,
|
||||
kucoinClient.FuturesApi.ComonFuturesClient
|
||||
};
|
||||
````
|
||||
|
||||
Where the IExchangeClient was returning interfaces which were implemented by models from the exchange, the `ISpotClient`/`IFuturesClient` returns actual objects defined in the `CryptoExchange.Net` library. This shifts the responsibility of parsing
|
||||
the library model to a shared model from the model class to the client class, which makes more sense and removes the need for separate library models to implement the mapping logic. It also removes the need for the `Common` prefix on properties:
|
||||
*V4*
|
||||
````C#
|
||||
var kline = await ((IExhangeClient)binanceClient).GetKlinesAysnc(/*params*/);
|
||||
var closePrice = kline.CommonClose;
|
||||
````
|
||||
|
||||
*V5*
|
||||
````C#
|
||||
var kline = await binanceClient.SpotApi.ComonSpotClient.GetKlinesAysnc(/*params*/);
|
||||
var closePrice = kline.ClosePrice;
|
||||
````
|
||||
|
||||
Reference in New Issue
Block a user