mirror of
				https://github.com/JKorf/CryptoExchange.Net
				synced 2025-10-30 18:07:42 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			127 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			127 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| @page "/OrderBooks"
 | |
| @using System.Collections.Concurrent
 | |
| @using System.Timers
 | |
| @using Binance.Net.Interfaces
 | |
| @using BingX.Net.Interfaces
 | |
| @using Bitfinex.Net.Interfaces
 | |
| @using Bitget.Net.Interfaces;
 | |
| @using BitMart.Net.Interfaces;
 | |
| @using BitMEX.Net.Interfaces;
 | |
| @using Bybit.Net.Interfaces
 | |
| @using CoinEx.Net.Interfaces
 | |
| @using CoinW.Net.Interfaces
 | |
| @using Coinbase.Net.Interfaces
 | |
| @using CryptoExchange.Net.Authentication
 | |
| @using CryptoExchange.Net.Interfaces
 | |
| @using CryptoCom.Net.Interfaces
 | |
| @using DeepCoin.Net.Interfaces
 | |
| @using GateIo.Net.Interfaces
 | |
| @using HTX.Net.Interfaces
 | |
| @using HyperLiquid.Net.Interfaces
 | |
| @using Kraken.Net.Interfaces
 | |
| @using Kucoin.Net.Clients
 | |
| @using Kucoin.Net.Interfaces
 | |
| @using Mexc.Net.Interfaces
 | |
| @using OKX.Net.Interfaces;
 | |
| @using Toobit.Net.Interfaces;
 | |
| @using WhiteBit.Net.Interfaces
 | |
| @using XT.Net.Interfaces
 | |
| @inject IBinanceOrderBookFactory binanceFactory
 | |
| @inject IBingXOrderBookFactory bingXFactory
 | |
| @inject IBitfinexOrderBookFactory bitfinexFactory
 | |
| @inject IBitgetOrderBookFactory bitgetFactory
 | |
| @inject IBitMartOrderBookFactory bitmartFactory
 | |
| @inject IBitMEXOrderBookFactory bitmexFactory
 | |
| @inject IBybitOrderBookFactory bybitFactory
 | |
| @inject ICoinbaseOrderBookFactory coinbaseFactory
 | |
| @inject ICoinExOrderBookFactory coinExFactory
 | |
| @inject ICoinWOrderBookFactory coinWFactory
 | |
| @inject ICryptoComOrderBookFactory cryptocomFactory
 | |
| @inject IDeepCoinOrderBookFactory deepCoinFactory
 | |
| @inject IGateIoOrderBookFactory gateioFactory
 | |
| @inject IHTXOrderBookFactory htxFactory
 | |
| @inject IHyperLiquidOrderBookFactory hyperLiquidFactory
 | |
| @inject IKrakenOrderBookFactory krakenFactory
 | |
| @inject IKucoinOrderBookFactory kucoinFactory
 | |
| @inject IMexcOrderBookFactory mexcFactory
 | |
| @inject IOKXOrderBookFactory okxFactory
 | |
| @inject IToobitOrderBookFactory toobitFactory
 | |
| @inject IWhiteBitOrderBookFactory whitebitFactory
 | |
| @inject IXTOrderBookFactory xtFactory
 | |
| @implements IDisposable
 | |
| 
 | |
| <h3>ETH-BTC books, live updates:</h3>
 | |
| <div style="display:flex; flex-wrap: wrap;">
 | |
|     @foreach(var book in _books.OrderBy(p => p.Key))
 | |
|     {
 | |
|         <div style="margin-bottom: 20px; flex: 1; min-width: 300px;">
 | |
|             <h4>@book.Key</h4>
 | |
|             @if (book.Value.AskCount >= 3 && book.Value.BidCount >= 3)
 | |
|             {
 | |
|                 for (var i = 0; i < 3; i++)
 | |
|                 {
 | |
|                     <div>@book.Value.Bids.ElementAt(i).Price - @book.Value.Asks.ElementAt(i).Price</div>
 | |
|                 }
 | |
|             }
 | |
|         </div>
 | |
|     }
 | |
| </div>
 | |
| 
 | |
| @code{
 | |
|     private Dictionary<string, ISymbolOrderBook> _books = new Dictionary<string, ISymbolOrderBook>();
 | |
|     private Timer _timer;
 | |
| 
 | |
|     protected override async Task OnInitializedAsync()
 | |
|     {
 | |
|         // Since the Kucoin order book stream needs authentication we will need to provide API credentials beforehand
 | |
|         KucoinRestClient.SetDefaultOptions(options =>
 | |
|         {
 | |
|             options.ApiCredentials = new ApiCredentials("KEY", "SECRET", "PASSPHRASE");
 | |
|         });
 | |
| 
 | |
|         _books = new Dictionary<string, ISymbolOrderBook>
 | |
|             {
 | |
|                 { "Binance", binanceFactory.CreateSpot("ETHBTC") },
 | |
|                 { "BingX", bingXFactory.CreateSpot("ETH-BTC") },
 | |
|                 { "Bitfinex", bitfinexFactory.Create("tETHBTC") },
 | |
|                 { "Bitget", bitgetFactory.CreateSpot("ETHBTC") },
 | |
|                 { "BitMart", bitmartFactory.CreateSpot("ETH_BTC", null) },
 | |
|                 { "BitMEX", bitmexFactory.Create("ETH_XBT") },
 | |
|                 { "Bybit", bybitFactory.Create("ETHBTC", Bybit.Net.Enums.Category.Spot) },
 | |
|                 { "Coinbase", coinbaseFactory.Create("ETH-BTC", null) },
 | |
|                 { "CoinEx", coinExFactory.CreateSpot("ETHBTC") },
 | |
|                 { "CoinW", coinWFactory.CreateSpot("ETH_BTC") },
 | |
|                 { "CryptoCom", cryptocomFactory.Create("ETH_BTC") },
 | |
|                 { "GateIo", gateioFactory.CreateSpot("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") },
 | |
|                 { "Kraken", krakenFactory.CreateSpot("ETH/BTC") },
 | |
|                 { "Kucoin", kucoinFactory.CreateSpot("ETH-BTC") },
 | |
|                 { "Mexc", mexcFactory.CreateSpot("ETHBTC") },
 | |
|                 { "OKX", okxFactory.Create("ETH-BTC") },
 | |
|                 // Toobit does not support the ETH/BTC pair
 | |
|                 //{ "Toobit", toobitFactory.Create("ETH/BTC") },
 | |
|                 { "WhiteBit", whitebitFactory.CreateV4("ETH_BTC") },
 | |
|                 { "XT", xtFactory.CreateSpot("eth_btc") },
 | |
|             };
 | |
| 
 | |
|         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);
 | |
|         _timer.Start();
 | |
|         _timer.Elapsed += (o, e) => InvokeAsync(StateHasChanged);
 | |
|     }
 | |
| 
 | |
|     public void Dispose()
 | |
|     {
 | |
|         _timer?.Stop();
 | |
|         _timer.Dispose();
 | |
|         foreach (var book in _books.Where(b => b.Value.Status != CryptoExchange.Net.Objects.OrderBookStatus.Disconnected))
 | |
|             // It's not necessary to wait for this
 | |
|             _ = book.Value.StopAsync();
 | |
|     }
 | |
| } |