mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-04-07 02:01:12 +00:00
Updated API credential logic, exchange implementation are expected to provide their own credentials implementation with ApiCredentials as base class Removed ApiCredentials implementation used by most exchanges Removed ApiCredentialsType Enum Added CredentialSet base class and implementations for defining different API credentials Added optional type param to AuthenticationProvider for the specific API credential type to improve type safety Moved AuthenticationProvider/ApiCredentials from BaseApiClient to RestApiClient/SocketApiClient base classes Added optional type params to RestApiClient/SocketApiClient base class to specify the AuthenticationProvider type and credentials type to improve type safety Moved SetOptions/SetApiCredentials from BaseApiClient to RestApiClient/SocketApiClient Extracted LibraryOptions<TRestOptions, TSocketOptions, TEnvironment> without TApiCredentials for libraries without API credentials Removed ApiCredentials from ApiOptions, credentials can only be configured at library, rest or socket level Added EnvironmentName to RestApiClient/SocketApiClient property Added Unknown enum value to Shared interfaces SharedOrderStatus, SharedTransferStatus and SharedTriggerOrderStatus enums Updated Enum converter to map value to an undefined Enum value instead of the first Enum value Added support for checking for missing fields on RestIntegrationTest Added BytesToHexString and HexToBytesString to ExchangeHelpers static class Fixed bug where WebSocket connections are not reconnected when configuring Proxy with SetUpdates Removed legacy CryptoBaseClient, CryptoRestClient and CryptoSocketClient
59 lines
2.3 KiB
C#
59 lines
2.3 KiB
C#
using CryptoExchange.Net.SharedApis;
|
|
using System;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace CryptoExchange.Net.Converters.SystemTextJson
|
|
{
|
|
internal class SharedQuantityConverter : SharedQuantityReferenceConverter<SharedQuantity> { }
|
|
internal class SharedOrderQuantityConverter : SharedQuantityReferenceConverter<SharedOrderQuantity> { }
|
|
|
|
internal class SharedQuantityReferenceConverter<T> : JsonConverter<T> where T: SharedQuantityReference, new()
|
|
{
|
|
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
|
{
|
|
if (reader.TokenType != JsonTokenType.StartArray)
|
|
throw new Exception("Invalid JSON structure");
|
|
|
|
reader.Read(); // Start array
|
|
var baseQuantity = reader.TokenType == JsonTokenType.Null ? (decimal?)null : reader.GetDecimal();
|
|
reader.Read();
|
|
var quoteQuantity = reader.TokenType == JsonTokenType.Null ? (decimal?)null : reader.GetDecimal();
|
|
reader.Read();
|
|
var contractQuantity = reader.TokenType == JsonTokenType.Null ? (decimal?)null : reader.GetDecimal();
|
|
reader.Read();
|
|
|
|
if (reader.TokenType != JsonTokenType.EndArray)
|
|
throw new Exception("Invalid JSON structure");
|
|
|
|
reader.Read(); // End array
|
|
|
|
var result = new T();
|
|
result.QuantityInBaseAsset = baseQuantity;
|
|
result.QuantityInQuoteAsset = quoteQuantity;
|
|
result.QuantityInContracts = contractQuantity;
|
|
return result;
|
|
}
|
|
|
|
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
|
{
|
|
writer.WriteStartArray();
|
|
if (value.QuantityInBaseAsset == null)
|
|
writer.WriteNullValue();
|
|
else
|
|
writer.WriteNumberValue(value.QuantityInBaseAsset.Value);
|
|
|
|
if (value.QuantityInQuoteAsset == null)
|
|
writer.WriteNullValue();
|
|
else
|
|
writer.WriteNumberValue(value.QuantityInQuoteAsset.Value);
|
|
|
|
if (value.QuantityInContracts == null)
|
|
writer.WriteNullValue();
|
|
else
|
|
writer.WriteNumberValue(value.QuantityInContracts.Value);
|
|
writer.WriteEndArray();
|
|
}
|
|
}
|
|
}
|