From 6bb45e73c305f0955067f4bf28de47e434d1903c Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Fri, 27 Sep 2024 12:55:34 +0200 Subject: [PATCH] Revert "Feature/shared" --- CryptoClients.Net/CryptoClients.Net.csproj | 38 +- CryptoClients.Net/CryptoClients.Net.xml | 1843 +---------------- CryptoClients.Net/Enums/Exchange.cs | 66 +- CryptoClients.Net/ExchangeRestClient.cs | 886 +------- CryptoClients.Net/ExchangeSocketClient.cs | 316 --- .../CryptoClientsExtensions.cs | 203 -- .../Interfaces/IExchangeRestClient.cs | 722 +------ .../Interfaces/IExchangeSocketClient.cs | 274 --- .../Models/ExchangeCredentials.cs | 3 +- .../PriceService.cs | 19 +- .../CryptoClients.Examples.Api/Program.cs | 13 +- .../CryptoClients.Examples.Blazor.csproj | 2 +- .../Pages/Books.razor | 10 +- .../Pages/Index.razor | 4 +- .../Pages/Live.razor | 138 +- .../CryptoClients.Examples.Blazor/Program.cs | 2 +- .../CryptoClients.Examples.Console/Program.cs | 110 +- Examples/CryptoClients.Examples.sln | 26 +- Examples/RequestCurrentPrices/Program.cs | 40 - .../RequestCurrentPrices.csproj | 14 - Examples/RequestSpotSymbols/Program.cs | 25 - .../RequestSpotSymbols.csproj | 14 - Examples/StreamSymbolPrices/Program.cs | 66 - .../StreamSymbolPrices.csproj | 14 - Examples/StreamTrades/Program.cs | 20 - Examples/StreamTrades/StreamTrades.csproj | 14 - README.md | 85 +- 27 files changed, 311 insertions(+), 4656 deletions(-) delete mode 100644 CryptoClients.Net/ExtensionMethods/CryptoClientsExtensions.cs delete mode 100644 Examples/RequestCurrentPrices/Program.cs delete mode 100644 Examples/RequestCurrentPrices/RequestCurrentPrices.csproj delete mode 100644 Examples/RequestSpotSymbols/Program.cs delete mode 100644 Examples/RequestSpotSymbols/RequestSpotSymbols.csproj delete mode 100644 Examples/StreamSymbolPrices/Program.cs delete mode 100644 Examples/StreamSymbolPrices/StreamSymbolPrices.csproj delete mode 100644 Examples/StreamTrades/Program.cs delete mode 100644 Examples/StreamTrades/StreamTrades.csproj diff --git a/CryptoClients.Net/CryptoClients.Net.csproj b/CryptoClients.Net/CryptoClients.Net.csproj index dbc5ab1..9f2720f 100644 --- a/CryptoClients.Net/CryptoClients.Net.csproj +++ b/CryptoClients.Net/CryptoClients.Net.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netstandard2.1 enable @@ -37,32 +37,26 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + CryptoClients.Net.xml diff --git a/CryptoClients.Net/CryptoClients.Net.xml b/CryptoClients.Net/CryptoClients.Net.xml index 8394a90..dd284fc 100644 --- a/CryptoClients.Net/CryptoClients.Net.xml +++ b/CryptoClients.Net/CryptoClients.Net.xml @@ -9,76 +9,71 @@ Exchange - + Binance - + BingX - + Bitfinex - + Bitget - + BitMart - + Bybit - + CoinEx - + Gate.io - + HTX - + Kraken - + Kucoin - + Mexc - + OKX - - - All exchange names - - Exchange information @@ -188,183 +183,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create a new ExchangeRestClient instance. Client instances will be created with default options. @@ -380,171 +198,12 @@ DI constructor - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Information on supported exchanges and universal functionality @@ -667,344 +326,33 @@ - - - - - + + + Create a new ExchangeSocketClient instance. Client instances will be created with default options. + - - + + + Create a new ExchangeSocketClient instance + - - + + + DI constructor + - + - - + + + Factory for creating SymbolOrderBook instances; locally synced order books. + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create a new ExchangeSocketClient instance. Client instances will be created with default options. - - - - - Create a new ExchangeSocketClient instance - - - - - DI constructor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Extension methods - - - - - Return the task results in the form of an IAsyncEnumerable, returning the first completed task first - - Type of task result - Task list - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Get the if available - - - - - Factory for creating SymbolOrderBook instances; locally synced order books. - - - - - Binance order book factory - + + + Binance order book factory + @@ -1136,1144 +484,89 @@ OKX REST API - + - DEPRECATED; use instead for common/shared functionality. See for more info. + Get an ISpotClient for the specific exchange. + Exchange + - DEPRECATED; use instead for common/shared functionality. See for more info. - - - - - Get all ISharedClient REST Api interfaces supported for the specified exchange - - The exchange name - Filter clients by trading mode - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode + Get all ISpotClient interfaces - Trading mode - Exchange name + - + - Get the clients for all exchanges + Client for accessing the exchange Websocket API's. - + - Get the client for a specific exchange + Binance Websocket API - Exchange name - + - Get the clients for all exchanges + BingX Websocket API - + - Get all clients for all exchanges which supports the provided trading mode + Bitfinex Websocket API - The trading mode the client should support - + - Get the client for a specific exchange which supports the provided trading mode + Bitget Websocket API - Trading mode - Exchange name - + - Get the clients for all exchanges + BitMart Websocket API - + - Get all clients for all exchanges which supports the provided trading mode + Bybit Websocket API - The trading mode the client should support - + - Get the client for a specific exchange which supports the provided trading mode + CoinEx Websocket API - Trading mode - Exchange name - + - Get the clients for all exchanges + Gate.io Websocket API - + - Get all clients for all exchanges which supports the provided trading mode + HTX Websocket API - The trading mode the client should support - + - Get the client for a specific exchange which supports the provided trading mode + Kraken Websocket API - Trading mode - Exchange name - + - Get the clients for all exchanges + Kucoin Websocket API - + - Get all clients for all exchanges which supports the provided trading mode + Mexc Websocket API - The trading mode the client should support - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges - - - - - Get all clients for all exchanges which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get spot ticker information for all symbols on all exchanges, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get spot ticker information for all symbols on all exchanges, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get spot ticker information for a specific symbol from all exchanges, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get spot ticker information for a specific symbol from all exchanges, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures ticker information for all symbols on all exchanges, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures ticker information for all symbols on all exchanges, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures ticker information for a specific symbol from all exchanges, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures ticker information for a specific symbol from all exchanges, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get kline data for a specific symbol from all exchanges, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get kline data for a specific symbol from all exchanges, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get mark price kline data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get mark price kline data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get index price kline data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get index price kline data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get recent trades public data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get recent trades public data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get public trade history data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get public trade history data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get order book data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get order book data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get asset info of all assets on all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get asset info of all assets on all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get asset info of a specific asset on all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get asset info of a specific asset on all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user balances from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user balances from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user deposit history from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user deposit history from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user withdrawal history from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user withdrawal history from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get spot symbol info of all symbols from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get spot symbol info of all symbols from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get open spot orders for the user from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get open spot orders for the user from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get closed spot orders for a symbol for the user from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get closed spot orders for a symbol for the user from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user executed trades from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user executed trades from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get funding rate history for a symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get funding rate history for a symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get current open interest for a symbol from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get current open interest for a symbol from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures symbol info of all symbols from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get futures symbol info of all symbols from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user position history from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user position history from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get open Futures orders for the user from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get open Futures orders for the user from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get closed Futures orders for a symbol for the user from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get closed Futures orders for a symbol for the user from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user executed trades from all exchanges supporting this request, async returning in the order the response from the server is received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Get user executed trades from all exchanges supporting this request, returning all results when all responses have been received - - The request - Optional exchange filter, when not specified all exchanges will be queried - Cancelation token - - - - Client for accessing the exchange Websocket API's. - - - - - Binance Websocket API - - - - - BingX Websocket API - - - - - Bitfinex Websocket API - - - - - Bitget Websocket API - - - - - BitMart Websocket API - - - - - Bybit Websocket API - - - - - CoinEx Websocket API - - - - - Gate.io Websocket API - - - - - HTX Websocket API - - - - - Kraken Websocket API - - - - - Kucoin Websocket API - - - - - Mexc Websocket API - - - + OKX Websocket API - - - Get all ISharedClient Socket Api interfaces supported for the specified exchange - - The exchange name - Filter clients by trading mode - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get the client for a specific exchange - - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Get the clients for all exchanges which have support for it - - - - - Get all clients for all exchanges which have support for it and which supports the provided trading mode - - The trading mode the client should support - - - - Get the client for a specific exchange which supports the provided trading mode - - Trading mode - Exchange name - - - - Subscribe to ticker updates for all symbols on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to ticker updates for a specific symbol on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to public trade updates for a symbol on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to book ticker (best ask/bid price) updates for a symbol on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to kline/candlestick updates for a symbol on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to order book snapshot updates for a symbol on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to user balance updates on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to user spot orders updates on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to user futures orders updates on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - - - - Subscribe to user trade execution updates on all exchanges that support this subscription - - The request - The data handler callback - Optional exchange filter, when not specified all exchanges will be queried - Cancellation token, can be used to stop the updates - Unsubscribe and close every connection diff --git a/CryptoClients.Net/Enums/Exchange.cs b/CryptoClients.Net/Enums/Exchange.cs index 5550eab..801e797 100644 --- a/CryptoClients.Net/Enums/Exchange.cs +++ b/CryptoClients.Net/Enums/Exchange.cs @@ -1,97 +1,61 @@ -using Binance.Net; -using BingX.Net; -using Bitfinex.Net; -using Bitget.Net; -using BitMart.Net; -using Bybit.Net; -using CoinEx.Net; -using GateIo.Net; -using HTX.Net; -using Kraken.Net; -using Kucoin.Net; -using Mexc.Net; -using OKX.Net; -using System.Collections; -using System.Collections.Generic; - -namespace CryptoClients.Net.Enums +namespace CryptoClients.Net.Enums { /// /// Exchange /// - public static class Exchange + public enum Exchange { /// /// Binance /// - public static string Binance => BinanceExchange.ExchangeName; + Binance, /// /// BingX /// - public static string BingX => BingXExchange.ExchangeName; + BingX, /// /// Bitfinex /// - public static string Bitfinex => BitfinexExchange.ExchangeName; + Bitfinex, /// /// Bitget /// - public static string Bitget => BitgetExchange.ExchangeName; + Bitget, /// /// BitMart /// - public static string BitMart => BitMartExchange.ExchangeName; + BitMart, /// /// Bybit /// - public static string Bybit => BybitExchange.ExchangeName; + Bybit, /// /// CoinEx /// - public static string CoinEx => CoinExExchange.ExchangeName; + CoinEx, /// /// Gate.io /// - public static string GateIo => "GateIo"; + GateIo, /// /// HTX /// - public static string HTX => HTXExchange.ExchangeName; + HTX, /// /// Kraken /// - public static string Kraken => KrakenExchange.ExchangeName; + Kraken, /// /// Kucoin /// - public static string Kucoin => KucoinExchange.ExchangeName; + Kucoin, /// /// Mexc /// - public static string Mexc => MexcExchange.ExchangeName; + Mexc, /// /// OKX /// - public static string OKX => OKXExchange.ExchangeName; - - /// - /// All exchange names - /// - public static string[] All { get; } = new[] - { - Binance, - BingX, - Bitfinex, - Bitget, - BitMart, - Bybit, - CoinEx, - GateIo, - HTX, - Kraken, - Kucoin, - Mexc, - OKX - }; + OKX } } diff --git a/CryptoClients.Net/ExchangeRestClient.cs b/CryptoClients.Net/ExchangeRestClient.cs index eb180dd..b93db3f 100644 --- a/CryptoClients.Net/ExchangeRestClient.cs +++ b/CryptoClients.Net/ExchangeRestClient.cs @@ -19,13 +19,14 @@ using CoinEx.Net.Clients; using CoinEx.Net.Interfaces.Clients; using CoinEx.Net.Objects.Options; +using CryptoClients.Net.Enums; using CryptoClients.Net.Interfaces; using CryptoClients.Net.Models; using CryptoExchange.Net.Authentication; +using CryptoExchange.Net.CommonObjects; using CryptoExchange.Net.Interfaces.CommonClients; using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Options; -using CryptoExchange.Net.SharedApis; using GateIo.Net.Clients; using GateIo.Net.Interfaces.Clients; using GateIo.Net.Objects.Options; @@ -47,8 +48,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; -using System.Threading.Tasks; +using System.Xml.Linq; namespace CryptoClients.Net { @@ -56,7 +56,23 @@ namespace CryptoClients.Net public class ExchangeRestClient : IExchangeRestClient { private IEnumerable _spotClients = Array.Empty(); - private IEnumerable _sharedClients = Array.Empty(); + + private readonly Dictionary _exchangeMapping = new() + { + { Exchange.Binance, "Binance" }, + { Exchange.BingX, "BingX" }, + { Exchange.Bitfinex, "Bitfinex" }, + { Exchange.Bitget, "Bitget" }, + { Exchange.BitMart, "BitMart" }, + { Exchange.Bybit, "Bybit" }, + { Exchange.CoinEx, "CoinEx" }, + { Exchange.GateIo, "GateIo" }, + { Exchange.HTX, "HTX" }, + { Exchange.Kraken, "Kraken" }, + { Exchange.Kucoin, "Kucoin" }, + { Exchange.Mexc, "Mexc" }, + { Exchange.OKX, "OKX" }, + }; /// public IBinanceRestClient Binance { get; } @@ -85,147 +101,6 @@ public class ExchangeRestClient : IExchangeRestClient /// public IOKXRestClient OKX { get; } - - /// - public IEnumerable GetAssetsClients() => _sharedClients.OfType(); - /// - public IAssetsRestClient? GetAssetClient(string exchange) => GetAssetsClients().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetBalancesClients() => _sharedClients.OfType(); - /// - public IEnumerable GetBalancesClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IBalanceRestClient? GetBalancesClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetDepositsClients() => _sharedClients.OfType(); - /// - public IDepositRestClient? GetDepositsClient(string exchange) => GetDepositsClients().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetKlineClients() => _sharedClients.OfType(); - /// - public IEnumerable GetKlineClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IKlineRestClient? GetKlineClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetOrderBookClients() => _sharedClients.OfType(); - /// - public IEnumerable GetOrderBookClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IOrderBookRestClient? GetOrderBookClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetRecentTradesClients() => _sharedClients.OfType(); - /// - public IEnumerable GetRecentTradesClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IRecentTradeRestClient? GetRecentTradesClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetTradeHistoryClients() => _sharedClients.OfType(); - /// - public IEnumerable GetTradeHistoryClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public ITradeHistoryRestClient? GetTradeHistoryClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetWithdrawalsClients() => _sharedClients.OfType(); - /// - public IWithdrawalRestClient? GetWithdrawalsClient(string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetWithdrawClients() => _sharedClients.OfType(); - /// - public IWithdrawRestClient? GetWithdrawClient(string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetSpotOrderClients() => _sharedClients.OfType(); - /// - public ISpotOrderRestClient? GetSpotOrderClient(string exchange) => GetSpotOrderClients().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetSpotSymbolClients() => _sharedClients.OfType(); - /// - public ISpotSymbolRestClient? GetSpotSymbolClient(string exchange) => GetSpotSymbolClients().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetSpotTickerClients() => _sharedClients.OfType(); - /// - public ISpotTickerRestClient? GetSpotTickerClient(string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetFundingRateClients() => _sharedClients.OfType(); - /// - public IEnumerable GetFundingRateClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IFundingRateRestClient? GetFundingRateClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetFuturesOrderClients() => _sharedClients.OfType(); - /// - public IEnumerable GetFuturesOrderClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IFuturesOrderRestClient? GetFuturesOrderClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetFuturesSymbolClients() => _sharedClients.OfType(); - /// - public IEnumerable GetFuturesSymbolClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IFuturesSymbolRestClient? GetFuturesSymbolClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetFuturesTickerClients() => _sharedClients.OfType(); - /// - public IEnumerable GetFuturesTickerClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IFuturesTickerRestClient? GetFuturesTickerClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetIndexPriceKlineClients() => _sharedClients.OfType(); - /// - public IEnumerable GetIndexPriceKlineClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IIndexPriceKlineRestClient? GetIndexPriceKlineClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetLeverageClients() => _sharedClients.OfType(); - /// - public IEnumerable GetLeverageClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public ILeverageRestClient? GetLeverageClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetMarkPriceKlineClients() => _sharedClients.OfType(); - /// - public IEnumerable GetMarkPriceKlineClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IMarkPriceKlineRestClient? GetMarkPriceKlineClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetOpenInterestClients() => _sharedClients.OfType(); - /// - public IEnumerable GetOpenInterestClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IOpenInterestRestClient? GetOpenInterestClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetPositionModeClients() => _sharedClients.OfType(); - /// - public IEnumerable GetPositionModeClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IPositionModeRestClient? GetPositionModeClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetPositionHistoryClients() => _sharedClients.OfType(); - /// - public IEnumerable GetPositionHistoryClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IPositionHistoryRestClient? GetPositionHistoryClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - /// /// Create a new ExchangeRestClient instance. Client instances will be created with default options. /// @@ -246,7 +121,6 @@ public ExchangeRestClient() OKX = new OKXRestClient(); InitSpotClients(); - InitSharedClients(); } /// @@ -321,7 +195,6 @@ Action SetGlobalRestOptions(GlobalExchangeOpti OKX = new OKXRestClient(okxRestOptions); InitSpotClients(); - InitSharedClients(); } private void InitSpotClients() @@ -344,36 +217,6 @@ private void InitSpotClients() }; } - private void InitSharedClients() - { - _sharedClients = new ISharedClient[] - { - Binance.SpotApi.SharedClient, - Binance.UsdFuturesApi.SharedClient, - Binance.CoinFuturesApi.SharedClient, - BingX.SpotApi.SharedClient, - BingX.PerpetualFuturesApi.SharedClient, - Bitfinex.SpotApi.SharedClient, - Bitget.SpotApiV2.SharedClient, - Bitget.FuturesApiV2.SharedClient, - BitMart.SpotApi.SharedClient, - BitMart.UsdFuturesApi.SharedClient, - Bybit.V5Api.SharedClient, - CoinEx.SpotApiV2.SharedClient, - CoinEx.FuturesApi.SharedClient, - GateIo.SpotApi.SharedClient, - GateIo.PerpetualFuturesApi.SharedClient, - HTX.SpotApi.SharedClient, - HTX.UsdtFuturesApi.SharedClient, - Kraken.SpotApi.SharedClient, - Kraken.FuturesApi.SharedClient, - Kucoin.SpotApi.SharedClient, - Kucoin.FuturesApi.SharedClient, - Mexc.SpotApi.SharedClient, - OKX.UnifiedApi.SharedClient - }; - } - /// /// DI constructor /// @@ -408,14 +251,12 @@ public ExchangeRestClient( Kucoin = kucoin; Mexc = mexc; OKX = okx; - - InitSharedClients(); } /// - public ISpotClient GetUnifiedSpotClient(string name) + public ISpotClient GetUnifiedSpotClient(Exchange name) { - return _spotClients.Single(s => s.ExchangeName == name); + return _spotClients.Single(s => s.ExchangeName == _exchangeMapping[name]); } /// @@ -423,688 +264,5 @@ public IEnumerable GetUnifiedSpotClients() { return _spotClients.ToList(); } - - /// - public IEnumerable GetExchangeSharedClients(string name, TradingMode? tradingMode = null) - { - var result = _sharedClients.Where(s => s.Exchange == name); - if (tradingMode.HasValue) - result = result.Where(x => x.SupportedTradingModes.Contains(tradingMode.Value)); - return result.ToList(); - } - - #region Get Spot Tickers - - /// - public async Task>>> GetSpotTickersAsync(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotTickersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetSpotTickersAsyncEnumerable(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotTickersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetSpotTickersInt(GetTickersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotTickerClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetSpotTickersAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Spot Ticker - - /// - public async Task>> GetSpotTickerAsync(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotTickerInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable> GetSpotTickerAsyncEnumerable(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotTickerInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>> GetSpotTickerInt(GetTickerRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotTickerClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetSpotTickerAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Spot Symbols - - /// - public async Task>>> GetSpotSymbolsAsync(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotSymbolsInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetSpotSymbolsAsyncEnumerable(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotSymbolsInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetSpotSymbolsInt(GetSymbolsRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotSymbolClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetSpotSymbolsAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Spot Open Orders - - /// - public async Task>>> GetSpotOpenOrdersAsync(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotOpenOrdersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetSpotOpenOrdersAsyncEnumerable(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotOpenOrdersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetSpotOpenOrdersInt(GetOpenOrdersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetOpenSpotOrdersAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Spot Closed Orders - - /// - public async Task>>> GetSpotClosedOrdersAsync(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotClosedOrdersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetSpotClosedOrdersAsyncEnumerable(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotClosedOrdersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetSpotClosedOrdersInt(GetClosedOrdersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetClosedSpotOrdersAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Spot User Trades - - /// - public async Task>>> GetSpotUserTradesAsync(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetSpotUserTradesInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetSpotUserTradesAsyncEnumerable(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetSpotUserTradesInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetSpotUserTradesInt(GetUserTradesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetSpotOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetSpotUserTradesAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Futures Tickers - - /// - public async Task>>> GetFuturesTickersAsync(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesTickersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFuturesTickersAsyncEnumerable(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesTickersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFuturesTickersInt(GetTickersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesTickerClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetFuturesTickersAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Futures Ticker - - /// - public async Task>> GetFuturesTickerAsync(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesTickerInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable> GetFuturesTickerAsyncEnumerable(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesTickerInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>> GetFuturesTickerInt(GetTickerRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesTickerClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetFuturesTickerAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Klines - /// - public async Task>>> GetKlinesAsync(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetKlinesIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetKlinesIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetKlinesIntAsync(GetKlinesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetKlineClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetKlinesAsync(request, null, ct)); - return tasks; - } - - - #endregion - - #region Get Mark Price Klines - /// - public async Task>>> GetMarkPriceKlinesAsync(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetMarkPriceKlinesIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetMarkPriceKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetMarkPriceKlinesIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetMarkPriceKlinesIntAsync(GetKlinesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetMarkPriceKlineClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetMarkPriceKlinesAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Index Price Klines - /// - public async Task>>> GetIndexPriceKlinesAsync(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetIndexPriceKlinesIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetIndexPriceKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetIndexPriceKlinesIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetIndexPriceKlinesIntAsync(GetKlinesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetIndexPriceKlineClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetIndexPriceKlinesAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Recent Trades - - /// - public async Task>>> GetRecentTradesAsync(GetRecentTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetRecentTradesIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetRecentTradesAsyncEnumerable(GetRecentTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetRecentTradesIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetRecentTradesIntAsync(GetRecentTradesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetRecentTradesClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetRecentTradesAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Trade History - - /// - public async Task>>> GetTradeHistoryAsync(GetTradeHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetTradeHistoryInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetTradeHistoryAsyncEnumerable(GetTradeHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetTradeHistoryInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetTradeHistoryInt(GetTradeHistoryRequest request, IEnumerable? exchanges,CancellationToken ct) - { - var clients = GetTradeHistoryClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetTradeHistoryAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Order Book - - /// - public async Task>> GetOrderBookAsync(GetOrderBookRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetOrderBookInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable> GetOrderBookAsyncEnumerable(GetOrderBookRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetOrderBookInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>> GetOrderBookInt(GetOrderBookRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetOrderBookClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetOrderBookAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Assets - - /// - public async Task>>> GetAssetsAsync(GetAssetsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetAssetsIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetAssetsAsyncEnumerable(GetAssetsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetAssetsIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetAssetsIntAsync(GetAssetsRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetAssetsClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetAssetsAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Asset - - /// - public async Task>> GetAssetAsync(GetAssetRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetAssetIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable> GetAssetAsyncEnumerable(GetAssetRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetAssetIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>> GetAssetIntAsync(GetAssetRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetAssetsClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetAssetAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Futures Open Orders - - /// - public async Task>>> GetFuturesOpenOrdersAsync(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesOpenOrdersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFuturesOpenOrdersAsyncEnumerable(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesOpenOrdersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFuturesOpenOrdersInt(GetOpenOrdersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetOpenFuturesOrdersAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Futures Closed Orders - - /// - public async Task>>> GetFuturesClosedOrdersAsync(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesClosedOrdersInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFuturesClosedOrdersAsyncEnumerable(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesClosedOrdersInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFuturesClosedOrdersInt(GetClosedOrdersRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetClosedFuturesOrdersAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Futures User Trades - - /// - public async Task>>> GetFuturesUserTradesAsync(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesUserTradesInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFuturesUserTradesAsyncEnumerable(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesUserTradesInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFuturesUserTradesInt(GetUserTradesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetFuturesUserTradesAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Balances - - /// - public async Task>>> GetBalancesAsync(GetBalancesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetBalancesIntAsync(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetBalancesAsyncEnumerable(GetBalancesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetBalancesIntAsync(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetBalancesIntAsync(GetBalancesRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetBalancesClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetBalancesAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Deposits - - /// - public async Task>>> GetDepositsAsync(GetDepositsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetDepositsInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetDepositsAsyncEnumerable(GetDepositsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetDepositsInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetDepositsInt(GetDepositsRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetDepositsClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetDepositsAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Withdrawals - - /// - public async Task>>> GetWithdrawalsAsync(GetWithdrawalsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetWithdrawalsInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetWithdrawalsAsyncEnumerable(GetWithdrawalsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetWithdrawalsInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetWithdrawalsInt(GetWithdrawalsRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetWithdrawalsClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetWithdrawalsAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Funding Rate History - - /// - public async Task>>> GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFundingRateHistoryInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFundingRateHistoryAsyncEnumerable(GetFundingRateHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFundingRateHistoryInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFundingRateHistoryInt(GetFundingRateHistoryRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFundingRateClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetFundingRateHistoryAsync(request, null, ct)); - return tasks; - } - - #endregion - - #region Get Open Interest - - /// - public async Task>> GetOpenInterestAsync(GetOpenInterestRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetOpenInterestInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable> GetOpenInterestAsyncEnumerable(GetOpenInterestRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetOpenInterestInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>> GetOpenInterestInt(GetOpenInterestRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetOpenInterestClients().Where(x => x.SupportedTradingModes.Contains(request.Symbol.TradingMode)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetOpenInterestAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Futures Symbols - - /// - public async Task>>> GetFuturesSymbolsAsync(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetFuturesSymbolsInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetFuturesSymbolsAsyncEnumerable(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetFuturesSymbolsInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetFuturesSymbolsInt(GetSymbolsRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetFuturesSymbolClients().Where(x => request.TradingMode == null ? true: x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetFuturesSymbolsAsync(request, ct)); - return tasks; - } - - #endregion - - #region Get Position History - - /// - public async Task>>> GetPositionHistoryAsync(GetPositionHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return await Task.WhenAll(GetPositionHistoryInt(request, exchanges, ct)).ConfigureAwait(false); - } - - /// - public IAsyncEnumerable>> GetPositionHistoryAsyncEnumerable(GetPositionHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default) - { - return GetPositionHistoryInt(request, exchanges, ct).ParallelEnumerateAsync(); - } - - private IEnumerable>>> GetPositionHistoryInt(GetPositionHistoryRequest request, IEnumerable? exchanges, CancellationToken ct) - { - var clients = GetPositionHistoryClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => x.GetPositionHistoryAsync(request, null, ct)); - return tasks; - } - - #endregion } } diff --git a/CryptoClients.Net/ExchangeSocketClient.cs b/CryptoClients.Net/ExchangeSocketClient.cs index 22a0388..12fe01f 100644 --- a/CryptoClients.Net/ExchangeSocketClient.cs +++ b/CryptoClients.Net/ExchangeSocketClient.cs @@ -22,10 +22,7 @@ using CryptoClients.Net.Interfaces; using CryptoClients.Net.Models; using CryptoExchange.Net.Authentication; -using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects.Options; -using CryptoExchange.Net.Objects.Sockets; -using CryptoExchange.Net.SharedApis; using GateIo.Net.Clients; using GateIo.Net.Interfaces.Clients; using GateIo.Net.Objects.Options; @@ -45,9 +42,6 @@ using OKX.Net.Interfaces.Clients; using OKX.Net.Objects.Options; using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; using System.Threading.Tasks; namespace CryptoClients.Net @@ -55,8 +49,6 @@ namespace CryptoClients.Net /// public class ExchangeSocketClient : IExchangeSocketClient { - private IEnumerable _sharedClients = Array.Empty(); - /// public IBinanceSocketClient Binance { get; } /// @@ -84,81 +76,6 @@ public class ExchangeSocketClient : IExchangeSocketClient /// public IOKXSocketClient OKX { get; } - /// - public IEnumerable GetTickerClients() => _sharedClients.OfType(); - /// - public IEnumerable GetTickerClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public ITickerSocketClient? GetTickerClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetTickersClients() => _sharedClients.OfType(); - /// - public IEnumerable GetTickersClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public ITickersSocketClient? GetTickersClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetTradeClients() => _sharedClients.OfType(); - /// - public IEnumerable GetTradeClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public ITradeSocketClient? GetTradeClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetKlineClients() => _sharedClients.OfType(); - /// - public IEnumerable GetKlineClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IKlineSocketClient? GetKlineClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetOrderBookClients() => _sharedClients.OfType(); - /// - public IEnumerable GetOrderBookClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IOrderBookSocketClient? GetOrderBookClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetBalanceClients() => _sharedClients.OfType(); - /// - public IEnumerable GetBalanceClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IBalanceSocketClient? GetBalanceClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetBookTickerClients() => _sharedClients.OfType(); - /// - public IEnumerable GetBookTickerClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IBookTickerSocketClient? GetBookTickerClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetSpotOrderClients() => _sharedClients.OfType(); - /// - public ISpotOrderSocketClient? GetSpotOrderClient(string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.Exchange == exchange); - - /// - public IEnumerable GetFuturesOrderClients() => _sharedClients.OfType(); - /// - public IEnumerable GetFuturesOrderClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IFuturesOrderSocketClient? GetFuturesOrderClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetUserTradeClients() => _sharedClients.OfType(); - /// - public IEnumerable GetUserTradeClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IUserTradeSocketClient? GetUserTradeClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - - /// - public IEnumerable GetPositionClients() => _sharedClients.OfType(); - /// - public IEnumerable GetPositionClients(TradingMode api) => _sharedClients.OfType().Where(s => s.SupportedTradingModes.Contains(api)); - /// - public IPositionSocketClient? GetPositionClient(TradingMode api, string exchange) => _sharedClients.OfType().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange); - /// /// Create a new ExchangeSocketClient instance. Client instances will be created with default options. /// @@ -177,8 +94,6 @@ public ExchangeSocketClient() Kucoin = new KucoinSocketClient(); Mexc = new MexcSocketClient(); OKX = new OKXSocketClient(); - - InitSharedClients(); } /// @@ -252,8 +167,6 @@ Action SetGlobalSocketOptions(GlobalExchangeOp Kucoin = new KucoinSocketClient(kucoinSocketOptions ?? new Action((x) => { })); Mexc = new MexcSocketClient(mexcSocketOptions ?? new Action((x) => { })); OKX = new OKXSocketClient(okxSocketOptions ?? new Action((x) => { })); - - InitSharedClients(); } /// @@ -287,237 +200,8 @@ public ExchangeSocketClient( Kucoin = kucoin; Mexc = mexc; OKX = okx; - - InitSharedClients(); - } - - private void InitSharedClients() - { - _sharedClients = new ISharedClient[] - { - Binance.SpotApi.SharedClient, - Binance.UsdFuturesApi.SharedClient, - Binance.CoinFuturesApi.SharedClient, - BingX.SpotApi.SharedClient, - BingX.PerpetualFuturesApi.SharedClient, - Bitfinex.SpotApi.SharedClient, - Bitget.SpotApiV2.SharedClient, - Bitget.FuturesApiV2.SharedClient, - BitMart.SpotApi.SharedClient, - BitMart.UsdFuturesApi.SharedClient, - Bybit.V5InverseApi.SharedClient, - Bybit.V5LinearApi.SharedClient, - Bybit.V5PrivateApi.SharedClient, - Bybit.V5SpotApi.SharedClient, - CoinEx.SpotApiV2.SharedClient, - CoinEx.FuturesApi.SharedClient, - GateIo.SpotApi.SharedClient, - GateIo.PerpetualFuturesApi.SharedClient, - HTX.SpotApi.SharedClient, - HTX.UsdtFuturesApi.SharedClient, - Kraken.SpotApi.SharedClient, - Kraken.FuturesApi.SharedClient, - Kucoin.SpotApi.SharedClient, - Kucoin.FuturesApi.SharedClient, - Mexc.SpotApi.SharedClient, - OKX.UnifiedApi.SharedClient - }; - } - - /// - public IEnumerable GetExchangeSharedClients(string name, TradingMode? tradingMode = null) - { - var result = _sharedClients.Where(s => s.Exchange == name); - if (tradingMode.HasValue) - result = result.Where(x => x.SupportedTradingModes.Contains(tradingMode.Value)); - return result.ToList(); - } - - #region Subscribe All Ticker - - /// - public async Task>> SubscribeToAllTickerUpdatesAsync(SubscribeAllTickersRequest request, Action>> handler, IEnumerable? exchanges, CancellationToken ct = default) - { - var clients = GetTickersClients().Where(x => request.TradingMode == null ? true: x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - return new ExchangeResult(x.Exchange, await x.SubscribeToAllTickersUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Ticker - - /// - public async Task>> SubscribeToTickerUpdatesAsync(SubscribeTickerRequest request, Action> handler, IEnumerable? exchanges, CancellationToken ct = default) - { - var clients = GetTickerClients(request.Symbol.TradingMode); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - return new ExchangeResult(x.Exchange, await x.SubscribeToTickerUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Trade - - /// - public async Task>> SubscribeToTradeUpdatesAsync(SubscribeTradeRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetTradeClients(request.Symbol.TradingMode); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - - return new ExchangeResult(x.Exchange, await x.SubscribeToTradeUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Book Ticker - - /// - public async Task>> SubscribeToBookTickerUpdatesAsync(SubscribeBookTickerRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetBookTickerClients(request.Symbol.TradingMode); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - return new ExchangeResult(x.Exchange, await x.SubscribeToBookTickerUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Kline - - /// - public async Task>> SubscribeToKlineUpdatesAsync(SubscribeKlineRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetKlineClients(request.Symbol.TradingMode); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - return new ExchangeResult(x.Exchange, await x.SubscribeToKlineUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Order Book - - /// - public async Task>> SubscribeToOrderBookUpdatesAsync(SubscribeOrderBookRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetOrderBookClients(request.Symbol.TradingMode); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - return new ExchangeResult(x.Exchange, await x.SubscribeToOrderBookUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Balance - - /// - public async Task>> SubscribeToBalanceUpdatesAsync(SubscribeBalancesRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetBalanceClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - var exchangeRequest = request with { ListenKey = ExchangeParameters.GetValue(request.ExchangeParameters, x.Exchange, nameof(SubscribeBalancesRequest.ListenKey)) ?? request.ListenKey }; - return new ExchangeResult(x.Exchange, await x.SubscribeToBalanceUpdatesAsync(exchangeRequest, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe Spot Order - - /// - public async Task>> SubscribeToSpotOrderUpdatesAsync(SubscribeSpotOrderRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetSpotOrderClients(); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - var exchangeRequest = request with { ListenKey = ExchangeParameters.GetValue(request.ExchangeParameters, x.Exchange, nameof(SubscribeSpotOrderRequest.ListenKey)) ?? request.ListenKey }; - return new ExchangeResult(x.Exchange, await x.SubscribeToSpotOrderUpdatesAsync(exchangeRequest, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); } - #endregion - - #region Subscribe Futures Order - - /// - public async Task>> SubscribeToFuturesOrderUpdatesAsync(SubscribeFuturesOrderRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetFuturesOrderClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - var exchangeRequest = request with { ListenKey = ExchangeParameters.GetValue(request.ExchangeParameters, x.Exchange, nameof(SubscribeFuturesOrderRequest.ListenKey)) ?? request.ListenKey }; - return new ExchangeResult(x.Exchange, await x.SubscribeToFuturesOrderUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - - #region Subscribe User Trade - - /// - public async Task>> SubscribeToUserTradeUpdatesAsync(SubscribeUserTradeRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default) - { - var clients = GetUserTradeClients().Where(x => request.TradingMode == null ? true : x.SupportedTradingModes.Contains(request.TradingMode.Value)); - if (exchanges != null) - clients = clients.Where(c => exchanges.Contains(c.Exchange)); - - var tasks = clients.Select(x => Task.Run(async () => - { - var exchangeRequest = request with { ListenKey = ExchangeParameters.GetValue(request.ExchangeParameters, x.Exchange, nameof(SubscribeUserTradeRequest.ListenKey)) ?? request.ListenKey }; - return new ExchangeResult(x.Exchange, await x.SubscribeToUserTradeUpdatesAsync(request, handler, ct).ConfigureAwait(false)); - })); - return await Task.WhenAll(tasks).ConfigureAwait(false); - } - - #endregion - /// public async Task UnsubscribeAllAsync() { diff --git a/CryptoClients.Net/ExtensionMethods/CryptoClientsExtensions.cs b/CryptoClients.Net/ExtensionMethods/CryptoClientsExtensions.cs deleted file mode 100644 index 9cc9002..0000000 --- a/CryptoClients.Net/ExtensionMethods/CryptoClientsExtensions.cs +++ /dev/null @@ -1,203 +0,0 @@ -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace CryptoClients.Net -{ - /// - /// Extension methods - /// - public static class CryptoClientsExtensions - { - /// - /// Return the task results in the form of an IAsyncEnumerable, returning the first completed task first - /// - /// Type of task result - /// Task list - public static async IAsyncEnumerable ParallelEnumerateAsync(this IEnumerable> tasks) - { - var remaining = new List>(tasks); - - while (remaining.Count != 0) - { - var task = await Task.WhenAny(remaining).ConfigureAwait(false); - remaining.Remove(task); - yield return task.Result; - } - } - - /// - /// Get the if available - /// - public static IAssetsRestClient? AssetsRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IBalanceRestClient? BalanceRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IDepositRestClient? DepositRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IKlineRestClient? KlineRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IListenKeyRestClient? ListenKeyRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IOrderBookRestClient? OrderBookRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IRecentTradeRestClient? RecentTradesRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ITradeHistoryRestClient? TradeHistoryRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IWithdrawalRestClient? WithdrawalRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IWithdrawRestClient? WithdrawRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static ISpotTickerRestClient? SpotTickerRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static ISpotSymbolRestClient? SpotSymbolRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static ISpotOrderRestClient? SpotOrderRestClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IFundingRateRestClient? FundingRateRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IFuturesOrderRestClient? FuturesOrderRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IFuturesSymbolRestClient? FuturesSymbolRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IFuturesTickerRestClient? FuturesTickerRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IIndexPriceKlineRestClient? IndexPriceKlineRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ILeverageRestClient? LeverageRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IMarkPriceKlineRestClient? MarkPriceKlineRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IOpenInterestRestClient? OpenInterestRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IPositionHistoryRestClient? PositionHistoryRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IPositionModeRestClient? PositionModeRestClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IBalanceSocketClient? BalanceSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IBookTickerSocketClient? BookTickerSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IKlineSocketClient? KlineSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IOrderBookSocketClient? OrderBookSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ITickerSocketClient? TickerSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ITickersSocketClient? TickersSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ITradeSocketClient? TradeSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static IUserTradeSocketClient? UserTradeSocketClient(this IEnumerable clients, TradingMode tradingMode) => clients.OfType().SingleOrDefault(x => x.SupportedTradingModes.Contains(tradingMode)); - - /// - /// Get the if available - /// - public static ISpotOrderSocketClient? SpotOrderSocketClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IPositionSocketClient? PositionSocketClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - /// - /// Get the if available - /// - public static IFuturesOrderSocketClient? FuturesOrderSocketClient(this IEnumerable clients) => clients.OfType().SingleOrDefault(); - - } -} \ No newline at end of file diff --git a/CryptoClients.Net/Interfaces/IExchangeRestClient.cs b/CryptoClients.Net/Interfaces/IExchangeRestClient.cs index 102e67f..4b2492f 100644 --- a/CryptoClients.Net/Interfaces/IExchangeRestClient.cs +++ b/CryptoClients.Net/Interfaces/IExchangeRestClient.cs @@ -5,9 +5,8 @@ using BitMart.Net.Interfaces.Clients; using Bybit.Net.Interfaces.Clients; using CoinEx.Net.Interfaces.Clients; +using CryptoClients.Net.Enums; using CryptoExchange.Net.Interfaces.CommonClients; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; using GateIo.Net.Interfaces.Clients; using HTX.Net.Interfaces.Clients; using Kraken.Net.Interfaces.Clients; @@ -15,8 +14,6 @@ using Mexc.Net.Interfaces.Clients; using OKX.Net.Interfaces.Clients; using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; namespace CryptoClients.Net.Interfaces { @@ -79,721 +76,16 @@ public interface IExchangeRestClient IOKXRestClient OKX { get; } /// - /// DEPRECATED; use instead for common/shared functionality. See for more info. + /// Get an ISpotClient for the specific exchange. /// - ISpotClient GetUnifiedSpotClient(string exchange); + /// Exchange + /// + ISpotClient GetUnifiedSpotClient(Exchange exchange); /// - /// DEPRECATED; use instead for common/shared functionality. See for more info. + /// Get all ISpotClient interfaces /// + /// IEnumerable GetUnifiedSpotClients(); - - /// - /// Get all ISharedClient REST Api interfaces supported for the specified exchange - /// - /// The exchange name - /// Filter clients by trading mode - IEnumerable GetExchangeSharedClients(string exchange, TradingMode? tradingMode = null); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetAssetsClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - IAssetsRestClient? GetAssetClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetBalancesClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetBalancesClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IBalanceRestClient? GetBalancesClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetDepositsClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - IDepositRestClient? GetDepositsClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetKlineClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetKlineClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IKlineRestClient? GetKlineClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetOrderBookClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetOrderBookClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IOrderBookRestClient? GetOrderBookClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetRecentTradesClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetRecentTradesClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IRecentTradeRestClient? GetRecentTradesClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetTradeHistoryClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetTradeHistoryClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - ITradeHistoryRestClient? GetTradeHistoryClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetWithdrawalsClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - IWithdrawalRestClient? GetWithdrawalsClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetWithdrawClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - IWithdrawRestClient? GetWithdrawClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetSpotOrderClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - ISpotOrderRestClient? GetSpotOrderClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetSpotSymbolClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - ISpotSymbolRestClient? GetSpotSymbolClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetSpotTickerClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - ISpotTickerRestClient? GetSpotTickerClient(string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetFundingRateClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetFundingRateClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IFundingRateRestClient? GetFundingRateClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetFuturesOrderClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetFuturesOrderClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IFuturesOrderRestClient? GetFuturesOrderClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetFuturesSymbolClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetFuturesSymbolClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IFuturesSymbolRestClient? GetFuturesSymbolClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetFuturesTickerClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetFuturesTickerClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IFuturesTickerRestClient? GetFuturesTickerClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetIndexPriceKlineClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetIndexPriceKlineClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IIndexPriceKlineRestClient? GetIndexPriceKlineClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetLeverageClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetLeverageClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - ILeverageRestClient? GetLeverageClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetMarkPriceKlineClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetMarkPriceKlineClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IMarkPriceKlineRestClient? GetMarkPriceKlineClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetOpenInterestClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetOpenInterestClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IOpenInterestRestClient? GetOpenInterestClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetPositionModeClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetPositionModeClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IPositionModeRestClient? GetPositionModeClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges - /// - IEnumerable GetPositionHistoryClients(); - /// - /// Get all clients for all exchanges which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetPositionHistoryClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IPositionHistoryRestClient? GetPositionHistoryClient(TradingMode tradingMode, string exchange); - - /// - /// Get spot ticker information for all symbols on all exchanges, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetSpotTickersAsyncEnumerable(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get spot ticker information for all symbols on all exchanges, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetSpotTickersAsync(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get spot ticker information for a specific symbol from all exchanges, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable> GetSpotTickerAsyncEnumerable(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get spot ticker information for a specific symbol from all exchanges, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>> GetSpotTickerAsync(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get futures ticker information for all symbols on all exchanges, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFuturesTickersAsyncEnumerable(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get futures ticker information for all symbols on all exchanges, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFuturesTickersAsync(GetTickersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get futures ticker information for a specific symbol from all exchanges, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable> GetFuturesTickerAsyncEnumerable(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get futures ticker information for a specific symbol from all exchanges, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>> GetFuturesTickerAsync(GetTickerRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get kline data for a specific symbol from all exchanges, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get kline data for a specific symbol from all exchanges, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetKlinesAsync(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get mark price kline data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetMarkPriceKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get mark price kline data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetMarkPriceKlinesAsync(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get index price kline data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetIndexPriceKlinesAsyncEnumerable(GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get index price kline data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetIndexPriceKlinesAsync( GetKlinesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get recent trades public data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetRecentTradesAsyncEnumerable(GetRecentTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get recent trades public data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetRecentTradesAsync(GetRecentTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get public trade history data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetTradeHistoryAsyncEnumerable(GetTradeHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get public trade history data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetTradeHistoryAsync(GetTradeHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get order book data for a specific symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable> GetOrderBookAsyncEnumerable(GetOrderBookRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get order book data for a specific symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>> GetOrderBookAsync(GetOrderBookRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get asset info of all assets on all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetAssetsAsyncEnumerable(GetAssetsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get asset info of all assets on all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetAssetsAsync(GetAssetsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get asset info of a specific asset on all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable> GetAssetAsyncEnumerable(GetAssetRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get asset info of a specific asset on all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>> GetAssetAsync(GetAssetRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user balances from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetBalancesAsyncEnumerable(GetBalancesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user balances from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetBalancesAsync(GetBalancesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user deposit history from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetDepositsAsyncEnumerable(GetDepositsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user deposit history from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetDepositsAsync(GetDepositsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user withdrawal history from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetWithdrawalsAsyncEnumerable(GetWithdrawalsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user withdrawal history from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetWithdrawalsAsync(GetWithdrawalsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get spot symbol info of all symbols from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetSpotSymbolsAsyncEnumerable(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get spot symbol info of all symbols from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetSpotSymbolsAsync(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get open spot orders for the user from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetSpotOpenOrdersAsyncEnumerable(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get open spot orders for the user from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetSpotOpenOrdersAsync( GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get closed spot orders for a symbol for the user from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetSpotClosedOrdersAsyncEnumerable(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get closed spot orders for a symbol for the user from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetSpotClosedOrdersAsync(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user executed trades from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetSpotUserTradesAsyncEnumerable(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user executed trades from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetSpotUserTradesAsync(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get funding rate history for a symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFundingRateHistoryAsyncEnumerable(GetFundingRateHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get funding rate history for a symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFundingRateHistoryAsync(GetFundingRateHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get current open interest for a symbol from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable> GetOpenInterestAsyncEnumerable(GetOpenInterestRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get current open interest for a symbol from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>> GetOpenInterestAsync(GetOpenInterestRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get futures symbol info of all symbols from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFuturesSymbolsAsyncEnumerable(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get futures symbol info of all symbols from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFuturesSymbolsAsync(GetSymbolsRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user position history from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetPositionHistoryAsyncEnumerable(GetPositionHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user position history from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetPositionHistoryAsync(GetPositionHistoryRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get open Futures orders for the user from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFuturesOpenOrdersAsyncEnumerable(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get open Futures orders for the user from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFuturesOpenOrdersAsync(GetOpenOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get closed Futures orders for a symbol for the user from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFuturesClosedOrdersAsyncEnumerable(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get closed Futures orders for a symbol for the user from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFuturesClosedOrdersAsync(GetClosedOrdersRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Get user executed trades from all exchanges supporting this request, async returning in the order the response from the server is received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - IAsyncEnumerable>> GetFuturesUserTradesAsyncEnumerable(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - /// - /// Get user executed trades from all exchanges supporting this request, returning all results when all responses have been received - /// - /// The request - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancelation token - Task>>> GetFuturesUserTradesAsync(GetUserTradesRequest request, IEnumerable? exchanges = null, CancellationToken ct = default); - } } diff --git a/CryptoClients.Net/Interfaces/IExchangeSocketClient.cs b/CryptoClients.Net/Interfaces/IExchangeSocketClient.cs index 4ef5ae9..54d154b 100644 --- a/CryptoClients.Net/Interfaces/IExchangeSocketClient.cs +++ b/CryptoClients.Net/Interfaces/IExchangeSocketClient.cs @@ -5,18 +5,12 @@ using BitMart.Net.Interfaces.Clients; using Bybit.Net.Interfaces.Clients; using CoinEx.Net.Interfaces.Clients; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.Objects.Sockets; -using CryptoExchange.Net.SharedApis; using GateIo.Net.Interfaces.Clients; using HTX.Net.Interfaces.Clients; using Kraken.Net.Interfaces.Clients; using Kucoin.Net.Interfaces.Clients; using Mexc.Net.Interfaces.Clients; using OKX.Net.Interfaces.Clients; -using System; -using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; namespace CryptoClients.Net.Interfaces @@ -79,274 +73,6 @@ public interface IExchangeSocketClient /// IOKXSocketClient OKX { get; } - /// - /// Get all ISharedClient Socket Api interfaces supported for the specified exchange - /// - /// The exchange name - /// Filter clients by trading mode - IEnumerable GetExchangeSharedClients(string exchange, TradingMode? tradingMode = null); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetTickerClients(); - - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetTickerClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - ITickerSocketClient? GetTickerClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetTickersClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetTickersClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - ITickersSocketClient? GetTickersClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetTradeClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetTradeClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - ITradeSocketClient? GetTradeClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetBookTickerClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetBookTickerClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IBookTickerSocketClient? GetBookTickerClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetKlineClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetKlineClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IKlineSocketClient? GetKlineClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetOrderBookClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetOrderBookClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IOrderBookSocketClient? GetOrderBookClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetBalanceClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetBalanceClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IBalanceSocketClient? GetBalanceClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetSpotOrderClients(); - /// - /// Get the client for a specific exchange - /// - /// Exchange name - ISpotOrderSocketClient? GetSpotOrderClient(string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetFuturesOrderClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetFuturesOrderClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IFuturesOrderSocketClient? GetFuturesOrderClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetUserTradeClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetUserTradeClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IUserTradeSocketClient? GetUserTradeClient(TradingMode tradingMode, string exchange); - - /// - /// Get the clients for all exchanges which have support for it - /// - IEnumerable GetPositionClients(); - /// - /// Get all clients for all exchanges which have support for it and which supports the provided trading mode - /// - /// The trading mode the client should support - IEnumerable GetPositionClients(TradingMode tradingMode); - /// - /// Get the client for a specific exchange which supports the provided trading mode - /// - /// Trading mode - /// Exchange name - IPositionSocketClient? GetPositionClient(TradingMode tradingMode, string exchange); - - /// - /// Subscribe to ticker updates for all symbols on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToAllTickerUpdatesAsync(SubscribeAllTickersRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to ticker updates for a specific symbol on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToTickerUpdatesAsync(SubscribeTickerRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to public trade updates for a symbol on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToTradeUpdatesAsync(SubscribeTradeRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to book ticker (best ask/bid price) updates for a symbol on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToBookTickerUpdatesAsync(SubscribeBookTickerRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to kline/candlestick updates for a symbol on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToKlineUpdatesAsync(SubscribeKlineRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to order book snapshot updates for a symbol on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToOrderBookUpdatesAsync(SubscribeOrderBookRequest request, Action> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to user balance updates on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToBalanceUpdatesAsync(SubscribeBalancesRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to user spot orders updates on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToSpotOrderUpdatesAsync(SubscribeSpotOrderRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to user futures orders updates on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToFuturesOrderUpdatesAsync(SubscribeFuturesOrderRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - - /// - /// Subscribe to user trade execution updates on all exchanges that support this subscription - /// - /// The request - /// The data handler callback - /// Optional exchange filter, when not specified all exchanges will be queried - /// Cancellation token, can be used to stop the updates - Task>> SubscribeToUserTradeUpdatesAsync(SubscribeUserTradeRequest request, Action>> handler, IEnumerable? exchanges = null, CancellationToken ct = default); - /// /// Unsubscribe and close every connection /// diff --git a/CryptoClients.Net/Models/ExchangeCredentials.cs b/CryptoClients.Net/Models/ExchangeCredentials.cs index 3683dda..5dcd23f 100644 --- a/CryptoClients.Net/Models/ExchangeCredentials.cs +++ b/CryptoClients.Net/Models/ExchangeCredentials.cs @@ -1,5 +1,4 @@ using Bitget.Net.Objects; -using BitMart.Net.Objects; using CryptoExchange.Net.Authentication; using Kucoin.Net.Objects; using OKX.Net.Objects; @@ -34,7 +33,7 @@ public class ExchangeCredentials /// /// BitMart API credentials /// - public BitMartApiCredentials? BitMart { get; set; } + public BitgetApiCredentials? BitMart { get; set; } /// /// Bybit API credentials diff --git a/Examples/CryptoClients.Examples.Api/PriceService.cs b/Examples/CryptoClients.Examples.Api/PriceService.cs index e9b1a08..6f2fa6e 100644 --- a/Examples/CryptoClients.Examples.Api/PriceService.cs +++ b/Examples/CryptoClients.Examples.Api/PriceService.cs @@ -1,8 +1,6 @@  using CryptoClients.Net.Enums; using CryptoClients.Net.Interfaces; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; using System.Collections.Concurrent; namespace CryptoClients.Examples.Api @@ -10,31 +8,26 @@ namespace CryptoClients.Examples.Api public class PriceService : IHostedService { private IExchangeSocketClient _socketClient; - private ConcurrentDictionary _prices; + private ConcurrentDictionary _prices; private CancellationTokenSource _cancellationTokenSource; public PriceService(IExchangeSocketClient socketClient) { _socketClient = socketClient; - _prices = new ConcurrentDictionary(); + _prices = new ConcurrentDictionary(); _cancellationTokenSource = new CancellationTokenSource(); } - public decimal GetPrice(string exchange) => _prices[exchange]; + public decimal GetPrice(Exchange exchange) => _prices[exchange]; public async Task StartAsync(CancellationToken cancellationToken) { - var binanceTask = SubscribeClient(_socketClient.Binance.SpotApi.SharedClient); - var bingXTask = SubscribeClient(_socketClient.BingX.SpotApi.SharedClient); - var bybitTask = SubscribeClient(_socketClient.Bybit.V5SpotApi.SharedClient); + var binanceTask = _socketClient.Binance.SpotApi.ExchangeData.SubscribeToTickerUpdatesAsync("ETHUSDT", x => _prices[Exchange.Binance] = x.Data.LastPrice, _cancellationTokenSource.Token); + var bingXTask = _socketClient.BingX.SpotApi.SubscribeToTickerUpdatesAsync("ETH-USDT", x => _prices[Exchange.BingX] = x.Data.LastPrice, _cancellationTokenSource.Token); + var bybitTask = _socketClient.Bybit.V5SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", x => _prices[Exchange.Bybit] = x.Data.LastPrice, _cancellationTokenSource.Token); await Task.WhenAll(binanceTask, bingXTask, bybitTask); } - private async Task SubscribeClient(ITickerSocketClient client) - { - await client.SubscribeToTickerUpdatesAsync(new SubscribeTickerRequest(new SharedSymbol(TradingMode.Spot, "ETH", "USDT")), x => _prices[Exchange.Binance] = x.Data.LastPrice ?? 0, _cancellationTokenSource.Token); - } - public Task StopAsync(CancellationToken cancellationToken) { _cancellationTokenSource.Cancel(); diff --git a/Examples/CryptoClients.Examples.Api/Program.cs b/Examples/CryptoClients.Examples.Api/Program.cs index 2b9dcb2..b7b507c 100644 --- a/Examples/CryptoClients.Examples.Api/Program.cs +++ b/Examples/CryptoClients.Examples.Api/Program.cs @@ -1,8 +1,6 @@ using CryptoClients.Examples.Api; using CryptoClients.Net.Enums; using CryptoClients.Net.Interfaces; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); @@ -19,13 +17,10 @@ app.UseSwaggerUI(); app.UseHttpsRedirection(); -app.MapGet("priceFromRequest", async (IExchangeRestClient restClient, string exchange, string baseAsset, string quoteAsset) => +app.MapGet("priceFromRequest", async (IExchangeRestClient restClient, Exchange exchange, string baseAsset, string quoteAsset) => { - var exchangeClient = restClient.GetSpotTickerClient(exchange); - if (exchangeClient == null) - return Results.Problem("Exchange not found"); - - var result = await exchangeClient.GetSpotTickerAsync(new GetTickerRequest(new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset))); + var exchangeClient = restClient.GetUnifiedSpotClient(exchange); + var result = await exchangeClient.GetTickerAsync(exchangeClient.GetSymbolName(baseAsset, quoteAsset)); if (!result) return Results.Problem(result.Error!.ToString()); @@ -34,7 +29,7 @@ .WithName("GetPriceRequest") .WithOpenApi(); -app.MapGet("priceFromSocket", ([FromServices]PriceService service, string exchange) => +app.MapGet("priceFromSocket", ([FromServices]PriceService service, Exchange exchange) => { return Results.Ok(service.GetPrice(exchange)); }) diff --git a/Examples/CryptoClients.Examples.Blazor/CryptoClients.Examples.Blazor.csproj b/Examples/CryptoClients.Examples.Blazor/CryptoClients.Examples.Blazor.csproj index 32cb01f..4d507b1 100644 --- a/Examples/CryptoClients.Examples.Blazor/CryptoClients.Examples.Blazor.csproj +++ b/Examples/CryptoClients.Examples.Blazor/CryptoClients.Examples.Blazor.csproj @@ -1,7 +1,7 @@ - net8.0 + net7.0 enable enable diff --git a/Examples/CryptoClients.Examples.Blazor/Pages/Books.razor b/Examples/CryptoClients.Examples.Blazor/Pages/Books.razor index bacd95d..0c02c1a 100644 --- a/Examples/CryptoClients.Examples.Blazor/Pages/Books.razor +++ b/Examples/CryptoClients.Examples.Blazor/Pages/Books.razor @@ -42,17 +42,17 @@ @code { - private Dictionary _books = new Dictionary(); + private Dictionary _books = new Dictionary(); private string _baseAsset = "BTC"; private string _quoteAsset = "USDT"; - private Timer? _timer; + private Timer _timer; protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { - _books = new Dictionary + _books = new Dictionary { { Exchange.Binance, BookFactory.Binance.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.BingX, BookFactory.BingX.Spot.Create(_baseAsset, _quoteAsset) }, @@ -60,7 +60,7 @@ { Exchange.Bitget, BookFactory.Bitget.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.Bybit, BookFactory.Bybit.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.CoinEx, BookFactory.CoinEx.Spot.Create(_baseAsset, _quoteAsset) }, - { Exchange.HTX, BookFactory.HTX.Spot.Create(_baseAsset, _quoteAsset) }, + { Exchange.Huobi, BookFactory.Huobi.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.Kraken, BookFactory.Kraken.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.Kucoin, BookFactory.Kucoin.Spot.Create(_baseAsset, _quoteAsset) }, { Exchange.Mexc, BookFactory.Mexc.Spot.Create(_baseAsset, _quoteAsset) }, @@ -81,6 +81,6 @@ foreach (var book in _books) book.Value.StopAsync(); - _timer?.Dispose(); + _timer.Dispose(); } } \ No newline at end of file diff --git a/Examples/CryptoClients.Examples.Blazor/Pages/Index.razor b/Examples/CryptoClients.Examples.Blazor/Pages/Index.razor index 55c857b..c3381cf 100644 --- a/Examples/CryptoClients.Examples.Blazor/Pages/Index.razor +++ b/Examples/CryptoClients.Examples.Blazor/Pages/Index.razor @@ -51,10 +51,10 @@ @code { private string[] _assets = new[] { "BTC", "ETH", "SOL", "ZZZ" }; - private string[] _exchanges = Exchange.All; + private Exchange[] _exchanges = Enum.GetValues(); private string _selectedAsset = "BTC"; - private string _selectedExchange = Exchange.Bybit; + private Exchange _selectedExchange = Exchange.Bybit; private string? _error; private decimal? _open; diff --git a/Examples/CryptoClients.Examples.Blazor/Pages/Live.razor b/Examples/CryptoClients.Examples.Blazor/Pages/Live.razor index 02610fe..681dc53 100644 --- a/Examples/CryptoClients.Examples.Blazor/Pages/Live.razor +++ b/Examples/CryptoClients.Examples.Blazor/Pages/Live.razor @@ -1,8 +1,18 @@ @page "/live" +@using Binance.Net.Interfaces +@using Binance.Net.Objects.Models.Spot.Socket +@using BingX.Net.Objects.Models +@using Bitfinex.Net.Objects.Models +@using Bitget.Net.Objects.Models +@using Bybit.Net.Objects.Models.V5 +@using CoinEx.Net.Objects.Models.V2 @using CryptoExchange.Net.CommonObjects -@using CryptoExchange.Net.Objects @using CryptoExchange.Net.Objects.Sockets -@using CryptoExchange.Net.SharedApis +@using Huobi.Net.Objects.Models +@using Kraken.Net.Objects.Models +@using Kucoin.Net.Objects.Models.Spot.Socket +@using Mexc.Net.Objects.Models.Spot +@using OKX.Net.Objects.Market @inject IExchangeSocketClient SocketClient @implements IDisposable @@ -21,11 +31,11 @@ { @exchangeVolume.Key - @Math.Round(exchangeVolume.Value, 8) + @exchangeVolume.Value } -
Total volume: @Math.Round(_volume.Select(v => v.Value).Sum(),8)
+
Total volume: @_volume.Select(v => v.Value).Sum()
@@ -39,8 +49,8 @@ { - - + + } } @@ -51,20 +61,14 @@ { class ExchangeTrade { - public string Exchange { get; set; } + public Exchange Exchange { get; set; } public Trade Trade { get; set; } - - public ExchangeTrade(string exchange, Trade trade) - { - Exchange = exchange; - Trade = trade; - } } private object _lock = new object(); private int _max = 100; private List _trades = new List(); - private Dictionary _volume = new Dictionary(); + private Dictionary _volume = new Dictionary(); private string _baseAsset = "BTC"; private string _quoteAsset = "USDT"; @@ -74,28 +78,112 @@ { if (firstRender) { - var symbol = new SharedSymbol(TradingMode.Spot, _baseAsset, _quoteAsset); - var request = new SubscribeTradeRequest(symbol); - await SocketClient.SubscribeToTradeUpdatesAsync(request, HandleUpdate); + var tasks = new Task[] { + SocketClient.Binance.SpotApi.ExchangeData.SubscribeToTradeUpdatesAsync(SocketClient.Binance.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), BinanceUpdate), + SocketClient.BingX.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.BingX.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), BingXUpdate), + SocketClient.Bitfinex.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.Bitfinex.SpotApi.FormatSymbol(_baseAsset, "UST"), BitfinexUpdate), + SocketClient.Bitget.SpotApi.SubscribeToTradeUpdatesAsync(new[] { SocketClient.Bitget.SpotApi.FormatSymbol(_baseAsset, _quoteAsset) }, BitgetUpdate), + SocketClient.Bybit.V5SpotApi.SubscribeToTradeUpdatesAsync(new[] { SocketClient.Bybit.V5SpotApi.FormatSymbol(_baseAsset, _quoteAsset) }, BybitUpdate), + SocketClient.CoinEx.SpotApiV2.SubscribeToTradeUpdatesAsync(SocketClient.CoinEx.SpotApiV2.FormatSymbol(_baseAsset, _quoteAsset), CoinExUpdate), + SocketClient.Huobi.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.Huobi.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), HuobiUpdate), + SocketClient.Kraken.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.Kraken.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), KrakenUpdate), + SocketClient.Kucoin.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.Kucoin.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), KucoinUpdate), + SocketClient.Mexc.SpotApi.SubscribeToTradeUpdatesAsync(SocketClient.Mexc.SpotApi.FormatSymbol(_baseAsset, _quoteAsset), MexcUpdate), + SocketClient.OKX.UnifiedApi.ExchangeData.SubscribeToTradeUpdatesAsync(SocketClient.OKX.UnifiedApi.FormatSymbol(_baseAsset, _quoteAsset), OKXUpdate), + }; + await Task.WhenAll(tasks); } } - private void HandleUpdate(ExchangeEvent> trades) + private void BinanceUpdate(DataEvent trade) + => AddTrade(Exchange.Binance, trade.Data.Price, trade.Data.Quantity, trade.Data.TradeTime); + + private void BingXUpdate(DataEvent trade) + => AddTrade(Exchange.BingX, trade.Data.Price, trade.Data.Quantity, trade.Data.TradeTime); + + private void BitfinexUpdate(DataEvent> trades) { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + foreach(var trade in trades.Data) - AddTrade(trades.Exchange, trade.Price, trade.Quantity, trade.Timestamp); + AddTrade(Exchange.Bitfinex, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void BitgetUpdate(DataEvent> trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data) + AddTrade(Exchange.Bitget, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void BybitUpdate(DataEvent> trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data) + AddTrade(Exchange.Bybit, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void CoinExUpdate(DataEvent> trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data) + AddTrade(Exchange.CoinEx, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void HuobiUpdate(DataEvent trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data.Details) + AddTrade(Exchange.Huobi, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void KrakenUpdate(DataEvent> trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data) + AddTrade(Exchange.Kraken, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); + } + + private void KucoinUpdate(DataEvent trade) + => AddTrade(Exchange.Kucoin, trade.Data.Price, trade.Data.Quantity, trade.Data.Timestamp); + + private void MexcUpdate(DataEvent> trades) + { + if (trades.UpdateType == CryptoExchange.Net.Objects.SocketUpdateType.Snapshot) + return; + + foreach (var trade in trades.Data) + AddTrade(Exchange.Mexc, trade.Price, Math.Abs(trade.Quantity), trade.Timestamp); } - private void AddTrade(string exchange, decimal price, decimal quantity, DateTime timestamp) + private void OKXUpdate(DataEvent trade) + => AddTrade(Exchange.OKX, trade.Data.Price, trade.Data.Quantity, trade.Data.Time); + + private void AddTrade(Exchange exchange, decimal price, decimal quantity, DateTime timestamp) { lock (_lock) { - _trades.Add(new ExchangeTrade(exchange, new Trade + _trades.Add(new ExchangeTrade { - Price = price, - Quantity = quantity, - Timestamp = timestamp - })); + Exchange = exchange, + Trade = new Trade + { + Price = price, + Quantity = quantity, + Timestamp = timestamp + } + }); if (_volume.ContainsKey(exchange)) _volume[exchange] += quantity; diff --git a/Examples/CryptoClients.Examples.Blazor/Program.cs b/Examples/CryptoClients.Examples.Blazor/Program.cs index eeaad9e..ae14553 100644 --- a/Examples/CryptoClients.Examples.Blazor/Program.cs +++ b/Examples/CryptoClients.Examples.Blazor/Program.cs @@ -17,7 +17,7 @@ app.UseHsts(); } -//app.UseHttpsRedirection(); +app.UseHttpsRedirection(); app.UseStaticFiles(); diff --git a/Examples/CryptoClients.Examples.Console/Program.cs b/Examples/CryptoClients.Examples.Console/Program.cs index a6801c5..69abd6f 100644 --- a/Examples/CryptoClients.Examples.Console/Program.cs +++ b/Examples/CryptoClients.Examples.Console/Program.cs @@ -4,8 +4,6 @@ using Bybit.Net.SymbolOrderBooks; using CryptoClients.Net; using CryptoClients.Net.Enums; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; using Kucoin.Net.Clients; // ##################################################################################################################################### @@ -21,21 +19,17 @@ // 1. Request tickers //await TickerExampleExchangeSpecific(); //await TickerExampleUnified(); -//await TickerExampleUnified2(); // 2. Place a new order //await PlaceOrderExampleExchangeSpecific(); //await PlaceOrderExampleUnified(); // 3. Subscribe to price updates -//await SubscribePriceUpdatesExchangeSpecific(); -//await SubscribePriceUpdatesUnified(); -//await SubscribePriceUpdatesUnified2(); +//await SubscribePriceUpdates(); // 4. Locally synced order books //await StartOrderBooks(); -Console.ReadLine(); async Task TickerExampleExchangeSpecific() { @@ -75,11 +69,9 @@ async Task TickerExampleUnified() var bingx = client.GetUnifiedSpotClient(Exchange.BingX); var bybit = client.GetUnifiedSpotClient(Exchange.Bybit); - var symbol = new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset); - var request = new GetTickerRequest(symbol); - var resultBinance = client.GetSpotTickerClient(Exchange.Binance)!.GetSpotTickerAsync(request); - var resultBingX = client.GetSpotTickerClient(Exchange.BingX)!.GetSpotTickerAsync(request); - var resultBybit = client.GetSpotTickerClient(Exchange.Bybit)!.GetSpotTickerAsync(request); + var resultBinance = binance.GetTickerAsync(binance.GetSymbolName(baseAsset, quoteAsset)); + var resultBingX = bingx.GetTickerAsync(bingx.GetSymbolName(baseAsset, quoteAsset)); + var resultBybit = bybit.GetTickerAsync(bybit.GetSymbolName(baseAsset, quoteAsset)); await Task.WhenAll(resultBinance, resultBingX, resultBybit); Console.WriteLine(); @@ -91,31 +83,6 @@ async Task TickerExampleUnified() } } -async Task TickerExampleUnified2() -{ - while (true) - { - Console.WriteLine("Enter base asset: "); - var baseAsset = Console.ReadLine(); - Console.WriteLine("Enter quote asset: "); - var quoteAsset = Console.ReadLine(); - - var client = new ExchangeRestClient(); - var binance = client.GetUnifiedSpotClient(Exchange.Binance); - var bingx = client.GetUnifiedSpotClient(Exchange.BingX); - var bybit = client.GetUnifiedSpotClient(Exchange.Bybit); - - var symbol = new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset); - var request = new GetTickerRequest(symbol); - - Console.WriteLine("Exchange prices:"); - await foreach(var result in client.GetSpotTickerAsyncEnumerable(request, [Exchange.Binance, Exchange.BingX, Exchange.Bybit])) - Console.WriteLine($"{result.Exchange}:" + (result.Success ? result.Data.LastPrice : result.Error)); - - Console.WriteLine(); - } -} - async Task PlaceOrderExampleExchangeSpecific() { Console.WriteLine("Enter base asset: "); @@ -160,7 +127,7 @@ async Task PlaceOrderExampleUnified() Console.WriteLine("Enter quote asset: "); var quoteAsset = Console.ReadLine(); Console.WriteLine("Enter side (buy/sell): "); - var side = Enum.Parse(Console.ReadLine(), true); + var side = Enum.Parse(Console.ReadLine(), true); Console.WriteLine("Enter quantity: "); var quantity = decimal.Parse(Console.ReadLine()); Console.WriteLine("Enter price: "); @@ -179,17 +146,13 @@ async Task PlaceOrderExampleUnified() options.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("BybitKey", "BybitSecret"); }); - var request = new PlaceSpotOrderRequest( - new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset), - side, - SharedOrderType.Limit, - quantity, - price: price - ); - - var resultBinance = client.GetSpotOrderClient(Exchange.Binance)!.PlaceSpotOrderAsync(request); - var resultBingX = client.GetSpotOrderClient(Exchange.BingX)!.PlaceSpotOrderAsync(request); - var resultBybit = client.GetSpotOrderClient(Exchange.Bybit)!.PlaceSpotOrderAsync(request); + var binance = client.GetUnifiedSpotClient(Exchange.Binance); + var bingX = client.GetUnifiedSpotClient(Exchange.BingX); + var bybit = client.GetUnifiedSpotClient(Exchange.Bybit); + + var resultBinance = binance.PlaceOrderAsync(binance.GetSymbolName(baseAsset, quoteAsset), side, CryptoExchange.Net.CommonObjects.CommonOrderType.Limit, quantity, price); + var resultBingX = bingX.PlaceOrderAsync(bingX.GetSymbolName(baseAsset, quoteAsset), side, CryptoExchange.Net.CommonObjects.CommonOrderType.Limit, quantity, price); + var resultBybit = bybit.PlaceOrderAsync(bybit.GetSymbolName(baseAsset, quoteAsset), side, CryptoExchange.Net.CommonObjects.CommonOrderType.Limit, quantity, price); await Task.WhenAll(resultBinance, resultBingX, resultBybit); Console.WriteLine("Binance:" + (resultBinance.Result.Success ? resultBinance.Result.Data.Id : resultBinance.Result.Error)); @@ -198,7 +161,7 @@ async Task PlaceOrderExampleUnified() Console.ReadLine(); } -async Task SubscribePriceUpdatesExchangeSpecific() +async Task SubscribePriceUpdates() { Console.WriteLine("Enter base asset: "); var baseAsset = Console.ReadLine(); @@ -220,53 +183,6 @@ async Task SubscribePriceUpdatesExchangeSpecific() Console.ReadLine(); } -async Task SubscribePriceUpdatesUnified() -{ - Console.WriteLine("Enter base asset: "); - var baseAsset = Console.ReadLine(); - Console.WriteLine("Enter quote asset: "); - var quoteAsset = Console.ReadLine(); - - var client = new ExchangeSocketClient(); - var symbol = new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset); - var request = new SubscribeTickerRequest(symbol); - var resultBinance = client.GetTickerClient(TradingMode.Spot, Exchange.Binance)!.SubscribeToTickerUpdatesAsync(request, update => Console.WriteLine($"Update from {update.Exchange}: {update.Data.LastPrice}")); - var resultBingX = client.GetTickerClient(TradingMode.Spot, Exchange.BingX)!.SubscribeToTickerUpdatesAsync(request, update => Console.WriteLine($"Update from {update.Exchange}: {update.Data.LastPrice}")); - var resultBybit = client.GetTickerClient(TradingMode.Spot, Exchange.Bybit)!.SubscribeToTickerUpdatesAsync(request, update => Console.WriteLine($"Update from {update.Exchange}: {update.Data.LastPrice}")); - await Task.WhenAll(resultBinance, resultBingX, resultBybit); - - Console.WriteLine(); - - if (!resultBinance.Result.Success) Console.WriteLine("Binance subscription failed: " + resultBinance.Result.Error); - if (!resultBingX.Result.Success) Console.WriteLine("BingX subscription failed: " + resultBingX.Result.Error); - if (!resultBybit.Result.Success) Console.WriteLine("Bybit subscription failed: " + resultBybit.Result.Error); - - Console.ReadLine(); -} - -async Task SubscribePriceUpdatesUnified2() -{ - Console.WriteLine("Enter base asset: "); - var baseAsset = Console.ReadLine(); - Console.WriteLine("Enter quote asset: "); - var quoteAsset = Console.ReadLine(); - - var client = new ExchangeSocketClient(); - var symbol = new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset); - var request = new SubscribeTickerRequest(symbol); - var results = await client.SubscribeToTickerUpdatesAsync(request, update => Console.WriteLine($"Update from {update.Exchange}: {update.Data.LastPrice}"), [Exchange.Binance, Exchange.BingX, Exchange.Bybit]); - - Console.WriteLine(); - - foreach (var result in results) - { - if (!result.Success) - Console.WriteLine($"{result.Exchange} subscription failed: {result.Error}"); - } - - Console.ReadLine(); -} - async Task StartOrderBooks() { Console.WriteLine("Enter base asset: "); diff --git a/Examples/CryptoClients.Examples.sln b/Examples/CryptoClients.Examples.sln index 8c1d3db..9a71333 100644 --- a/Examples/CryptoClients.Examples.sln +++ b/Examples/CryptoClients.Examples.sln @@ -9,15 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoClients.Net", "..\Cry EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoClients.Examples.Api", "CryptoClients.Examples.Api\CryptoClients.Examples.Api.csproj", "{4068C1D1-DCCC-451F-8542-4ADAAF7086C4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CryptoClients.Examples.Blazor", "CryptoClients.Examples.Blazor\CryptoClients.Examples.Blazor.csproj", "{42D2A652-7713-4E39-9D07-F9135E07E5A9}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamSymbolPrices", "StreamSymbolPrices\StreamSymbolPrices.csproj", "{907343AB-DCA2-45BB-B31D-CF4091A8BD95}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RequestCurrentPrices", "RequestCurrentPrices\RequestCurrentPrices.csproj", "{A2DCF957-9F8D-44A1-94D5-BC9C7962BCDC}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RequestSpotSymbols", "RequestSpotSymbols\RequestSpotSymbols.csproj", "{1CE8B5BF-D778-425A-979A-8B9805F489E2}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StreamTrades", "StreamTrades\StreamTrades.csproj", "{FE48688D-6FDA-4853-AC7B-1744C2C408EA}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CryptoClients.Examples.Blazor", "CryptoClients.Examples.Blazor\CryptoClients.Examples.Blazor.csproj", "{42D2A652-7713-4E39-9D07-F9135E07E5A9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -41,22 +33,6 @@ Global {42D2A652-7713-4E39-9D07-F9135E07E5A9}.Debug|Any CPU.Build.0 = Debug|Any CPU {42D2A652-7713-4E39-9D07-F9135E07E5A9}.Release|Any CPU.ActiveCfg = Release|Any CPU {42D2A652-7713-4E39-9D07-F9135E07E5A9}.Release|Any CPU.Build.0 = Release|Any CPU - {907343AB-DCA2-45BB-B31D-CF4091A8BD95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {907343AB-DCA2-45BB-B31D-CF4091A8BD95}.Debug|Any CPU.Build.0 = Debug|Any CPU - {907343AB-DCA2-45BB-B31D-CF4091A8BD95}.Release|Any CPU.ActiveCfg = Release|Any CPU - {907343AB-DCA2-45BB-B31D-CF4091A8BD95}.Release|Any CPU.Build.0 = Release|Any CPU - {A2DCF957-9F8D-44A1-94D5-BC9C7962BCDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A2DCF957-9F8D-44A1-94D5-BC9C7962BCDC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A2DCF957-9F8D-44A1-94D5-BC9C7962BCDC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A2DCF957-9F8D-44A1-94D5-BC9C7962BCDC}.Release|Any CPU.Build.0 = Release|Any CPU - {1CE8B5BF-D778-425A-979A-8B9805F489E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1CE8B5BF-D778-425A-979A-8B9805F489E2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1CE8B5BF-D778-425A-979A-8B9805F489E2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1CE8B5BF-D778-425A-979A-8B9805F489E2}.Release|Any CPU.Build.0 = Release|Any CPU - {FE48688D-6FDA-4853-AC7B-1744C2C408EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FE48688D-6FDA-4853-AC7B-1744C2C408EA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FE48688D-6FDA-4853-AC7B-1744C2C408EA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FE48688D-6FDA-4853-AC7B-1744C2C408EA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Examples/RequestCurrentPrices/Program.cs b/Examples/RequestCurrentPrices/Program.cs deleted file mode 100644 index 1888bfa..0000000 --- a/Examples/RequestCurrentPrices/Program.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CryptoClients.Net; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; -using System.Diagnostics; - -var symbols = new[] -{ - // Symbols to retrieve - new SharedSymbol(TradingMode.Spot, "BTC", "USDT"), - new SharedSymbol(TradingMode.Spot, "ETH", "USDT"), - new SharedSymbol(TradingMode.Spot, "XRP", "USDT") -}; - -var client = new ExchangeRestClient(); -foreach (var symbol in symbols) -{ - Console.WriteLine($"{symbol.BaseAsset}/{symbol.QuoteAsset}"); - - // Method 1, GetSpotTickerAsync will return all results when all requests have finished - var sw = Stopwatch.StartNew(); - var tickers = await client.GetSpotTickerAsync(new GetTickerRequest(symbol)); - foreach (var result in tickers) - Console.WriteLine($"{result.Exchange}: {result.Data.LastPrice}, result in {sw.ElapsedMilliseconds}ms"); - sw.Stop(); - Console.WriteLine(); - Console.WriteLine($"Method 1, All exchanges completed in {sw.ElapsedMilliseconds}ms"); - Console.WriteLine(); - - // Method 2, GetSpotTickerAsyncEnumerable will return results whenever a request is finished instead of waiting for all requests - sw.Restart(); - await foreach (var result in client.GetSpotTickerAsyncEnumerable(new GetTickerRequest(symbol))) - Console.WriteLine($"{result.Exchange}: {result.Data.LastPrice}, result in {sw.ElapsedMilliseconds}ms"); - sw.Stop(); - - Console.WriteLine(); - Console.WriteLine($"Method 2, All exchanges completed in {sw.ElapsedMilliseconds}ms"); - Console.WriteLine(); -} - -Console.ReadLine(); diff --git a/Examples/RequestCurrentPrices/RequestCurrentPrices.csproj b/Examples/RequestCurrentPrices/RequestCurrentPrices.csproj deleted file mode 100644 index 81b228e..0000000 --- a/Examples/RequestCurrentPrices/RequestCurrentPrices.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/Examples/RequestSpotSymbols/Program.cs b/Examples/RequestSpotSymbols/Program.cs deleted file mode 100644 index 7f0ae7a..0000000 --- a/Examples/RequestSpotSymbols/Program.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CryptoClients.Net; -using CryptoExchange.Net.SharedApis; - -var client = new ExchangeRestClient(); -// Method 1, GetSpotSymbolsAsync will return all results when all requests have finished -var symbols = await client.GetSpotSymbolsAsync(new GetSymbolsRequest()); -foreach (var result in symbols) -{ - Console.WriteLine($"{result.Exchange} - first 3 symbols"); - foreach(var symbol in result.Data.Take(3)) - Console.WriteLine($" {symbol.BaseAsset} {symbol.QuoteAsset} -> {symbol.Name}"); - Console.WriteLine(); -} - -// Method 2, GetSpotSymbolsAsyncEnumerable will return results whenever a request is finished instead of waiting for all requests -await foreach (var result in client.GetSpotSymbolsAsyncEnumerable(new GetSymbolsRequest())) -{ - Console.WriteLine($"{result.Exchange} - first 3 symbols"); - foreach (var symbol in result.Data.Take(3)) - Console.WriteLine($" {symbol.BaseAsset} {symbol.QuoteAsset} -> {symbol.Name}"); - Console.WriteLine(); -} - - -Console.ReadLine(); diff --git a/Examples/RequestSpotSymbols/RequestSpotSymbols.csproj b/Examples/RequestSpotSymbols/RequestSpotSymbols.csproj deleted file mode 100644 index 81b228e..0000000 --- a/Examples/RequestSpotSymbols/RequestSpotSymbols.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/Examples/StreamSymbolPrices/Program.cs b/Examples/StreamSymbolPrices/Program.cs deleted file mode 100644 index d33fea1..0000000 --- a/Examples/StreamSymbolPrices/Program.cs +++ /dev/null @@ -1,66 +0,0 @@ -using CryptoClients.Net; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; -using System.Collections.Concurrent; - -var cache = new ConcurrentDictionary>(); -var symbols = new[] -{ - // Symbols to track - new SharedSymbol(TradingMode.Spot, "BTC", "USDT"), - new SharedSymbol(TradingMode.Spot, "ETH", "USDT"), - new SharedSymbol(TradingMode.Spot, "XRP", "USDT") -}; - -var client = new ExchangeSocketClient(); -foreach (var symbol in symbols) -{ - // Subscribe to ticker updates on all exchanges for each symbol - var result = await client.SubscribeToTickerUpdatesAsync(new SubscribeTickerRequest(symbol), x => - { - if (!cache.ContainsKey(x.Exchange)) - cache[x.Exchange] = new List(); - - var value = cache[x.Exchange].SingleOrDefault(c => c.Symbol == symbol.BaseAsset); - if (value == null) - cache[x.Exchange].Add(new ExchangeTicker { Symbol = symbol.BaseAsset }); - else - value.Price = x.Data.LastPrice; - }); - - // Output any failed subscriptions - foreach (var failed in result.Where(x => !x.Success)) - Console.WriteLine($"{failed.Exchange}: {failed.Error}"); -} - -// Small delay to display any failed subscription messages -await Task.Delay(3000); - -// Loop continuously -while (true) -{ - Console.Clear(); - - foreach (var symbol in symbols) - { - Console.WriteLine($"{symbol.BaseAsset}"); - foreach (var exchange in cache) - { - var value = exchange.Value.SingleOrDefault(x => x.Symbol == symbol.BaseAsset)?.Price; - if (value == null) - continue; - - Console.WriteLine($"{exchange.Key}: {value}"); - } - Console.WriteLine(); - } - - await Task.Delay(500); -} - - -class ExchangeTicker -{ - public string Symbol { get; set; } = string.Empty; - public decimal? Price { get; set; } -} \ No newline at end of file diff --git a/Examples/StreamSymbolPrices/StreamSymbolPrices.csproj b/Examples/StreamSymbolPrices/StreamSymbolPrices.csproj deleted file mode 100644 index 81b228e..0000000 --- a/Examples/StreamSymbolPrices/StreamSymbolPrices.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/Examples/StreamTrades/Program.cs b/Examples/StreamTrades/Program.cs deleted file mode 100644 index bea4a49..0000000 --- a/Examples/StreamTrades/Program.cs +++ /dev/null @@ -1,20 +0,0 @@ - -using CryptoClients.Net; -using CryptoClients.Net.Enums; -using CryptoExchange.Net.Objects; -using CryptoExchange.Net.SharedApis; - -var symbol = new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT"); -var socketClient = new ExchangeSocketClient(); - -// Subscribe to trade updates for the specified exchange -foreach (var subResult in await socketClient.SubscribeToTradeUpdatesAsync(new SubscribeTradeRequest(symbol), LogTrades, [Exchange.Binance, Exchange.HTX, Exchange.OKX])) - Console.WriteLine($"{subResult.Exchange} subscribe result: {subResult.Success} {subResult.Error}"); - -Console.ReadLine(); - -void LogTrades(ExchangeEvent> update) -{ - foreach (var item in update.Data) - Console.WriteLine($"{update.Exchange.PadRight(10)} | {item.Quantity} @ {item.Price}"); -} \ No newline at end of file diff --git a/Examples/StreamTrades/StreamTrades.csproj b/Examples/StreamTrades/StreamTrades.csproj deleted file mode 100644 index 81b228e..0000000 --- a/Examples/StreamTrades/StreamTrades.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - diff --git a/README.md b/README.md index 3222e6f..fafb496 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,6 @@ There are 2 main clients, the `ExchangeRestClient` and `ExchangeSocketClient`, f Alternatively exchange specific clients can be used, for example `BinanceRestClient` or `KucoinSocketClient`. Either create new clients directly or use Dotnet dependency injection. -*Dependency injection* -```csharp -// Dependency injection, allows the injection of `IExchangeRestClient`, `IExchangeSocketClient` and `IExchangeOrderBookFactory` interfaces -// as well as for all exchanges the `I[ExchangeName]RestClient`, `I[ExchangeName]SocketClient` and `I[ExchangeName]OrderBookFactory` types -services.AddCryptoClients(); -``` - *Construction* ```csharp // Client for accessing all exchanges @@ -88,9 +81,15 @@ IExchangeSocketClient socketClient = new ExchangeSocketClient(); IBinanceRestClient binanceRestClient = new BinanceRestClient(); IKucoinSocketClient kucoinSocketClient = new KucoinSocketClient(); ``` +*Dependency injection* +```csharp +// Dependency injection, allows the injection of `IExchangeRestClient`, `IExchangeSocketClient` and `IExchangeOrderBookFactory` interfaces +// as well as for all exchanges the `I[ExchangeName]RestClient`, `I[ExchangeName]SocketClient` and `I[ExchangeName]OrderBookFactory` types +services.AddCryptoClients(); +``` ### Configuration -Clients can be configured during the dependency injection registration, or when constructing the clients. Configuration can be done for all exchanges/clients, can be set per exchange or a combination: +Clients can be configured when doing the dependency injection registration, or when constructing the clients. Configuration can be done for all exchanges/clients, can be set per exchange or a combination: ```csharp builder.Services.AddCryptoClients(globalOptions => { @@ -112,67 +111,55 @@ bybitRestOptions: bybitOptions => }); ``` -More info on options available for each client can be found in the [CryptoExchange.Net documentation](https://jkorf.github.io/CryptoExchange.Net/#idocs_options_def). - -### Usage -There are multiple ways to access exchange API's. Options 1 and 2 allow access to the full exchange API while option 3 uses a common interface which allows exchange agnostic requesting, but is therefor limited in functionality. - -Option 1 -Using the exchange specific clients directly. This offers full functionality of the exchange API's. +### Using the client +There are multiple options for accessing exchange API's. Options 1 and 2 allow access to the full exchange API while option 3 uses a common interface which allows exchange agnostic requesting, but is therefor limited in functionality. +Option 3 is currently only supported for the Spot REST API's. ```csharp +// Option 1 +// Use exchange clients directly, full functionality var kucoinClient1 = new KucoinRestClient(); var binanceClient1 = new BinanceRestClient(); var binanceResult1 = await binanceClient1.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT"); var kucoinResult1 = await kucoinClient1.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT"); -``` -Option 2 -Using the exchange clients via the main client, also allows for full functionality of the exchange API's. -```csharp +// Option 2 +// Use exchange client via ExchangeRestClient, full functionality var restClient2 = new ExchangeRestClient(); -var binanceResult2 = await restClient2.Binance.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT"); -var kucoinResult2 = await restClient2.Kucoin.SpotApi.ExchangeData.GetTickerAsync("ETH-USDT"); -``` - -Option 3 -Using the shared client interfaces to access exchanges. This is the most generic and exchange agnostic way, but might not support all functionality the full API offers. -```csharp -// Define functionality based on shared interface -async Task> GetTickerAsync(ISpotTickerRestClient client, SharedSymbol symbol) - => await client.GetSpotTickerAsync(new GetTickerRequest(symbol)); - -// Execute for multiple exchanges -var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT"); -var binanceResult3 = await GetTickerAsync(restClient3.Binance.SpotApi.SharedClient, symbol); -var kucoinResult3 = await GetTickerAsync(restClient3.Kucoin.SpotApi.SharedClient, symbol); -``` - -Option 4 -Using the shared client interfaces thought the main client. For this the same limitation applies as option 3. -```csharp -var symbol = new SharedSymbol(TradingMode.Spot, "ETH", "USDT"); -var tickers = await restClient.GetSpotTickerAsync(new GetTickerRequest(symbol), [Exchange.Binance, Exchange.Kucoin]); +var baseAsset2 = "ETH"; +var quoteAsset2 = "USDT"; +var binanceResult2 = await restClient2.Binance.SpotApi.ExchangeData.GetTickerAsync(restClient2.Binance.SpotApi.FormatSymbol(baseAsset2, quoteAsset2)); +var kucoinResult2 = await restClient2.Kucoin.SpotApi.ExchangeData.GetTickerAsync(restClient2.Kucoin.SpotApi.FormatSymbol(baseAsset2, quoteAsset2)); + +// Option 3 +// Use unified spot client via GetUnifiedSpotClient, most generic but only supports common functionality +var restClient3 = new ExchangeRestClient(); +var baseAsset3 = "ETH"; +var quoteAsset3 = "USDT"; +var unifiedBinanceClient3 = restClient3.GetUnifiedSpotClient(Exchange.Binance); +var unifiedKucoinClient3 = restClient3.GetUnifiedSpotClient(Exchange.Kucoin); +var binanceResult3 = await unifiedBinanceClient3.GetTickerAsync(unifiedBinanceClient3.GetSymbolName(baseAsset3, quoteAsset3)); +var kucoinResult3 = await unifiedKucoinClient3.GetTickerAsync(unifiedKucoinClient3.GetSymbolName(baseAsset3, quoteAsset3)); ``` -For information on the specific exchange clients, dependency injection, response processing and more see the [CryptoExchange.Net documentation](https://jkorf.github.io/CryptoExchange.Net) or have a look at the examples [here](https://github.com/JKorf/CryptoClients.Net/tree/main/Examples). See the [CryptoExchange.Net examples](https://github.com/JKorf/CryptoExchange.Net/tree/master/Examples) for client examples which also apply to CryptoClients.Net +For information on the specific exchange clients, dependency injection, response processing and more see the [CryptoExchange.Net documentation](https://jkorf.github.io/CryptoExchange.Net) or have a look at the examples [here](https://github.com/JKorf/CryptoClients.Net/tree/main/Examples). See the [CryptoExchange.Net examples](https://github.com/JKorf/CryptoExchange.Net/tree/master/Examples) for client examples which also apply to CryptClients.Net ### Example -An API allowing the requesting of any ticker on any (supported) exchange in 14 lines; +An API allowing the requesting of any ticker on any (supported) exchange in 13 lines; For example `GET /Ticker/Kraken/ETH/BTC` or `GET /Ticker/Kucoin/BTC/USDT` ```csharp +using CryptoExchange.Net.Interfaces; +using CryptoClients.Net.Enums; using CryptoClients.Net.Interfaces; -using CryptoExchange.Net.SharedApis; -using CryptoExchange.Net.Objects; using Microsoft.AspNetCore.Mvc; var builder = WebApplication.CreateBuilder(args); builder.Services.AddCryptoClients(); var app = builder.Build(); -app.MapGet("Ticker/{exchange}/{baseAsset}/{quoteAsset}", async ([FromServices] IExchangeRestClient client, string exchange, string baseAsset, string quoteAsset) => +app.MapGet("Ticker/{exchange}/{baseAsset}/{quoteAsset}", async ([FromServices] IExchangeRestClient client, Exchange exchange, string baseAsset, string quoteAsset) => { - var spotClient = client.GetSpotTickerClient(exchange)!; - var result = await spotClient.GetSpotTickerAsync(new GetTickerRequest(new SharedSymbol(TradingMode.Spot, baseAsset, quoteAsset))); + var spotClient = client.GetUnifiedSpotClient(exchange)!; + var result = await spotClient.GetTickerAsync(spotClient.GetSymbolName(baseAsset, quoteAsset)); return result.Data; }); @@ -184,7 +171,7 @@ app.Run(); A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries. ## Support the project -Any support is greatly appreciated. +I develop and maintain this package on my own for free in my spare time, any support is greatly appreciated. ### 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.
@trade.Exchange@Math.Round(trade.Trade.Price, 2)@Math.Round(trade.Trade.Quantity, 8)@trade.Trade.Price@trade.Trade.Quantity