mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-18 03:43:00 +00:00
e823114623
* Result types: * (Web)CallResult types are replaced by HttpResult, WebSocketResult and QueryResult with the same logic * Updated result types to record type * Result creation can be done with (Http/WebSocket/Query)Result.Ok(..) and .Fail(..) * Removed implicit result type conversion to bool, `if (result)` no longer works, instead use `if (result.Success)` * Replaced CallResult.SuccessResult with CallResult.Ok() * Fixed result object nullability hinting, for example Data might be null if Success isn't checked for true * Parameters & serialization: * Added support for `enabled` and `disabled` strings to bool converter * Removed ParameterCollection type, has been replaced by Parameters type * Removed ArraySerialization, OrderParameters and ParameterOrderComparer properties from RestApiClient, moved to ParameterSerializationsSettings * Updated RestRequestConfiguration in AuthenticationProvider.ProcessRequest to contain the full RequestDefinition instead of copied fields * Clients: * Updated Api client constructor logging parameter from ILogger to ILoggerFactory? * Added Api client constructor exchange name parameter * Added ToString overrides on base API types * Added Exchange property on BaseApiClient * Added ApiCredentials property on IRestApiClient and ISocketApiClient interfaces * Updated ILogger source from client name to topic specific client name * Removed logging from client creation * Fixed BaseRestClient SetApiCredentials not marked as virtual * Rest: * Added BaseAddress to RequestDefinition object * Updated RestApiClient AuthenticationProvider logic from private to protected and virtual * Removed RestApiClient.SendAsync baseAddress parameter removed * Removed RestApiClient.SendAsync without type parameter * WebSocket: * Updated MessageRouting definition into CreateForEvent for subscriptions and CreateForQuery for queries * Improved Query type safety with CeateForQuery which allows second parameter for specifying the result type * Renamed MessageRouter.CreateWithoutHandler to CreateVoid * Updated SocketApiClient.GetSocketConnection to check connection uri instead of Tag for finding compatible connections * Removed unused UnhandledMessageExpected property SocketApiClient * Fixed issue in SocketApiClient.GetSocketConnection causing requests to always wait the full max 10 seconds when there was a reconnecting socket * Shared APIs: * Updated Option definitions to always require the exchange name as first parameter * Added missing dedicated option types * Added Discover method on ISharedClient interface, returning info on supported capabilities and operations * Added SharedRequest GetParamValue helper method accepting multiple parameter names * Added ResetStaticExchangeParameters method on ExchangeParameters * Added Status property to SharedWithdrawal model * Added TradingModes property to SharedBalance model * Updated ExchangeSymbolCache to support multiple environments and additional key separation * Updated Shared ExchangeParameters parameter names to be case insensitive * Updated code comments * Replaced ExchangeResult with ExchangeCallResult type * Removed AsExchangeResult/ExchangeWebResult * Removed TradingMode from the response model, only maintained on models where it makes sense * Removed IListenKey support, listen keys now rely on internal management with TokenManager * Rate limiting: * Fixed websocket connection attempts counting towards rate limit even when server could not be reached * Removed host from rate limit methods, now part of the already provided RequestDefinition * Added amount parameter to RateLimit Reset method to allow partially resetting the limit * Added TokenManager implementation for automatic listenkey/token management * Added UserClientProvider base class * Added async streaming on UserDataTracker items with StreamUpdatesAsync * Added cancellation token support to UserDataTracker starting * Added Unit type for non-result types * Added ServerError constructor taking ErrorType and message to make it easier to create * Added SupportedEnvironments property to PlatformInfo * Updated SymbolOrderBook DoResyncAsync to return CallResult instead of CallResult<bool> which was redundant * Various small performance improvements
117 lines
4.1 KiB
C#
117 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text;
|
|
|
|
namespace CryptoExchange.Net.Objects;
|
|
|
|
/// <summary>
|
|
/// Call result
|
|
/// </summary>
|
|
public record CallResult : ICallResult
|
|
{
|
|
private static CallResult _successResult = new CallResult();
|
|
|
|
/// <inheritdoc />
|
|
public Error? Error { get; init; }
|
|
/// <inheritdoc />
|
|
[MemberNotNullWhen(false, nameof(Error))]
|
|
public bool Success => Error == null;
|
|
|
|
/// <summary>
|
|
/// Create an error response
|
|
/// </summary>
|
|
/// <param name="error">The error</param>
|
|
public static CallResult Fail(Error error) => new CallResult { Error = error };
|
|
/// <summary>
|
|
/// Create a success result
|
|
/// </summary>
|
|
public static CallResult Ok() => _successResult;
|
|
/// <summary>
|
|
/// Create a success result
|
|
/// </summary>
|
|
/// <typeparam name="T">Result type</typeparam>
|
|
/// <param name="originalData">The original string data</param>
|
|
/// <param name="data">Data type</param>
|
|
public static CallResult<T> Ok<T>(T data, string? originalData = null) => new CallResult<T> { Data = data, OriginalData = originalData };
|
|
/// <summary>
|
|
/// Create an error response
|
|
/// </summary>
|
|
/// <typeparam name="T">Result type</typeparam>
|
|
/// <param name="originalData">The original string data</param>
|
|
/// <param name="error">The error</param>
|
|
public static CallResult<T> Fail<T>(Error error, string? originalData = null) => new CallResult<T> { Error = error, OriginalData = originalData };
|
|
|
|
/// <inheritdoc />
|
|
public override string ToString()
|
|
{
|
|
return Success ? $"Success" : $"Error: {Error}";
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
public record CallResult<T> : CallResult, ICallResult<T>
|
|
{
|
|
/// <inheritdoc />
|
|
public new Error? Error
|
|
{
|
|
get => base.Error;
|
|
init => base.Error = value;
|
|
}
|
|
/// <inheritdoc />
|
|
[MemberNotNullWhen(false, nameof(Error))]
|
|
[MemberNotNullWhen(true, nameof(Data))]
|
|
public new bool Success => Error == null;
|
|
|
|
/// <summary>
|
|
/// The data returned by the call, only available when Success = true
|
|
/// </summary>
|
|
public T? Data { get; init; }
|
|
|
|
/// <summary>
|
|
/// The original data returned by the call, only available when `OutputOriginalData` is set to `true` in the client options
|
|
/// </summary>
|
|
public string? OriginalData { get; init; }
|
|
|
|
/// <summary>
|
|
/// Create an error response
|
|
/// </summary>
|
|
/// <param name="error">The error</param>
|
|
/// <param name="originalData">The original string data</param>
|
|
public static CallResult<T> Fail(Error error, string? originalData = null) => new CallResult<T> { Error = error, OriginalData = originalData };
|
|
/// <summary>
|
|
/// Create a success result
|
|
/// </summary>
|
|
/// <param name="data">The data</param>
|
|
/// <param name="originalData">The original string data</param>
|
|
/// <returns></returns>
|
|
public static CallResult<T> Ok(T data, string? originalData = null) => new CallResult<T> { Data = data, OriginalData = originalData };
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call result for an exchange
|
|
/// </summary>
|
|
/// <typeparam name="T">Data type</typeparam>
|
|
public record ExchangeCallResult<T> : CallResult<T>
|
|
{
|
|
/// <summary>
|
|
/// Exchange name
|
|
/// </summary>
|
|
public string Exchange { get; set; } = string.Empty;
|
|
/// <summary>
|
|
/// Create an error response
|
|
/// </summary>
|
|
/// <param name="exchange">The exchange name</param>
|
|
/// <param name="error">The error</param>
|
|
/// <param name="originalData">The original string data</param>
|
|
public static ExchangeCallResult<T> Fail(string exchange, Error error, string? originalData = null) => new ExchangeCallResult<T> { Exchange = exchange, Error = error };
|
|
/// <summary>
|
|
/// Create a success result
|
|
/// </summary>
|
|
/// <param name="exchange">The exchange name</param>
|
|
/// <param name="data">The data</param>
|
|
/// <param name="originalData">The original string data</param>
|
|
/// <returns></returns>
|
|
public static ExchangeCallResult<T> Ok(string exchange, T data, string? originalData = null) => new ExchangeCallResult<T> { Exchange = exchange, Data = data };
|
|
} |