From f151b961a5399f5934e6b0ffaafec9c1500fb39b Mon Sep 17 00:00:00 2001 From: Jkorf Date: Fri, 14 Mar 2025 09:02:19 +0100 Subject: [PATCH] wip --- .../TestImplementations/TestBaseClient.cs | 2 +- .../TestImplementations/TestRestClient.cs | 4 +-- .../TestImplementations/TestSocketClient.cs | 2 +- .../Authentication/AuthenticationProvider.cs | 4 +++ .../SystemTextJson/EnumConverter.cs | 30 +++++++++---------- .../SystemTextJson/EnumIntWriterConverter.cs | 23 ++++++++++++++ .../Comparers/SystemTextJsonComparer.cs | 5 ++++ 7 files changed, 51 insertions(+), 19 deletions(-) create mode 100644 CryptoExchange.Net/Converters/SystemTextJson/EnumIntWriterConverter.cs diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs index e21317a..f9e3bd5 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestBaseClient.cs @@ -63,7 +63,7 @@ namespace CryptoExchange.Net.UnitTests public override TimeSpan? GetTimeOffset() => null; public override TimeSyncInfo GetTimeSyncInfo() => null; protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions()); - protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new TestSerializerContext()); + protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException(); protected override Task> GetServerTimestampAsync() => throw new NotImplementedException(); } diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs index d4f5da1..b2e16bd 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestRestClient.cs @@ -139,7 +139,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions() { TypeInfoResolver = new TestSerializerContext() }); - protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new TestSerializerContext()); + protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); public async Task> Request(CancellationToken ct = default) where T : class { @@ -183,7 +183,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations } protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions()); - protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new TestSerializerContext()); + protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); /// public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; diff --git a/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs b/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs index 55f51e2..11080ec 100644 --- a/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs +++ b/CryptoExchange.Net.UnitTests/TestImplementations/TestSocketClient.cs @@ -99,7 +99,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations } protected internal override IByteMessageAccessor CreateAccessor() => new SystemTextJsonByteMessageAccessor(new System.Text.Json.JsonSerializerOptions()); - protected internal override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new TestSerializerContext()); + protected internal override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions()); /// public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs index 6920e98..ede3cf0 100644 --- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs +++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs @@ -32,6 +32,10 @@ namespace CryptoExchange.Net.Authentication /// Get the API key of the current credentials /// public string ApiKey => _credentials.Key!; + /// + /// Get the Passphrase of the current credentials + /// + public string? Pass => _credentials.Pass; /// /// ctor diff --git a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs index d543d5d..bad0d4d 100644 --- a/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs +++ b/CryptoExchange.Net/Converters/SystemTextJson/EnumConverter.cs @@ -65,22 +65,22 @@ namespace CryptoExchange.Net.Converters.SystemTextJson private bool _writeAsInt; private NullableEnumConverter? _nullableEnumConverter = null; - /// - /// ctor - /// - public EnumConverter() : this(false, true) - { } + ///// + ///// ctor + ///// + //public EnumConverter() : this(false, true) + //{ } - /// - /// ctor - /// - /// - /// - public EnumConverter(bool writeAsInt, bool warnOnMissingEntry) - { - _warnOnMissingEntry = warnOnMissingEntry; - _writeAsInt = writeAsInt; - } + ///// + ///// ctor + ///// + ///// + ///// + //public EnumConverter(bool writeAsInt, bool warnOnMissingEntry) + //{ + // _warnOnMissingEntry = warnOnMissingEntry; + // _writeAsInt = writeAsInt; + //} internal class NullableEnumConverter : JsonConverter { diff --git a/CryptoExchange.Net/Converters/SystemTextJson/EnumIntWriterConverter.cs b/CryptoExchange.Net/Converters/SystemTextJson/EnumIntWriterConverter.cs new file mode 100644 index 0000000..9a0c9a7 --- /dev/null +++ b/CryptoExchange.Net/Converters/SystemTextJson/EnumIntWriterConverter.cs @@ -0,0 +1,23 @@ +using System; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace CryptoExchange.Net.Converters.SystemTextJson +{ + /// + /// Converter for serializing enum values as int + /// + public class EnumIntWriterConverter : JsonConverter where T: struct, Enum + { + /// + public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + throw new NotImplementedException(); + } + + /// + public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + => writer.WriteNumberValue((int)(object)value); + } +} diff --git a/CryptoExchange.Net/Testing/Comparers/SystemTextJsonComparer.cs b/CryptoExchange.Net/Testing/Comparers/SystemTextJsonComparer.cs index 12b3695..89c0d67 100644 --- a/CryptoExchange.Net/Testing/Comparers/SystemTextJsonComparer.cs +++ b/CryptoExchange.Net/Testing/Comparers/SystemTextJsonComparer.cs @@ -411,6 +411,11 @@ namespace CryptoExchange.Net.Testing.Comparers if (dec != value) throw new Exception($"{method}: {property} not equal: {dec} vs {value}"); } + else if(objectValue is string objStr) + { + if (objStr != value.ToString()) + throw new Exception($"{method}: {property} not equal: {value} vs {objStr}"); + } else if (value != Convert.ToInt64(objectValue, CultureInfo.InvariantCulture)) { throw new Exception($"{method}: {property} not equal: {value} vs {Convert.ToInt64(objectValue)}");