From 31842b415d7a97a6b31dbc5417385a0419cadc5f Mon Sep 17 00:00:00 2001 From: Jkorf Date: Mon, 21 Dec 2020 14:11:36 +0100 Subject: [PATCH] Updated IExchangeClient interface, added HandleUnhandledMessage virtual method in SocketClient --- CryptoExchange.Net/CryptoExchange.Net.xml | 193 +++++++++++++++++- .../ExchangeInterfaces/ICommonBalance.cs | 25 +++ .../ExchangeInterfaces/IExchangeClient.cs | 25 ++- CryptoExchange.Net/SocketClient.cs | 9 + .../Sockets/SocketConnection.cs | 7 +- 5 files changed, 253 insertions(+), 6 deletions(-) create mode 100644 CryptoExchange.Net/ExchangeInterfaces/ICommonBalance.cs diff --git a/CryptoExchange.Net/CryptoExchange.Net.xml b/CryptoExchange.Net/CryptoExchange.Net.xml index 4e8ba34..8f991a3 100644 --- a/CryptoExchange.Net/CryptoExchange.Net.xml +++ b/CryptoExchange.Net/CryptoExchange.Net.xml @@ -441,6 +441,26 @@ + + + Common balance + + + + + The asset name + + + + + Amount available + + + + + Total amount + + Common trade @@ -496,12 +516,22 @@ - + + + Get a ticker for the exchange + + The symbol to get klines for + + + Get a list of candles for a given symbol on the exchange The symbol to retrieve the candles for The timespan to retrieve the candles for. The supported value are dependent on the exchange + [Optional] Start time to retrieve klines for + [Optional] End time to retrieve klines for + [Optional] Max number of results @@ -568,6 +598,13 @@ [Optional] The symbol the order is on, required for some exchanges, ignored otherwise + + + Get balances + + [Optional] The account id to retrieve balances for, required for some exchanges, ignored otherwise + + Common order id @@ -2948,6 +2985,12 @@ Whether the socket should be authenticated + + + Process an unhandled message + + The token that wasn't processed + Connect a socket @@ -3203,6 +3246,11 @@ Connecting closed event + + + Unhandled message event + + The amount of handlers @@ -3417,5 +3465,148 @@ + + + Specifies that is allowed as an input even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that is disallowed as an input even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that a method that will never return under any circumstance. + + + + + Initializes a new instance of the class. + + + + + Specifies that the method will not return if the associated + parameter is passed the specified value. + + + + + Gets the condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Initializes a new instance of the + class with the specified parameter value. + + + The condition parameter value. + Code after the method is considered unreachable by diagnostics if the argument + to the associated parameter matches this value. + + + + + Specifies that an output may be even if the + corresponding type disallows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that when a method returns , + the parameter may be even if the corresponding type disallows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter may be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter may be . + + + + + Specifies that an output is not even if the + corresponding type allows it. + + + + + Initializes a new instance of the class. + + + + + Specifies that the output will be non- if the + named parameter is non-. + + + + + Gets the associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Initializes the attribute with the associated parameter name. + + + The associated parameter name. + The output will be non- if the argument to the + parameter specified is non-. + + + + + Specifies that when a method returns , + the parameter will not be even if the corresponding type allows it. + + + + + Gets the return value condition. + If the method returns this value, the associated parameter will not be . + + + + + Initializes the attribute with the specified return value condition. + + + The return value condition. + If the method returns this value, the associated parameter will not be . + + diff --git a/CryptoExchange.Net/ExchangeInterfaces/ICommonBalance.cs b/CryptoExchange.Net/ExchangeInterfaces/ICommonBalance.cs new file mode 100644 index 0000000..abf6ab4 --- /dev/null +++ b/CryptoExchange.Net/ExchangeInterfaces/ICommonBalance.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CryptoExchange.Net.ExchangeInterfaces +{ + /// + /// Common balance + /// + public interface ICommonBalance + { + /// + /// The asset name + /// + public string CommonAsset { get; } + /// + /// Amount available + /// + public decimal CommonAvailable { get; } + /// + /// Total amount + /// + public decimal CommonTotal { get; } + } +} diff --git a/CryptoExchange.Net/ExchangeInterfaces/IExchangeClient.cs b/CryptoExchange.Net/ExchangeInterfaces/IExchangeClient.cs index 145f069..041f4ea 100644 --- a/CryptoExchange.Net/ExchangeInterfaces/IExchangeClient.cs +++ b/CryptoExchange.Net/ExchangeInterfaces/IExchangeClient.cs @@ -30,13 +30,23 @@ namespace CryptoExchange.Net.ExchangeInterfaces /// Task>> GetTickersAsync(); + /// + /// Get a ticker for the exchange + /// + /// The symbol to get klines for + /// + Task> GetTickerAsync(string symbol); + /// /// Get a list of candles for a given symbol on the exchange /// /// The symbol to retrieve the candles for /// The timespan to retrieve the candles for. The supported value are dependent on the exchange + /// [Optional] Start time to retrieve klines for + /// [Optional] End time to retrieve klines for + /// [Optional] Max number of results /// - Task>> GetKlinesAsync(string symbol, TimeSpan timespan); + Task>> GetKlinesAsync(string symbol, TimeSpan timespan, DateTime? startTime = null, DateTime? endTime = null, int? limit = null); /// /// Get the order book for a symbol /// @@ -80,21 +90,28 @@ namespace CryptoExchange.Net.ExchangeInterfaces /// /// [Optional] The symbol to get open orders for, required for some exchanges, ignored otherwise /// - Task>> GetOpenOrdersAsync(string? symbol); + Task>> GetOpenOrdersAsync(string? symbol = null); /// /// Get a list of closed orders /// /// [Optional] The symbol to get closed orders for, required for some exchanges, ignored otherwise /// - Task>> GetClosedOrdersAsync(string? symbol); + Task>> GetClosedOrdersAsync(string? symbol = null); /// /// Cancel an order by id /// /// The id /// [Optional] The symbol the order is on, required for some exchanges, ignored otherwise /// - Task> CancelOrderAsync(string orderId, string? symbol); + Task> CancelOrderAsync(string orderId, string? symbol = null); + + /// + /// Get balances + /// + /// [Optional] The account id to retrieve balances for, required for some exchanges, ignored otherwise + /// + Task>> GetBalancesAsync(string? accountId = null); /// /// Common order id diff --git a/CryptoExchange.Net/SocketClient.cs b/CryptoExchange.Net/SocketClient.cs index 0332595..b766eb8 100644 --- a/CryptoExchange.Net/SocketClient.cs +++ b/CryptoExchange.Net/SocketClient.cs @@ -443,6 +443,7 @@ namespace CryptoExchange.Net // Create new socket var socket = CreateSocket(address); var socketWrapper = new SocketConnection(this, socket); + socketWrapper.UnhandledMessage += HandleUnhandledMessage; foreach (var kvp in genericHandlers) { var handler = SocketSubscription.CreateForIdentifier(kvp.Key, false, kvp.Value); @@ -452,6 +453,14 @@ namespace CryptoExchange.Net return socketWrapper; } + /// + /// Process an unhandled message + /// + /// The token that wasn't processed + protected virtual void HandleUnhandledMessage(JToken token) + { + } + /// /// Connect a socket /// diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 5d30915..7145eb0 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -36,6 +36,10 @@ namespace CryptoExchange.Net.Sockets /// Connecting closed event /// public event Action? Closed; + /// + /// Unhandled message event + /// + public event Action? UnhandledMessage; /// /// The amount of handlers @@ -162,7 +166,8 @@ namespace CryptoExchange.Net.Sockets if (!HandleData(tokenData) && !handledResponse) { - log.Write(LogVerbosity.Debug, "Message not handled: " + tokenData); + log.Write(LogVerbosity.Warning, "Message not handled: " + tokenData); + UnhandledMessage?.Invoke(tokenData); } }