1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-12 17:03:10 +00:00

Compare commits

...

10 Commits

Author SHA1 Message Date
JKorf 24c40d2dc6 Updated version 2024-04-05 20:09:37 +02:00
JKorf 5ef6feb996 Added readme for docs folder 2024-04-03 16:52:41 +02:00
JKorf 85dad6f6f0 Fix BoolConverter writing 2024-04-03 09:49:34 +02:00
JKorf 3cdcf0d9be Improved SystemTextJson message accessor value retrieval 2024-03-29 15:55:19 +01:00
JKorf b90a0a71e9 Socket connection improvements on reconnect 2024-03-28 20:35:49 +01:00
JKorf e62786a70f Update index.html 2024-03-27 16:17:37 +01:00
JKorf 87722f2d28 BingX example docs 2024-03-26 09:33:14 +01:00
JKorf a86276f18d Added BingX to docs 2024-03-25 22:09:28 +01:00
JKorf f432a66016 Updated examples 2024-03-25 19:56:21 +01:00
JKorf 9e2910d2ec Update README.md 2024-03-24 21:15:11 +01:00
14 changed files with 239 additions and 35 deletions
@@ -28,7 +28,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
{
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> (T)((object?)ReadBool(ref reader, typeToConvert, options) ?? default(T))!;
public bool? ReadBool(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.True)
@@ -74,7 +74,10 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WriteNullValue();
if (value is bool boolVal)
writer.WriteBooleanValue(boolVal);
else
writer.WriteNullValue();
}
}
@@ -118,17 +118,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
if (value.Value.ValueKind == JsonValueKind.Object || value.Value.ValueKind == JsonValueKind.Array)
return default;
var ttype = typeof(T);
if (ttype == typeof(string))
return (T?)(object?)value.Value.GetString();
if (ttype == typeof(short))
return (T)(object)value.Value.GetInt16();
if (ttype == typeof(int))
return (T)(object)value.Value.GetInt32();
if (ttype == typeof(long))
return (T)(object)value.Value.GetInt64();
return default;
return value.Value.Deserialize<T>();
}
/// <inheritdoc />
+3 -3
View File
@@ -6,9 +6,9 @@
<PackageId>CryptoExchange.Net</PackageId>
<Authors>JKorf</Authors>
<Description>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.</Description>
<PackageVersion>7.2.0</PackageVersion>
<AssemblyVersion>7.2.0</AssemblyVersion>
<FileVersion>7.2.0</FileVersion>
<PackageVersion>7.2.1</PackageVersion>
<AssemblyVersion>7.2.1</AssemblyVersion>
<FileVersion>7.2.1</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>OKX;OKX.Net;Mexc;Mexc.Net;Kucoin;Kucoin.Net;Kraken;Kraken.Net;Huobi;Huobi.Net;CoinEx;CoinEx.Net;Bybit;Bybit.Net;Bitget;Bitget.Net;Bitfinex;Bitfinex.Net;Binance;Binance.Net;CryptoCurrency;CryptoCurrency Exchange</PackageTags>
<RepositoryType>git</RepositoryType>
@@ -194,11 +194,16 @@ namespace CryptoExchange.Net.Sockets
try
{
using CancellationTokenSource tcs = new(TimeSpan.FromSeconds(10));
await _socket.ConnectAsync(Uri, tcs.Token).ConfigureAwait(false);
using var linked = CancellationTokenSource.CreateLinkedTokenSource(tcs.Token, _ctsSource.Token);
await _socket.ConnectAsync(Uri, linked.Token).ConfigureAwait(false);
}
catch (Exception e)
{
_logger.SocketConnectionFailed(Id, e.Message, e);
if (!_ctsSource.IsCancellationRequested)
{
// if _ctsSource was canceled this was already logged
_logger.SocketConnectionFailed(Id, e.Message, e);
}
return false;
}
@@ -386,10 +391,13 @@ namespace CryptoExchange.Net.Sockets
if (_disposed)
return;
if (_ctsSource?.IsCancellationRequested == false)
_ctsSource.Cancel();
_logger.SocketDisposing(Id);
_disposed = true;
_socket.Dispose();
_ctsSource.Dispose();
_ctsSource?.Dispose();
_logger.SocketDisposed(Id);
}
@@ -714,6 +714,12 @@ namespace CryptoExchange.Net.Sockets
return new CallResult(new InvalidOperationError(info));
}
if (!_socket.IsOpen)
{
_logger.LogWarning("[Sckt {SocketId}] msg {RequestId} - Failed to send, socket no longer open", SocketId, requestId);
return new CallResult(new WebError("Failed to send message, socket no longer open"));
}
_logger.SendingData(SocketId, requestId, data);
try
{
+10 -9
View File
@@ -5,15 +5,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Binance.Net" Version="9.5.0" />
<PackageReference Include="Bitfinex.Net" Version="7.1.0" />
<PackageReference Include="Bybit.Net" Version="3.4.0" />
<PackageReference Include="CoinEx.Net" Version="6.1.0" />
<PackageReference Include="Huobi.Net" Version="5.1.0" />
<PackageReference Include="JK.Bitget.Net" Version="1.1.0" />
<PackageReference Include="JK.OKX.Net" Version="1.6.0" />
<PackageReference Include="KrakenExchange.Net" Version="4.3.0" />
<PackageReference Include="Kucoin.Net" Version="5.2.0" />
<PackageReference Include="Binance.Net" Version="9.7.1" />
<PackageReference Include="Bitfinex.Net" Version="7.2.2" />
<PackageReference Include="Bybit.Net" Version="3.7.1" />
<PackageReference Include="CoinEx.Net" Version="6.2.1" />
<PackageReference Include="Huobi.Net" Version="5.2.1" />
<PackageReference Include="JK.BingX.Net" Version="1.0.0" />
<PackageReference Include="JK.Bitget.Net" Version="1.3.1" />
<PackageReference Include="JK.OKX.Net" Version="1.7.1" />
<PackageReference Include="KrakenExchange.Net" Version="4.4.3" />
<PackageReference Include="Kucoin.Net" Version="5.3.2" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" />
</ItemGroup>
+6 -1
View File
@@ -1,5 +1,6 @@
@page "/"
@inject IBinanceRestClient binanceClient
@inject IBingXRestClient bingXClient
@inject IBitfinexRestClient bitfinexClient
@inject IBitgetRestClient bitgetClient
@inject IBybitRestClient bybitClient
@@ -21,6 +22,7 @@
protected override async Task OnInitializedAsync()
{
var binanceTask = binanceClient.SpotApi.ExchangeData.GetTickerAsync("BTCUSDT");
var bingXTask = bingXClient.SpotApi.ExchangeData.GetTickersAsync("BTC-USDT");
var bitfinexTask = bitfinexClient.SpotApi.ExchangeData.GetTickerAsync("tBTCUSD");
var bitgetTask = bitgetClient.SpotApi.ExchangeData.GetTickerAsync("BTCUSDT_SPBL");
var bybitTask = bybitClient.V5Api.ExchangeData.GetSpotTickersAsync("BTCUSDT");
@@ -30,10 +32,13 @@
var kucoinTask = kucoinClient.SpotApi.ExchangeData.GetTickerAsync("BTC-USDT");
var okxTask = okxClient.UnifiedApi.ExchangeData.GetTickerAsync("BTCUSDT");
await Task.WhenAll(binanceTask, bitfinexTask, bybitTask, coinexTask, huobiTask, krakenTask, kucoinTask);
await Task.WhenAll(binanceTask, bingXTask, bitfinexTask, bybitTask, coinexTask, huobiTask, krakenTask, kucoinTask);
if (binanceTask.Result.Success)
_prices.Add("Binance", binanceTask.Result.Data.LastPrice);
if (bingXTask.Result.Success)
_prices.Add("BingX", bingXTask.Result.Data.First().LastPrice);
if (bitfinexTask.Result.Success)
_prices.Add("Bitfinex", bitfinexTask.Result.Data.LastPrice);
@@ -1,5 +1,6 @@
@page "/LiveData"
@inject IBinanceSocketClient binanceSocketClient
@inject IBingXSocketClient bingXSocketClient
@inject IBitfinexSocketClient bitfinexSocketClient
@inject IBitgetSocketClient bitgetSocketClient
@inject IBybitSocketClient bybitSocketClient
@@ -29,6 +30,7 @@
var tasks = new Task<CallResult<UpdateSubscription>>[]
{
binanceSocketClient.SpotApi.ExchangeData.SubscribeToTickerUpdatesAsync("ETHBTC", data => UpdateData("Binance", data.Data.LastPrice)),
bingXSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH-BTC", data => UpdateData("BingX", data.Data.LastPrice)),
bitfinexSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("tETHBTC", data => UpdateData("Bitfinex", data.Data.LastPrice)),
bitgetSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETHBTC", data => UpdateData("Bitget", data.Data.LastPrice)),
bybitSocketClient.V5SpotApi.SubscribeToTickerUpdatesAsync("ETHBTC", data => UpdateData("Bybit", data.Data.LastPrice)),
@@ -2,6 +2,7 @@
@using System.Collections.Concurrent
@using System.Timers
@using Binance.Net.Interfaces
@using BingX.Net.Interfaces
@using Bitfinex.Net.Interfaces
@using Bitget.Net.Interfaces;
@using Bybit.Net.Interfaces
@@ -13,6 +14,7 @@
@using Kucoin.Net.Interfaces
@using OKX.Net.Interfaces;
@inject IBinanceOrderBookFactory binanceFactory
@inject IBingXOrderBookFactory bingXFactory
@inject IBitfinexOrderBookFactory bitfinexFactory
@inject IBitgetOrderBookFactory bitgetFactory
@inject IBybitOrderBookFactory bybitFactory
@@ -55,6 +57,7 @@
_books = new Dictionary<string, ISymbolOrderBook>
{
{ "Binance", binanceFactory.CreateSpot("ETHBTC") },
{ "BingX", bingXFactory.CreateSpot("ETH-BTC") },
{ "Bitfinex", bitfinexFactory.Create("tETHBTC") },
{ "Bitget", bitgetFactory.CreateSpot("ETHBTC") },
{ "Bybit", bybitFactory.Create("ETHBTC", Bybit.Net.Enums.Category.Spot) },
+1
View File
@@ -36,6 +36,7 @@ namespace BlazorClient
socketOptions.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
services.AddBingX();
services.AddBitfinex();
services.AddBitget();
services.AddBybit();
+1
View File
@@ -9,6 +9,7 @@
@using BlazorClient
@using BlazorClient.Shared
@using Binance.Net.Interfaces.Clients;
@using BingX.Net.Interfaces.Clients;
@using Bitfinex.Net.Interfaces.Clients;
@using Bitget.Net.Interfaces.Clients;
@using Bybit.Net.Interfaces.Clients;
+9 -2
View File
@@ -12,6 +12,7 @@ The following API's are directly supported. Note that there are 3rd party implem
|Exchange|Repository|Nuget|
|--|--|--|
|Binance|[JKorf/Binance.Net](https://github.com/JKorf/Binance.Net)|[![Nuget version](https://img.shields.io/nuget/v/Binance.net.svg?style=flat-square)](https://www.nuget.org/packages/Binance.Net)|
|BingX|[JKorf/BingX.Net](https://github.com/JKorf/BingX.Net)|[![Nuget version](https://img.shields.io/nuget/v/JK.BingX.net.svg?style=flat-square)](https://www.nuget.org/packages/JK.BingX.Net)|
|Bitfinex|[JKorf/Bitfinex.Net](https://github.com/JKorf/Bitfinex.Net)|[![Nuget version](https://img.shields.io/nuget/v/Bitfinex.net.svg?style=flat-square)](https://www.nuget.org/packages/Bitfinex.Net)|
|Bitget|[JKorf/Bitget.Net](https://github.com/JKorf/Bitget.Net)|[![Nuget version](https://img.shields.io/nuget/v/JK.Bitget.net.svg?style=flat-square)](https://www.nuget.org/packages/JK.Bitget.Net)|
|Bybit|[JKorf/Bybit.Net](https://github.com/JKorf/Bybit.Net)|[![Nuget version](https://img.shields.io/nuget/v/Bybit.net.svg?style=flat-square)](https://www.nuget.org/packages/Bybit.Net)|
@@ -33,13 +34,19 @@ I develop and maintain this package on my own for free in my spare time, any sup
### Donate
Make 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**: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
**Btc**: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
**Eth**: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
**USDT (TRX)** TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd
### Sponsor
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).
## Release notes
* Version 7.2.1 - 05 Apr 2024
* Improved websocket reconnect logic
* Simplified SystemTextJsonMessageAccessor value retrieval
* Fixed System.Text.Json BoolConverter value writing
* Version 7.2.0 - 24 Mar 2024
* Added ArrayParametersSerialization.JsonArray support
* Refactored to high-performance logging for hot paths
+1
View File
@@ -0,0 +1 @@
Source for https://jkorf.github.io/CryptoExchange.Net
+180 -4
View File
@@ -135,6 +135,7 @@
<th>Nuget</th>
</tr>
<tr><td>Binance</td><td><a href="https://github.com/JKorf/Binance.Net">JKorf/Binance.Net</a></td><td><a href="https://www.nuget.org/packages/Binance.Net"><img src="https://img.shields.io/nuget/v/Binance.net.svg?style=flat-square" /></a></td></tr>
<tr><td>BingX</td><td><a href="https://github.com/JKorf/BingX.Net">JKorf/BingX.Net</a></td><td><a href="https://www.nuget.org/packages/JK.BingX.Net"><img src="https://img.shields.io/nuget/v/JK.BingX.net.svg?style=flat-square" /></a></td></tr>
<tr><td>Bitfinex</td><td><a href="https://github.com/JKorf/Bitfinex.Net">JKorf/Bitfinex.Net</a></td><td><a href="https://www.nuget.org/packages/Bitfinex.Net"><img src="https://img.shields.io/nuget/v/Bitfinex.net.svg?style=flat-square" /></a></td></tr>
<tr><td>Bitget</td><td><a href="https://github.com/JKorf/Bitget.Net">JKorf/Bitget.Net</a></td><td><a href="https://www.nuget.org/packages/JK.Bitget.Net"><img src="https://img.shields.io/nuget/v/JK.Bitget.net.svg?style=flat-square" /></a></td></tr>
<tr><td>Bybit</td><td><a href="https://github.com/JKorf/Bybit.Net">JKorf/Bybit.Net</a></td><td><a href="https://www.nuget.org/packages/Bybit.Net"><img src="https://img.shields.io/nuget/v/Bybit.net.svg?style=flat-square" /></a></td></tr>
@@ -174,8 +175,9 @@
<b>Donate</b><br />
<p>Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.<p>
<p><em>Btc</em>: bc1qz0jv0my7fc60rxeupr23e75x95qmlq6489n8gh <br />
<em>Eth</em>: 0x8E21C4d955975cB645589745ac0c46ECA8FAE504</p>
<p><em>Btc</em>: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf<br />
<em>Eth</em>: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7<br />
<em>USDT (TRX)</em>: TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd</p>
<b>Sponsor</b><br />
<p>Alternatively, sponsor me on Github using <a href="https://github.com/sponsors/JKorf">Github Sponsors</a>.</p>
@@ -206,6 +208,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link active" id="install-binance-tab" data-toggle="tab" href="#install-binance" role="tab" aria-controls="install-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="install-bingx-tab" data-toggle="tab" href="#install-bingx" role="tab" aria-controls="install-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="install-bitfinex-tab" data-toggle="tab" href="#install-bitfinex" role="tab" aria-controls="install-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -242,6 +247,9 @@
<pre><code>dotnet add package Binance.Net</code></pre>
<img src="assets/images/BinanceInstall.png" />
</div>
<div class="tab-pane fade" id="install-bingx" role="tabpanel" aria-labelledby="install-bingx-tab">
<pre><code>dotnet add package JK.BingX.Net</code></pre>
</div>
<div class="tab-pane fade" id="install-bitfinex" role="tabpanel" aria-labelledby="install-bitfinex-tab">
<pre><code>dotnet add package Bitfinex.Net</code></pre>
<img src="assets/images/BitfinexInstall.png" />
@@ -299,6 +307,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link active" id="di-binance-tab" data-toggle="tab" href="#di-binance" role="tab" aria-controls="di-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="di-bingx-tab" data-toggle="tab" href="#di-bingx" role="tab" aria-controls="di-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="di-bitfinex-tab" data-toggle="tab" href="#di-bitfinex" role="tab" aria-controls="di-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -333,6 +344,9 @@
<div class="tab-content my-3" id="myTabContent">
<div class="tab-pane fade show active" id="di-binance" role="tabpanel" aria-labelledby="di-binance-tab">
<pre><code>builder.Services.AddBinance();</code></pre>
</div>
<div class="tab-pane fade" id="di-bingx" role="tabpanel" aria-labelledby="di-bingx-tab">
<pre><code>builder.Services.AddBingX();</code></pre>
</div>
<div class="tab-pane fade" id="di-bitfinex" role="tabpanel" aria-labelledby="di-bitfinex-tab">
<pre><code>builder.Services.AddBitfinex();</code></pre>
@@ -373,6 +387,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link active" id="interfaces-binance-tab" data-toggle="tab" href="#interfaces-binance" role="tab" aria-controls="interfaces-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="interfaces-bingx-tab" data-toggle="tab" href="#interfaces-bingx" role="tab" aria-controls="interfaces-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="interfaces-bitfinex-tab" data-toggle="tab" href="#interfaces-bitfinex" role="tab" aria-controls="interfaces-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -434,6 +451,35 @@
</tr>
</table>
</div>
<div class="tab-pane fade" id="interfaces-bingx" role="tabpanel" aria-labelledby="interfaces-bingx-tab">
<table class="table table-bordered">
<tr><th>Interface</th><th>Description</th></tr>
<tr>
<td><code>IBingXRestClient</code></td>
<td>The client for accessing the BingX REST API</td>
</tr>
<tr>
<td><code>IBingXSocketClient</code></td>
<td>The client for accessing the BingX Websocket API</td>
</tr>
<tr>
<td><code>IBingXOrderBookFactory</code></td>
<td>A factory for creating SymbolOrderBook instances for the BingX API</td>
</tr>
<tr>
<td><code>ICryptoRestClient</code></td>
<td>An aggregating client from which multiple different library REST clients can be accessed</td>
</tr>
<tr>
<td><code>ICryptoSocketClient</code></td>
<td>An aggregating client from which multiple different library Websocket clients can be accessed</td>
</tr>
<tr>
<td><code>ISpotClient</code></td>
<td>An implementation of the ISpotClient interface for BingX. The ISpotClient offers basic Spot API functionality in a combined interface</td>
</tr>
</table>
</div>
<div class="tab-pane fade" id="interfaces-bitfinex" role="tabpanel" aria-labelledby="interfaces-bitfinex-tab">
<table class="table table-bordered">
<tr><th>Interface</th><th>Description</th></tr>
@@ -726,6 +772,9 @@
<li class="nav-item" role="presentation">
<a class="nav-link active" id="rest-binance-tab" data-toggle="tab" href="#rest-binance" role="tab" aria-controls="rest-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="rest-bingx-tab" data-toggle="tab" href="#rest-bingx" role="tab" aria-controls="rest-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="rest-bitfinex-tab" data-toggle="tab" href="#rest-bitfinex" role="tab" aria-controls="rest-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -766,6 +815,18 @@ if (!tickersResult.Success)
// Handle error, tickersResult.Error contains more information
}
else
{
// Handle data, tickersResult.Data will contain the actual data
}</code></pre>
</div>
<div class="tab-pane fade" id="rest-bingx" role="tabpanel" aria-labelledby="rest-bingx-tab">
<pre><code>var client = new BingXRestClient();
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
}</code></pre>
@@ -965,6 +1026,9 @@ else
<li class="nav-item" role="presentation">
<a class="nav-link active" id="socket-binance-tab" data-toggle="tab" href="#socket-binance" role="tab" aria-controls="socket-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="socket-bingx-tab" data-toggle="tab" href="#socket-bingx" role="tab" aria-controls="socket-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="socket-bitfinex-tab" data-toggle="tab" href="#socket-bitfinex" role="tab" aria-controls="socket-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -1003,6 +1067,17 @@ 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</code></pre>
</div>
<div class="tab-pane fade" id="socket-bingx" role="tabpanel" aria-labelledby="socket-bingx-tab">
<pre><code>var client = new BingXSocketClient();
var subscribeResult = await client.SpotApi.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</code></pre>
</div>
<div class="tab-pane fade" id="socket-bitfinex" role="tabpanel" aria-labelledby="socket-bitfinex-tab">
@@ -1310,6 +1385,9 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
<li class="nav-item" role="presentation">
<a class="nav-link active" id="options-binance-tab" data-toggle="tab" href="#options-binance" role="tab" aria-controls="options-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bingx-tab" data-toggle="tab" href="#options-bingx" role="tab" aria-controls="options-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bitfinex-tab" data-toggle="tab" href="#options-bitfinex" role="tab" aria-controls="options-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -1344,6 +1422,15 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
<div class="tab-content my-3" id="myTabContent">
<div class="tab-pane fade show active" id="options-binance" role="tabpanel" aria-labelledby="options-binance-tab">
<pre><code>builder.Services.AddBinance(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
socketOptions => {
socketOptions.RequestTimeout = TimeSpan.FromSeconds(10);
});</code></pre>
</div>
<div class="tab-pane fade" id="options-bingx" role="tabpanel" aria-labelledby="options-bingx-tab">
<pre><code>builder.Services.AddBingX(
restOptions => {
restOptions.RequestTimeout = TimeSpan.FromSeconds(30);
},
@@ -1448,6 +1535,9 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
<li class="nav-item" role="presentation">
<a class="nav-link active" id="options-binance-tab" data-toggle="tab" href="#options-constr-binance" role="tab" aria-controls="options-constr-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bingx-tab" data-toggle="tab" href="#options-constr-bingx" role="tab" aria-controls="options-constr-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bitfinex-tab" data-toggle="tab" href="#options-constr-bitfinex" role="tab" aria-controls="options-constr-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -1482,6 +1572,12 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
<div class="tab-content my-3" id="myTabContent">
<div class="tab-pane fade show active" id="options-constr-binance" role="tabpanel" aria-labelledby="options-binance-tab">
<pre><code>var binanceRestClient = new BinanceRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});</code></pre>
</div>
<div class="tab-pane fade" id="options-constr-bingx" role="tabpanel" aria-labelledby="options-bingx-tab">
<pre><code>var client = new BingXRestClient(opts =>
{
opts.RequestTimeout = TimeSpan.FromSeconds(30);
});</code></pre>
@@ -1556,6 +1652,9 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
<li class="nav-item" role="presentation">
<a class="nav-link active" id="options-binance-tab" data-toggle="tab" href="#options-default-binance" role="tab" aria-controls="options-default-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bingx-tab" data-toggle="tab" href="#options-default-bingx" role="tab" aria-controls="options-default-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="options-bitfinex-tab" data-toggle="tab" href="#options-default-bitfinex" role="tab" aria-controls="options-default-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -1594,6 +1693,13 @@ options.ApiCredentials = new ApiCredentials("YOUR PUBLIC KEY", "YOUR PRIVATE KEY
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BinanceRestClient();</code></pre>
</div>
<div class="tab-pane fade" id="options-default-bingx" role="tabpanel" aria-labelledby="options-bingx-tab">
<pre><code>BingXRestClient.SetDefaultOptions(options =>
{
options.RequestTimeout = TimeSpan.FromSeconds(30);
});
var client = new BingXRestClient();</code></pre>
</div>
<div class="tab-pane fade" id="options-default-bitfinex" role="tabpanel" aria-labelledby="options-bitfinex-tab">
<pre><code>BitfinexRestClient.SetDefaultOptions(options =>
@@ -1846,6 +1952,9 @@ var client = new OKXRestClient();</code></pre>
<li class="nav-item" role="presentation">
<a class="nav-link active" id="book-binance-tab" data-toggle="tab" href="#book-binance" role="tab" aria-controls="book-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="book-bingx-tab" data-toggle="tab" href="#book-bingx" role="tab" aria-controls="book-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="book-bitfinex-tab" data-toggle="tab" href="#book-bitfinex" role="tab" aria-controls="book-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -1884,6 +1993,19 @@ if (!startResult.Success)
}
// Book has successfully started and synchronized
// Once no longer needed you can stop the live sync functionality by calling StopAsync()
await book.StopAsync();
</code></pre>
</div>
<div class="tab-pane fade" id="book-bingx" role="tabpanel" aria-labelledby="book-bingx-tab">
<pre><code>var book = new BingXSpotSymbolOrderBook("ETH-USDT");
var startResult = await book.StartAsync();
if (!startResult.Success)
{
// Handle error, error info available in startResult.Error
}
// Book has successfully started and synchronized
// Once no longer needed you can stop the live sync functionality by calling StopAsync()
await book.StopAsync();
</code></pre>
@@ -2205,7 +2327,10 @@ This adds another limit of 10 requests per 2 seconds for the order endpoint in a
<a class="nav-link active" id="example-symbols-general-tab" data-toggle="tab" href="#example-symbols-general" role="tab" aria-controls="example-symbols-general" aria-selected="true">CryptoRestClient</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-symbols-binance-tab" data-toggle="tab" href="#example-symbols-binance" role="tab" aria-controls="example-symbols-binance" aria-selected="true">Binance</a>
<a class="nav-link" id="example-symbols-binance-tab" data-toggle="tab" href="#example-symbols-binance" role="tab" aria-controls="example-symbols-binance" aria-selected="false">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-symbols-bingx-tab" data-toggle="tab" href="#example-symbols-bingx" role="tab" aria-controls="example-symbols-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-symbols-bitfinex-tab" data-toggle="tab" href="#example-symbols-bitfinex" role="tab" aria-controls="example-symbols-bitfinex" aria-selected="false">Bitfinex</a>
@@ -2243,6 +2368,9 @@ await spotClient.GetSymbolsAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-symbols-binance" role="tabpanel" aria-labelledby="example-symbols-binance-tab">
<pre><code>await binanceClient.SpotApi.ExchangeData.GetExchangeInfoAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-symbols-bingx" role="tabpanel" aria-labelledby="example-symbols-bingx-tab">
<pre><code>await bingXClient.SpotApi.ExchangeData.GetSymbolsAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-symbols-bitfinex" role="tabpanel" aria-labelledby="example-symbols-bitfinex-tab">
<pre><code>await bitfinexClient.SpotApi.ExchangeData.GetSymbolsAsync();</code></pre>
@@ -2295,6 +2423,9 @@ await spotClient.GetSymbolsAsync();</code></pre>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-ticker-binance-tab" data-toggle="tab" href="#example-ticker-binance" role="tab" aria-controls="example-ticker-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-ticker-bingx-tab" data-toggle="tab" href="#example-ticker-bingx" role="tab" aria-controls="example-ticker-bingx" aria-selected="true">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-ticker-bitfinex-tab" data-toggle="tab" href="#example-ticker-bitfinex" role="tab" aria-controls="example-ticker-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -2331,6 +2462,9 @@ await spotClient.GetTickerAsync(spotClient.GetSymbolName("BTC", "USDT"));</code>
</div>
<div class="tab-pane fade" id="example-ticker-binance" role="tabpanel" aria-labelledby="example-ticker-binance-tab">
<pre><code>await binanceClient.SpotApi.ExchangeData.GetTickerAsync("BTCUSDT");</code></pre>
</div>
<div class="tab-pane fade" id="example-ticker-bingx" role="tabpanel" aria-labelledby="example-ticker-bingx-tab">
<pre><code>await bingXClient.SpotApi.ExchangeData.GetTickersAsync("BTC-USDT");</code></pre>
</div>
<div class="tab-pane fade" id="example-ticker-bitfinex" role="tabpanel" aria-labelledby="example-ticker-bitfinex-tab">
<pre><code>await bitfinexClient.SpotApi.ExchangeData.GetTickerAsync("tBTCUST");</code></pre>
@@ -2383,6 +2517,9 @@ await spotClient.GetTickerAsync(spotClient.GetSymbolName("BTC", "USDT"));</code>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-balances-binance-tab" data-toggle="tab" href="#example-balances-binance" role="tab" aria-controls="example-balances-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-balances-bingx-tab" data-toggle="tab" href="#example-balances-bingx" role="tab" aria-controls="example-balances-bingx" aria-selected="true">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-balances-bitfinex-tab" data-toggle="tab" href="#example-balances-bitfinex" role="tab" aria-controls="example-balances-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -2419,6 +2556,9 @@ await spotClient.GetBalancesAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-balances-binance" role="tabpanel" aria-labelledby="example-balances-binance-tab">
<pre><code>await binanceClient.SpotApi.Account.GetBalancesAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-balances-bingx" role="tabpanel" aria-labelledby="example-balances-bingx-tab">
<pre><code>await bingXClient.SpotApi.Account.GetBalancesAsync();</code></pre>
</div>
<div class="tab-pane fade" id="example-balances-bitfinex" role="tabpanel" aria-labelledby="example-balances-bitfinex-tab">
<pre><code>await bitfinexClient.SpotApi.Account.GetBalancesAsync();</code></pre>
@@ -2475,6 +2615,9 @@ var result = await huobiClient.SpotApi.Account.GetBalancesAsync();</code></pre>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-place-binance-tab" data-toggle="tab" href="#example-place-binance" role="tab" aria-controls="example-place-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-place-binance-tab" data-toggle="tab" href="#example-place-bingx" role="tab" aria-controls="example-place-bingx" aria-selected="true">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-place-bitfinex-tab" data-toggle="tab" href="#example-place-bitfinex" role="tab" aria-controls="example-place-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -2511,6 +2654,9 @@ await spotClient.PlaceOrderAsync(spotClient.GetSymbolName("BTC", "USDT"), Common
</div>
<div class="tab-pane fade" id="example-place-binance" role="tabpanel" aria-labelledby="example-place-binance-tab">
<pre><code>await binanceClient.SpotApi.Trading.PlaceOrderAsync("BTCUSDT", OrderSide.Buy, SpotOrderType.Limit, 0.1m, price: 50000, timeInForce: TimeInForce.GoodTillCanceled);</code></pre>
</div>
<div class="tab-pane fade" id="example-place-bingx" role="tabpanel" aria-labelledby="example-place-bingx-tab">
<pre><code>await bingXClient.SpotApi.Trading.PlaceOrderAsync("BTC-USDT", OrderSide.Buy, OrderType.Limit, 0.1m, price: 50000);</code></pre>
</div>
<div class="tab-pane fade" id="example-place-bitfinex" role="tabpanel" aria-labelledby="example-place-bitfinex-tab">
<pre><code>await bitfinexClient.SpotApi.Trading.PlaceOrderAsync("tBTCUST", OrderSide.Buy, OrderType.Limit, 0.1m, 50000);</code></pre>
@@ -2564,6 +2710,9 @@ var result = await huobiClient.SpotApi.Trading.PlaceOrderAsync(account.Id, "BTCU
<li class="nav-item" role="presentation">
<a class="nav-link active" id="example-stream-ticker-binance-tab" data-toggle="tab" href="#example-stream-ticker-binance" role="tab" aria-controls="example-stream-ticker-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-stream-ticker-bingx-tab" data-toggle="tab" href="#example-stream-ticker-bingx" role="tab" aria-controls="example-stream-ticker-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-stream-ticker-bitfinex-tab" data-toggle="tab" href="#example-stream-ticker-bitfinex" role="tab" aria-controls="example-stream-ticker-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -2596,6 +2745,11 @@ var result = await huobiClient.SpotApi.Trading.PlaceOrderAsync(account.Id, "BTCU
<div class="tab-pane fade show active" id="example-stream-ticker-binance" role="tabpanel" aria-labelledby="example-stream-ticker-binance-tab">
<pre><code>await binanceSocketClient.SpotApi.ExchangeData.SubscribeToTickerUpdatesAsync("ETHUSDT", data => {
// Handle update
});</code></pre>
</div>
<div class="tab-pane fade" id="example-stream-ticker-bingx" role="tabpanel" aria-labelledby="example-stream-ticker-bingx-tab">
<pre><code>await bingXSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH-USDT", data => {
// Handle update
});</code></pre>
</div>
<div class="tab-pane fade" id="example-stream-ticker-bitfinex" role="tabpanel" aria-labelledby="example-stream-ticker-bitfinex-tab">
@@ -2665,6 +2819,9 @@ var result = await huobiClient.SpotApi.Trading.PlaceOrderAsync(account.Id, "BTCU
<li class="nav-item" role="presentation">
<a class="nav-link active" id="example-stream-order-binance-tab" data-toggle="tab" href="#example-stream-order-binance" role="tab" aria-controls="example-stream-order-binance" aria-selected="true">Binance</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-stream-order-bitfinex-tab" data-toggle="tab" href="#example-stream-order-bingx" role="tab" aria-controls="example-stream-order-bingx" aria-selected="false">BingX</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="example-stream-order-bitfinex-tab" data-toggle="tab" href="#example-stream-order-bitfinex" role="tab" aria-controls="example-stream-order-bitfinex" aria-selected="false">Bitfinex</a>
</li>
@@ -2709,7 +2866,26 @@ _ = Task.Run(async () => {
while (true)
{
await Task.Delay(Timespan.FromMinutes(30));
await binanceClient.SpotApi.Account.KeepAliveUserStreamAsync(token.Data);
await binanceClient.SpotApi.Account.KeepAliveUserStreamAsync(listenKey.Data);
}
});</code></pre>
</div>
<div class="tab-pane fade" id="example-stream-order-bingx" role="tabpanel" aria-labelledby="example-stream-order-bingx-tab">
<pre><code>// Retrieve the listen key
var listenKey = await bingXRestClient.SpotApi.Account.StartUserStreamAsync();
// Subscribe using the key
await bingXSocketClient.SpotApi.SubscribeToBalanceUpdatesAsync(listenKey.Data, data => {
// Handle update
});
// The listen key will stay valid for 60 minutes, after this no updates will be send anymore
// To extend the life time of the listen key it is recommended to call the KeepAliveUserStreamAsync method every 30 minutes
_ = Task.Run(async () => {
while (true)
{
await Task.Delay(Timespan.FromMinutes(30));
await bingXClient.SpotApi.Account.KeepAliveUserStreamAsync(listenKey.Data);
}
});</code></pre>
</div>