From f1342b5ff2b7ab8ab2af654a3e86829d866f494d Mon Sep 17 00:00:00 2001 From: Jkorf Date: Wed, 14 May 2025 14:30:05 +0200 Subject: [PATCH] Examples --- .../Testing/SocketSubscriptionValidator.cs | 9 ++++- Examples/BlazorClient/BlazorClient.csproj | 39 ++++++++++--------- Examples/BlazorClient/Pages/Index.razor | 11 ++++-- Examples/BlazorClient/Pages/LiveData.razor | 5 ++- Examples/BlazorClient/Pages/OrderBooks.razor | 11 ++++-- Examples/BlazorClient/Pages/Trackers.razor | 3 ++ Examples/BlazorClient/Startup.cs | 4 +- Examples/BlazorClient/_Imports.razor | 1 + Examples/ConsoleClient/ConsoleClient.csproj | 28 ++++++------- Examples/SharedClients/SharedClients.csproj | 6 +-- README.md | 2 +- 11 files changed, 71 insertions(+), 48 deletions(-) diff --git a/CryptoExchange.Net/Testing/SocketSubscriptionValidator.cs b/CryptoExchange.Net/Testing/SocketSubscriptionValidator.cs index b4dbc48..9e9ca41 100644 --- a/CryptoExchange.Net/Testing/SocketSubscriptionValidator.cs +++ b/CryptoExchange.Net/Testing/SocketSubscriptionValidator.cs @@ -94,7 +94,14 @@ namespace CryptoExchange.Net.Testing TUpdate? update = default; // Invoke subscription method - var task = methodInvoke(_client, x => { update = x.Data; }); + try + { + var task = methodInvoke(_client, x => { update = x.Data; }); + } + catch(Exception ex) + { + + } var replaceValues = new Dictionary(); while (true) diff --git a/Examples/BlazorClient/BlazorClient.csproj b/Examples/BlazorClient/BlazorClient.csproj index 172e8d8..7444201 100644 --- a/Examples/BlazorClient/BlazorClient.csproj +++ b/Examples/BlazorClient/BlazorClient.csproj @@ -5,26 +5,27 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + + diff --git a/Examples/BlazorClient/Pages/Index.razor b/Examples/BlazorClient/Pages/Index.razor index 8d7ec42..0a8dab9 100644 --- a/Examples/BlazorClient/Pages/Index.razor +++ b/Examples/BlazorClient/Pages/Index.razor @@ -18,6 +18,7 @@ @inject IMexcRestClient mexcClient @inject IOKXRestClient okxClient @inject IWhiteBitRestClient whitebitClient +@inject IXTRestClient xtClient

BTC-USD prices:

@foreach(var price in _prices.OrderBy(p => p.Key)) @@ -33,7 +34,7 @@ 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 bitgetTask = bitgetClient.SpotApiV2.ExchangeData.GetTickersAsync("BTCUSDT"); var bitmartTask = bitmartClient.SpotApi.ExchangeData.GetTickerAsync("BTC_USDT"); var bitmexTask = bitmexClient.ExchangeApi.ExchangeData.GetSymbolsAsync("XBT_USDT"); var bybitTask = bybitClient.V5Api.ExchangeData.GetSpotTickersAsync("BTCUSDT"); @@ -49,6 +50,7 @@ var mexcTask = mexcClient.SpotApi.ExchangeData.GetTickerAsync("BTCUSDT"); var okxTask = okxClient.UnifiedApi.ExchangeData.GetTickerAsync("BTCUSDT"); var whitebitTask = whitebitClient.V4Api.ExchangeData.GetTickersAsync(); + var xtTask = xtClient.SpotApi.ExchangeData.GetTickersAsync("eth_btc"); await Task.WhenAll(binanceTask, bingXTask, bitfinexTask, bitgetTask, bitmartTask, bybitTask, coinexTask, deepCoinTask, gateioTask, htxTask, krakenTask, kucoinTask, mexcTask, okxTask); @@ -62,10 +64,10 @@ _prices.Add("Bitfinex", bitfinexTask.Result.Data.LastPrice); if (bitgetTask.Result.Success) - _prices.Add("Bitget", bitgetTask.Result.Data.ClosePrice); + _prices.Add("Bitget", bitgetTask.Result.Data.Single().LastPrice); if (bitmartTask.Result.Success) - _prices.Add("BitMart", bitgetTask.Result.Data.ClosePrice); + _prices.Add("BitMart", bitmartTask.Result.Data.LastPrice); if (bitmexTask.Result.Success) _prices.Add("BitMEX", bitmexTask.Result.Data.First().LastPrice); @@ -119,6 +121,9 @@ var tickers = whitebitTask.Result.Data; _prices.Add("WhiteBit", tickers.Single(x => x.Symbol == "BTC_USDT").LastPrice); } + + if (xtTask.Result.Success) + _prices.Add("XT", xtTask.Result.Data.Single().LastPrice ?? 0); } } \ No newline at end of file diff --git a/Examples/BlazorClient/Pages/LiveData.razor b/Examples/BlazorClient/Pages/LiveData.razor index 665c5ed..9b2b161 100644 --- a/Examples/BlazorClient/Pages/LiveData.razor +++ b/Examples/BlazorClient/Pages/LiveData.razor @@ -18,10 +18,12 @@ @inject IMexcSocketClient mexcSocketClient @inject IOKXSocketClient okxSocketClient @inject IWhiteBitSocketClient whitebitSocketClient +@inject IXTSocketClient xtSocketClient @using System.Collections.Concurrent @using CryptoExchange.Net.Objects @using CryptoExchange.Net.Objects.Sockets; @using CryptoExchange.Net.Sockets +@using XT.Net.Interfaces.Clients @implements IDisposable

ETH-BTC prices, live updates:

@@ -41,7 +43,7 @@ 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)), + bitgetSocketClient.SpotApiV2.SubscribeToTickerUpdatesAsync("ETHBTC", data => UpdateData("Bitget", data.Data.LastPrice)), bitmartSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH_BTC", data => UpdateData("BitMart", data.Data.LastPrice)), bitmexSocketClient.ExchangeApi.SubscribeToSymbolUpdatesAsync("ETH_XBT", data => UpdateData("BitMEX", data.Data.LastPrice ?? 0)), bybitSocketClient.V5SpotApi.SubscribeToTickerUpdatesAsync("ETHBTC", data => UpdateData("Bybit", data.Data.LastPrice)), @@ -51,6 +53,7 @@ deepCoinSocketClient.ExchangeApi.SubscribeToSymbolUpdatesAsync("ETH-BTC", data => UpdateData("DeepCoin", data.Data.LastPrice ?? 0)), gateioSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH_BTC", data => UpdateData("GateIo", data.Data.LastPrice)), htxSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ethbtc", data => UpdateData("HTX", data.Data.ClosePrice ?? 0)), + xtSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("eth_btc", data => UpdateData("XT", data.Data.LastPrice ?? 0)), // HyperLiquid doesn't support the ETH/BTC pair //hyperLiquidSocketClient.SpotApi.SubscribeToSymbolUpdatesAsync("ETH", data => UpdateData("HyperLiquid", data.Data.MidPrice ?? 0)), krakenSocketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETH/BTC", data => UpdateData("Kraken", data.Data.LastPrice)), diff --git a/Examples/BlazorClient/Pages/OrderBooks.razor b/Examples/BlazorClient/Pages/OrderBooks.razor index c7b2234..e553563 100644 --- a/Examples/BlazorClient/Pages/OrderBooks.razor +++ b/Examples/BlazorClient/Pages/OrderBooks.razor @@ -10,6 +10,7 @@ @using Bybit.Net.Interfaces @using CoinEx.Net.Interfaces @using Coinbase.Net.Interfaces +@using CryptoExchange.Net.Authentication @using CryptoExchange.Net.Interfaces @using CryptoCom.Net.Interfaces @using DeepCoin.Net.Interfaces @@ -22,6 +23,7 @@ @using Mexc.Net.Interfaces @using OKX.Net.Interfaces; @using WhiteBit.Net.Interfaces +@using XT.Net.Interfaces @inject IBinanceOrderBookFactory binanceFactory @inject IBingXOrderBookFactory bingXFactory @inject IBitfinexOrderBookFactory bitfinexFactory @@ -41,6 +43,7 @@ @inject IMexcOrderBookFactory mexcFactory @inject IOKXOrderBookFactory okxFactory @inject IWhiteBitOrderBookFactory whitebitFactory +@inject IXTOrderBookFactory xtFactory @implements IDisposable

ETH-BTC books, live updates:

@@ -69,7 +72,7 @@ // Since the Kucoin order book stream needs authentication we will need to provide API credentials beforehand KucoinRestClient.SetDefaultOptions(options => { - options.ApiCredentials = new Kucoin.Net.Objects.KucoinApiCredentials("KEY", "SECRET", "PASSPHRASE"); + options.ApiCredentials = new ApiCredentials("KEY", "SECRET", "PASSPHRASE"); }); _books = new Dictionary @@ -85,7 +88,8 @@ { "CoinEx", coinExFactory.CreateSpot("ETHBTC") }, { "CryptoCom", cryptocomFactory.Create("ETH_BTC") }, { "GateIo", gateioFactory.CreateSpot("ETH_BTC") }, - { "DeepCoin", deepCoinFactory.Create("ETH-BTC") }, + // DeepCoin does not support the ETH/BTC pair + //{ "DeepCoin", deepCoinFactory.Create("ETH-BTC") }, { "HTX", htxFactory.CreateSpot("ethbtc") }, // HyperLiquid does not support the ETH/BTC pair //{ "HyperLiquid", hyperLiquidFactory.Create("ETH/BTC") }, @@ -94,9 +98,10 @@ { "Mexc", mexcFactory.CreateSpot("ETHBTC") }, { "OKX", okxFactory.Create("ETH-BTC") }, { "WhiteBit", whitebitFactory.CreateV4("ETH_BTC") }, + { "XT", xtFactory.CreateSpot("eth_btc") }, }; - await Task.WhenAll(_books.Select(b => b.Value.StartAsync())); + var result = await Task.WhenAll(_books.Select(b => b.Value.StartAsync())); // Use a manual update timer so the page isn't refreshed too often _timer = new Timer(500); diff --git a/Examples/BlazorClient/Pages/Trackers.razor b/Examples/BlazorClient/Pages/Trackers.razor index d5f6ccb..8372aa9 100644 --- a/Examples/BlazorClient/Pages/Trackers.razor +++ b/Examples/BlazorClient/Pages/Trackers.razor @@ -24,6 +24,7 @@ @using Mexc.Net.Interfaces @using OKX.Net.Interfaces; @using WhiteBit.Net.Interfaces +@using XT.Net.Interfaces @inject IBinanceTrackerFactory binanceFactory @inject IBingXTrackerFactory bingXFactory @inject IBitfinexTrackerFactory bitfinexFactory @@ -43,6 +44,7 @@ @inject IMexcTrackerFactory mexcFactory @inject IOKXTrackerFactory okxFactory @inject IWhiteBitTrackerFactory whitebitFactory +@inject IXTTrackerFactory xtFactory @implements IDisposable

ETH-BTC trade Trackers, live updates:

@@ -89,6 +91,7 @@ { mexcFactory.CreateTradeTracker(usdtSymbol, period: TimeSpan.FromMinutes(5)) }, { okxFactory.CreateTradeTracker(usdtSymbol, period: TimeSpan.FromMinutes(5)) }, { whitebitFactory.CreateTradeTracker(usdtSymbol, period: TimeSpan.FromMinutes(5)) }, + { xtFactory.CreateTradeTracker(usdtSymbol, period: TimeSpan.FromMinutes(5)) }, }; await Task.WhenAll(_trackers.Select(b => b.StartAsync())); diff --git a/Examples/BlazorClient/Startup.cs b/Examples/BlazorClient/Startup.cs index da7d9d4..9b60670 100644 --- a/Examples/BlazorClient/Startup.cs +++ b/Examples/BlazorClient/Startup.cs @@ -31,9 +31,6 @@ namespace BlazorClient services.AddBinance(restOptions => { restOptions.ApiCredentials = new ApiCredentials("KEY", "SECRET"); - }, socketOptions => - { - socketOptions.ApiCredentials = new ApiCredentials("KEY", "SECRET"); }); services.AddBingX(); @@ -54,6 +51,7 @@ namespace BlazorClient services.AddMexc(); services.AddOKX(); services.AddWhiteBit(); + services.AddXT(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Examples/BlazorClient/_Imports.razor b/Examples/BlazorClient/_Imports.razor index 3dc0bc3..d55b7e4 100644 --- a/Examples/BlazorClient/_Imports.razor +++ b/Examples/BlazorClient/_Imports.razor @@ -27,4 +27,5 @@ @using Mexc.Net.Interfaces.Clients; @using OKX.Net.Interfaces.Clients; @using WhiteBit.Net.Interfaces.Clients +@using XT.Net.Interfaces.Clients @using CryptoExchange.Net.Interfaces; \ No newline at end of file diff --git a/Examples/ConsoleClient/ConsoleClient.csproj b/Examples/ConsoleClient/ConsoleClient.csproj index 1f1d060..ffb096d 100644 --- a/Examples/ConsoleClient/ConsoleClient.csproj +++ b/Examples/ConsoleClient/ConsoleClient.csproj @@ -6,20 +6,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/Examples/SharedClients/SharedClients.csproj b/Examples/SharedClients/SharedClients.csproj index 554bb29..675510c 100644 --- a/Examples/SharedClients/SharedClients.csproj +++ b/Examples/SharedClients/SharedClients.csproj @@ -8,9 +8,9 @@ - - - + + + diff --git a/README.md b/README.md index 4ddb118..4ade401 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free t ## Support the project Any support is greatly appreciated. -## Referral +### Referral When creating an account on new exchanges please consider using a referral link from above. ### Donate