mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Docs
This commit is contained in:
parent
84d0f0ec9e
commit
273cab9fdb
@ -11,15 +11,15 @@ Each implementation generally provides two different clients, which will be the
|
|||||||
The rest client gives access to the Rest endpoint of the API. Rest endpoints are accessed by sending an HTTP request and receiving a response. The client is split in different sub-clients, which are named API Clients. These API clients are then again split in different topics. Typically a Rest client will look like this:
|
The rest client gives access to the Rest endpoint of the API. Rest endpoints are accessed by sending an HTTP request and receiving a response. The client is split in different sub-clients, which are named API Clients. These API clients are then again split in different topics. Typically a Rest client will look like this:
|
||||||
|
|
||||||
- [ExchangeName]RestClient
|
- [ExchangeName]RestClient
|
||||||
- SpotApi
|
- SpotApi
|
||||||
- Account
|
- Account
|
||||||
- ExchangeData
|
- ExchangeData
|
||||||
- Trading
|
- Trading
|
||||||
- FuturesApi
|
- FuturesApi
|
||||||
- Account
|
- Account
|
||||||
- ExchangeData
|
- ExchangeData
|
||||||
- Trading
|
- Trading
|
||||||
|
|
||||||
This rest client has 2 different API clients, the `SpotApi` and the `FuturesApi`, each offering their own set of endpoints.
|
This rest client has 2 different API clients, the `SpotApi` and the `FuturesApi`, each offering their own set of endpoints.
|
||||||
|
|
||||||
*Requesting ticker info on the spot API*
|
*Requesting ticker info on the spot API*
|
||||||
@ -64,8 +64,8 @@ When processing the result of a call it should always be checked for success. No
|
|||||||
var callResult = await kucoinClient.SpotApi.ExchangeData.GetTickersAsync();
|
var callResult = await kucoinClient.SpotApi.ExchangeData.GetTickersAsync();
|
||||||
if(!callResult.Success)
|
if(!callResult.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Request failed: " + callResult.Error);
|
Console.WriteLine("Request failed: " + callResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Result: " + callResult.Data);
|
Console.WriteLine("Result: " + callResult.Data);
|
||||||
@ -78,8 +78,8 @@ Just like the Rest client is divided in Rest Api clients, the Socket client is d
|
|||||||
```csharp
|
```csharp
|
||||||
|
|
||||||
- KucoinSocketClient
|
- KucoinSocketClient
|
||||||
- SpotStreams
|
- SpotStreams
|
||||||
- FuturesStreams
|
- FuturesStreams
|
||||||
|
|
||||||
```
|
```
|
||||||
*Subscribing to updates for all tickers on the Spot Api*
|
*Subscribing to updates for all tickers on the Spot Api*
|
||||||
@ -95,7 +95,7 @@ await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(DataHandle
|
|||||||
|
|
||||||
private static void DataHandler(DataEvent<KucoinStreamTick> updateData)
|
private static void DataHandler(DataEvent<KucoinStreamTick> updateData)
|
||||||
{
|
{
|
||||||
// Process updateData
|
// Process updateData
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ private static void DataHandler(DataEvent<KucoinStreamTick> updateData)
|
|||||||
```csharp
|
```csharp
|
||||||
await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(updateData =>
|
await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(updateData =>
|
||||||
{
|
{
|
||||||
// Process updateData
|
// Process updateData
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -122,16 +122,16 @@ Subscribing to a stream will return a `CallResult<UpdateSubscription>` object. T
|
|||||||
var subscriptionResult = await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(DataHandler);
|
var subscriptionResult = await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(DataHandler);
|
||||||
if(!subscriptionResult.Success)
|
if(!subscriptionResult.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to connect: " + subscriptionResult.Error);
|
Console.WriteLine("Failed to connect: " + subscriptionResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
subscriptionResult.Data.ConnectionLost += () =>
|
subscriptionResult.Data.ConnectionLost += () =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Connection lost");
|
Console.WriteLine("Connection lost");
|
||||||
};
|
};
|
||||||
subscriptionResult.Data.ConnectionRestored += (time) =>
|
subscriptionResult.Data.ConnectionRestored += (time) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Connection restored");
|
Console.WriteLine("Connection restored");
|
||||||
};
|
};
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -28,7 +28,7 @@ private void SomeMethod()
|
|||||||
{
|
{
|
||||||
var socketClient = new BinanceSocketClient();
|
var socketClient = new BinanceSocketClient();
|
||||||
socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
||||||
// Handle data
|
// Handle data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -41,7 +41,7 @@ private BinanceSocketClient _socketClient = new BinanceSocketClient();
|
|||||||
private void SomeMethod()
|
private void SomeMethod()
|
||||||
{
|
{
|
||||||
_socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
_socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
||||||
// Handle data
|
// Handle data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ Yes, generally these are all supported and can be configured by setting the Envi
|
|||||||
```csharp
|
```csharp
|
||||||
var client = new BinanceRestClient(options =>
|
var client = new BinanceRestClient(options =>
|
||||||
{
|
{
|
||||||
options.Environment = BinanceEnvironment.Testnet;
|
options.Environment = BinanceEnvironment.Testnet;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ The library offers extensive logging, which depends on the dotnet `Microsoft.Ext
|
|||||||
```csharp
|
```csharp
|
||||||
IServiceCollection services = new ServiceCollection();
|
IServiceCollection services = new ServiceCollection();
|
||||||
services
|
services
|
||||||
.AddBinance()
|
.AddBinance()
|
||||||
.AddLogging(options =>
|
.AddLogging(options =>
|
||||||
{
|
{
|
||||||
options.SetMinimumLevel(LogLevel.Trace);
|
options.SetMinimumLevel(LogLevel.Trace);
|
||||||
@ -66,8 +66,8 @@ IServiceCollection serviceCollection = new ServiceCollection();
|
|||||||
serviceCollection.AddBinance();
|
serviceCollection.AddBinance();
|
||||||
serviceCollection.AddLogging(options =>
|
serviceCollection.AddLogging(options =>
|
||||||
{
|
{
|
||||||
options.SetMinimumLevel(LogLevel.Trace);
|
options.SetMinimumLevel(LogLevel.Trace);
|
||||||
options.AddConsole();
|
options.AddConsole();
|
||||||
}).BuildServiceProvider();
|
}).BuildServiceProvider();
|
||||||
|
|
||||||
var client = serviceCollection.GetRequiredService<IBinanceRestClient>();
|
var client = serviceCollection.GetRequiredService<IBinanceRestClient>();
|
||||||
@ -91,7 +91,7 @@ By default the `OriginalData` property in the `WebCallResult`/`DataEvent` object
|
|||||||
```csharp
|
```csharp
|
||||||
var client = new BinanceClient(options =>
|
var client = new BinanceClient(options =>
|
||||||
{
|
{
|
||||||
options.OutputOriginalData = true
|
options.OutputOriginalData = true
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ var originallyReceivedData = tickerResult.OriginalData;
|
|||||||
|
|
||||||
// Socket update
|
// Socket update
|
||||||
await client.SpotStreams.SubscribeToAllTickerUpdatesAsync(update => {
|
await client.SpotStreams.SubscribeToAllTickerUpdatesAsync(update => {
|
||||||
var originallyRecievedData = update.OriginalData;
|
var originallyRecievedData = update.OriginalData;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ The HttpClient will now be received by the DI container instead of having to pas
|
|||||||
```csharp
|
```csharp
|
||||||
var client = new BinanceClient(new BinanceClientOptions(){
|
var client = new BinanceClient(new BinanceClientOptions(){
|
||||||
OutputOriginalData = true,
|
OutputOriginalData = true,
|
||||||
SpotApiOptions = new RestApiOptions {
|
SpotApiOptions = new RestApiOptions {
|
||||||
BaseAddress = BinanceApiAddresses.TestNet.RestClientAddress
|
BaseAddress = BinanceApiAddresses.TestNet.RestClientAddress
|
||||||
}
|
}
|
||||||
// Other options
|
// Other options
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -38,7 +38,7 @@ var client = new BinanceClient(new BinanceClientOptions(){
|
|||||||
```csharp
|
```csharp
|
||||||
var client = new BinanceClient(options => {
|
var client = new BinanceClient(options => {
|
||||||
options.OutputOriginalData = true;
|
options.OutputOriginalData = true;
|
||||||
options.Environment = BinanceEnvironment.Testnet;
|
options.Environment = BinanceEnvironment.Testnet;
|
||||||
// Other options
|
// Other options
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -53,10 +53,10 @@ With the change in options providing the DI extension methods for the IServiceCo
|
|||||||
```csharp
|
```csharp
|
||||||
builder.Services.AddKucoin((restOpts, socketOpts) =>
|
builder.Services.AddKucoin((restOpts, socketOpts) =>
|
||||||
{
|
{
|
||||||
restOpts.LogLevel = LogLevel.Debug;
|
restOpts.LogLevel = LogLevel.Debug;
|
||||||
restOpts.ApiCredentials = new KucoinApiCredentials("KEY", "SECRET", "PASS");
|
restOpts.ApiCredentials = new KucoinApiCredentials("KEY", "SECRET", "PASS");
|
||||||
socketOpts.LogLevel = LogLevel.Debug;
|
socketOpts.LogLevel = LogLevel.Debug;
|
||||||
socketOpts.ApiCredentials = new KucoinApiCredentials("KEY", "SECRET", "PASS");
|
socketOpts.ApiCredentials = new KucoinApiCredentials("KEY", "SECRET", "PASS");
|
||||||
}, ServiceLifetime.Singleton);
|
}, ServiceLifetime.Singleton);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ Each implementation can be configured using client options. There are 2 ways to
|
|||||||
|
|
||||||
BinanceClient.SetDefaultOptions(options =>
|
BinanceClient.SetDefaultOptions(options =>
|
||||||
{
|
{
|
||||||
options.OutputOriginalData = true;
|
options.OutputOriginalData = true;
|
||||||
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -23,8 +23,8 @@ BinanceClient.SetDefaultOptions(options =>
|
|||||||
|
|
||||||
var client = new BinanceClient(options =>
|
var client = new BinanceClient(options =>
|
||||||
{
|
{
|
||||||
options.OutputOriginalData = true;
|
options.OutputOriginalData = true;
|
||||||
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -34,12 +34,12 @@ When calling `SetDefaultOptions` each client created after that will use the opt
|
|||||||
|
|
||||||
BinanceClient.SetDefaultOptions(options =>
|
BinanceClient.SetDefaultOptions(options =>
|
||||||
{
|
{
|
||||||
options.OutputOriginalData = true;
|
options.OutputOriginalData = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
var client = new BinanceClient(options =>
|
var client = new BinanceClient(options =>
|
||||||
{
|
{
|
||||||
options.OutputOriginalData = false;
|
options.OutputOriginalData = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -54,8 +54,8 @@ The options are divided in two categories. The basic options, which will apply t
|
|||||||
|
|
||||||
var client = new BinanceRestClient(options =>
|
var client = new BinanceRestClient(options =>
|
||||||
{
|
{
|
||||||
options.ApiCredentials = new ApiCredentials("GENERAL-KEY", "GENERAL-SECRET"),
|
options.ApiCredentials = new ApiCredentials("GENERAL-KEY", "GENERAL-SECRET"),
|
||||||
options.SpotOptions.ApiCredentials = new ApiCredentials("SPOT-KEY", "SPOT-SECRET");
|
options.SpotOptions.ApiCredentials = new ApiCredentials("SPOT-KEY", "SPOT-SECRET");
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -18,15 +18,15 @@ book.OnStatusChange += (oldState, newState) => Console.WriteLine($"State changed
|
|||||||
var startResult = await book.StartAsync();
|
var startResult = await book.StartAsync();
|
||||||
if (!startResult.Success)
|
if (!startResult.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to start order book: " + startResult.Error);
|
Console.WriteLine("Failed to start order book: " + startResult.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.WriteLine(book.ToString(3);
|
Console.WriteLine(book.ToString(3);
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -13,12 +13,12 @@ A rate limiter can be configured in the options like so:
|
|||||||
```csharp
|
```csharp
|
||||||
new ClientOptions
|
new ClientOptions
|
||||||
{
|
{
|
||||||
RateLimitingBehaviour = RateLimitingBehaviour.Wait,
|
RateLimitingBehaviour = RateLimitingBehaviour.Wait,
|
||||||
RateLimiters = new List<IRateLimiter>
|
RateLimiters = new List<IRateLimiter>
|
||||||
{
|
{
|
||||||
new RateLimiter()
|
new RateLimiter()
|
||||||
.AddTotalRateLimit(50, TimeSpan.FromSeconds(10))
|
.AddTotalRateLimit(50, TimeSpan.FromSeconds(10))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ This will add a rate limiter for 50 requests per 10 seconds.
|
|||||||
A rate limiter can have multiple limits:
|
A rate limiter can have multiple limits:
|
||||||
```csharp
|
```csharp
|
||||||
new RateLimiter()
|
new RateLimiter()
|
||||||
.AddTotalRateLimit(50, TimeSpan.FromSeconds(10))
|
.AddTotalRateLimit(50, TimeSpan.FromSeconds(10))
|
||||||
.AddEndpointLimit("/api/order", 10, TimeSpan.FromSeconds(2))
|
.AddEndpointLimit("/api/order", 10, TimeSpan.FromSeconds(2))
|
||||||
```
|
```
|
||||||
This adds another limit of 10 requests per 2 seconds in addition to the 50 requests per 10 seconds limit.
|
This adds another limit of 10 requests per 2 seconds in addition to the 50 requests per 10 seconds limit.
|
||||||
These are the available rate limit configurations:
|
These are the available rate limit configurations:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user