1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 17:06:19 +00:00

Updated IExchangeClient interface, added HandleUnhandledMessage virtual method in SocketClient

This commit is contained in:
Jkorf 2020-12-21 14:11:36 +01:00
parent 7a54625bb5
commit 31842b415d
5 changed files with 253 additions and 6 deletions

View File

@ -441,6 +441,26 @@
<member name="M:CryptoExchange.Net.Converters.UTCDateTimeConverter.CanConvert(System.Type)">
<inheritdoc />
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonBalance">
<summary>
Common balance
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonBalance.CommonAsset">
<summary>
The asset name
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonBalance.CommonAvailable">
<summary>
Amount available
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonBalance.CommonTotal">
<summary>
Total amount
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade">
<summary>
Common trade
@ -496,12 +516,22 @@
</summary>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetKlinesAsync(System.String,System.TimeSpan)">
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetTickerAsync(System.String)">
<summary>
Get a ticker for the exchange
</summary>
<param name="symbol">The symbol to get klines for</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetKlinesAsync(System.String,System.TimeSpan,System.Nullable{System.DateTime},System.Nullable{System.DateTime},System.Nullable{System.Int32})">
<summary>
Get a list of candles for a given symbol on the exchange
</summary>
<param name="symbol">The symbol to retrieve the candles for</param>
<param name="timespan">The timespan to retrieve the candles for. The supported value are dependent on the exchange</param>
<param name="startTime">[Optional] Start time to retrieve klines for</param>
<param name="endTime">[Optional] End time to retrieve klines for</param>
<param name="limit">[Optional] Max number of results</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetOrderBookAsync(System.String)">
@ -568,6 +598,13 @@
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetBalancesAsync(System.String)">
<summary>
Get balances
</summary>
<param name="accountId">[Optional] The account id to retrieve balances for, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderType">
<summary>
Common order id
@ -2948,6 +2985,12 @@
<param name="authenticated">Whether the socket should be authenticated</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.SocketClient.HandleUnhandledMessage(Newtonsoft.Json.Linq.JToken)">
<summary>
Process an unhandled message
</summary>
<param name="token">The token that wasn't processed</param>
</member>
<member name="M:CryptoExchange.Net.SocketClient.ConnectSocket(CryptoExchange.Net.Sockets.SocketConnection)">
<summary>
Connect a socket
@ -3203,6 +3246,11 @@
Connecting closed event
</summary>
</member>
<member name="E:CryptoExchange.Net.Sockets.SocketConnection.UnhandledMessage">
<summary>
Unhandled message event
</summary>
</member>
<member name="P:CryptoExchange.Net.Sockets.SocketConnection.HandlerCount">
<summary>
The amount of handlers
@ -3417,5 +3465,148 @@
<member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})">
<inheritdoc />
</member>
<member name="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute">
<summary>
Specifies that <see langword="null"/> is allowed as an input even if the
corresponding type disallows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.AllowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute">
<summary>
Specifies that <see langword="null"/> is disallowed as an input even if the
corresponding type allows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DisallowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute">
<summary>
Specifies that a method that will never return under any circumstance.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
<summary>
Specifies that the method will not return if the associated <see cref="T:System.Boolean"/>
parameter is passed the specified value.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.ParameterValue">
<summary>
Gets the condition parameter value.
Code after the method is considered unreachable by diagnostics if the argument
to the associated parameter matches this value.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.#ctor(System.Boolean)">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute"/>
class with the specified parameter value.
</summary>
<param name="parameterValue">
The condition parameter value.
Code after the method is considered unreachable by diagnostics if the argument
to the associated parameter matches this value.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute">
<summary>
Specifies that an output may be <see langword="null"/> even if the
corresponding type disallows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.MaybeNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute">
<summary>
Specifies that when a method returns <see cref="P:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.ReturnValue"/>,
the parameter may be <see langword="null"/> even if the corresponding type disallows it.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.ReturnValue">
<summary>
Gets the return value condition.
If the method returns this value, the associated parameter may be <see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.#ctor(System.Boolean)">
<summary>
Initializes the attribute with the specified return value condition.
</summary>
<param name="returnValue">
The return value condition.
If the method returns this value, the associated parameter may be <see langword="null"/>.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullAttribute">
<summary>
Specifies that an output is not <see langword="null"/> even if the
corresponding type allows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.NotNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute">
<summary>
Specifies that the output will be non-<see langword="null"/> if the
named parameter is non-<see langword="null"/>.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.ParameterName">
<summary>
Gets the associated parameter name.
The output will be non-<see langword="null"/> if the argument to the
parameter specified is non-<see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.#ctor(System.String)">
<summary>
Initializes the attribute with the associated parameter name.
</summary>
<param name="parameterName">
The associated parameter name.
The output will be non-<see langword="null"/> if the argument to the
parameter specified is non-<see langword="null"/>.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute">
<summary>
Specifies that when a method returns <see cref="P:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.ReturnValue"/>,
the parameter will not be <see langword="null"/> even if the corresponding type allows it.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.ReturnValue">
<summary>
Gets the return value condition.
If the method returns this value, the associated parameter will not be <see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.#ctor(System.Boolean)">
<summary>
Initializes the attribute with the specified return value condition.
</summary>
<param name="returnValue">
The return value condition.
If the method returns this value, the associated parameter will not be <see langword="null"/>.
</param>
</member>
</members>
</doc>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.ExchangeInterfaces
{
/// <summary>
/// Common balance
/// </summary>
public interface ICommonBalance
{
/// <summary>
/// The asset name
/// </summary>
public string CommonAsset { get; }
/// <summary>
/// Amount available
/// </summary>
public decimal CommonAvailable { get; }
/// <summary>
/// Total amount
/// </summary>
public decimal CommonTotal { get; }
}
}

View File

@ -30,13 +30,23 @@ namespace CryptoExchange.Net.ExchangeInterfaces
/// <returns></returns>
Task<WebCallResult<IEnumerable<ICommonTicker>>> GetTickersAsync();
/// <summary>
/// Get a ticker for the exchange
/// </summary>
/// <param name="symbol">The symbol to get klines for</param>
/// <returns></returns>
Task<WebCallResult<ICommonTicker>> GetTickerAsync(string symbol);
/// <summary>
/// Get a list of candles for a given symbol on the exchange
/// </summary>
/// <param name="symbol">The symbol to retrieve the candles for</param>
/// <param name="timespan">The timespan to retrieve the candles for. The supported value are dependent on the exchange</param>
/// <param name="startTime">[Optional] Start time to retrieve klines for</param>
/// <param name="endTime">[Optional] End time to retrieve klines for</param>
/// <param name="limit">[Optional] Max number of results</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<ICommonKline>>> GetKlinesAsync(string symbol, TimeSpan timespan);
Task<WebCallResult<IEnumerable<ICommonKline>>> GetKlinesAsync(string symbol, TimeSpan timespan, DateTime? startTime = null, DateTime? endTime = null, int? limit = null);
/// <summary>
/// Get the order book for a symbol
/// </summary>
@ -80,21 +90,28 @@ namespace CryptoExchange.Net.ExchangeInterfaces
/// </summary>
/// <param name="symbol">[Optional] The symbol to get open orders for, required for some exchanges, ignored otherwise</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<ICommonOrder>>> GetOpenOrdersAsync(string? symbol);
Task<WebCallResult<IEnumerable<ICommonOrder>>> GetOpenOrdersAsync(string? symbol = null);
/// <summary>
/// Get a list of closed orders
/// </summary>
/// <param name="symbol">[Optional] The symbol to get closed orders for, required for some exchanges, ignored otherwise</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<ICommonOrder>>> GetClosedOrdersAsync(string? symbol);
Task<WebCallResult<IEnumerable<ICommonOrder>>> GetClosedOrdersAsync(string? symbol = null);
/// <summary>
/// Cancel an order by id
/// </summary>
/// <param name="orderId">The id</param>
/// <param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
/// <returns></returns>
Task<WebCallResult<ICommonOrderId>> CancelOrderAsync(string orderId, string? symbol);
Task<WebCallResult<ICommonOrderId>> CancelOrderAsync(string orderId, string? symbol = null);
/// <summary>
/// Get balances
/// </summary>
/// <param name="accountId">[Optional] The account id to retrieve balances for, required for some exchanges, ignored otherwise</param>
/// <returns></returns>
Task<WebCallResult<IEnumerable<ICommonBalance>>> GetBalancesAsync(string? accountId = null);
/// <summary>
/// Common order id

View File

@ -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;
}
/// <summary>
/// Process an unhandled message
/// </summary>
/// <param name="token">The token that wasn't processed</param>
protected virtual void HandleUnhandledMessage(JToken token)
{
}
/// <summary>
/// Connect a socket
/// </summary>

View File

@ -36,6 +36,10 @@ namespace CryptoExchange.Net.Sockets
/// Connecting closed event
/// </summary>
public event Action? Closed;
/// <summary>
/// Unhandled message event
/// </summary>
public event Action<JToken>? UnhandledMessage;
/// <summary>
/// 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);
}
}