1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-07 16:06:15 +00:00
This commit is contained in:
Jkorf 2025-03-14 09:02:19 +01:00
parent 932cc4864e
commit f151b961a5
7 changed files with 51 additions and 19 deletions

View File

@ -63,7 +63,7 @@ namespace CryptoExchange.Net.UnitTests
public override TimeSpan? GetTimeOffset() => null; public override TimeSpan? GetTimeOffset() => null;
public override TimeSyncInfo GetTimeSyncInfo() => null; public override TimeSyncInfo GetTimeSyncInfo() => null;
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions()); 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 AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException(); protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();
} }

View File

@ -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()}"; 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 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<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class public async Task<CallResult<T>> Request<T>(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 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());
/// <inheritdoc /> /// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";

View File

@ -99,7 +99,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
} }
protected internal override IByteMessageAccessor CreateAccessor() => new SystemTextJsonByteMessageAccessor(new System.Text.Json.JsonSerializerOptions()); 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());
/// <inheritdoc /> /// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}"; public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";

View File

@ -32,6 +32,10 @@ namespace CryptoExchange.Net.Authentication
/// Get the API key of the current credentials /// Get the API key of the current credentials
/// </summary> /// </summary>
public string ApiKey => _credentials.Key!; public string ApiKey => _credentials.Key!;
/// <summary>
/// Get the Passphrase of the current credentials
/// </summary>
public string? Pass => _credentials.Pass;
/// <summary> /// <summary>
/// ctor /// ctor

View File

@ -65,22 +65,22 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
private bool _writeAsInt; private bool _writeAsInt;
private NullableEnumConverter? _nullableEnumConverter = null; private NullableEnumConverter? _nullableEnumConverter = null;
/// <summary> ///// <summary>
/// ctor ///// ctor
/// </summary> ///// </summary>
public EnumConverter() : this(false, true) //public EnumConverter() : this(false, true)
{ } //{ }
/// <summary> ///// <summary>
/// ctor ///// ctor
/// </summary> ///// </summary>
/// <param name="writeAsInt"></param> ///// <param name="writeAsInt"></param>
/// <param name="warnOnMissingEntry"></param> ///// <param name="warnOnMissingEntry"></param>
public EnumConverter(bool writeAsInt, bool warnOnMissingEntry) //public EnumConverter(bool writeAsInt, bool warnOnMissingEntry)
{ //{
_warnOnMissingEntry = warnOnMissingEntry; // _warnOnMissingEntry = warnOnMissingEntry;
_writeAsInt = writeAsInt; // _writeAsInt = writeAsInt;
} //}
internal class NullableEnumConverter : JsonConverter<T?> internal class NullableEnumConverter : JsonConverter<T?>
{ {

View File

@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CryptoExchange.Net.Converters.SystemTextJson
{
/// <summary>
/// Converter for serializing enum values as int
/// </summary>
public class EnumIntWriterConverter<T> : JsonConverter<T> where T: struct, Enum
{
/// <inheritdoc />
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
=> writer.WriteNumberValue((int)(object)value);
}
}

View File

@ -411,6 +411,11 @@ namespace CryptoExchange.Net.Testing.Comparers
if (dec != value) if (dec != value)
throw new Exception($"{method}: {property} not equal: {dec} vs {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)) else if (value != Convert.ToInt64(objectValue, CultureInfo.InvariantCulture))
{ {
throw new Exception($"{method}: {property} not equal: {value} vs {Convert.ToInt64(objectValue)}"); throw new Exception($"{method}: {property} not equal: {value} vs {Convert.ToInt64(objectValue)}");