1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-12 17:03:10 +00:00

Compare commits

...

7 Commits

8 changed files with 35 additions and 13 deletions
@@ -87,8 +87,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
if (prop.JsonConverterType == null && IsSimple(prop.PropertyInfo.PropertyType)) if (prop.JsonConverterType == null && IsSimple(prop.PropertyInfo.PropertyType))
{ {
if (prop.PropertyInfo.PropertyType == typeof(string)) if (prop.TargetType == typeof(string))
writer.WriteStringValue(Convert.ToString(objValue, CultureInfo.InvariantCulture)); writer.WriteStringValue(Convert.ToString(objValue, CultureInfo.InvariantCulture));
else if(prop.TargetType.IsEnum)
writer.WriteStringValue(EnumConverter.GetString(objValue));
else if (prop.TargetType == typeof(bool))
writer.WriteBooleanValue((bool)objValue);
else else
writer.WriteRawValue(Convert.ToString(objValue, CultureInfo.InvariantCulture)!); writer.WriteRawValue(Convert.ToString(objValue, CultureInfo.InvariantCulture)!);
} }
@@ -187,12 +191,12 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
_converterOptionsCache.TryAdd(attribute.JsonConverterType, newOptions); _converterOptionsCache.TryAdd(attribute.JsonConverterType, newOptions);
} }
value = JsonDocument.ParseValue(ref reader).Deserialize(targetType, newOptions); value = JsonDocument.ParseValue(ref reader).Deserialize(attribute.PropertyInfo.PropertyType, newOptions);
} }
else if (attribute.DefaultDeserialization) else if (attribute.DefaultDeserialization)
{ {
// Use default deserialization // Use default deserialization
value = JsonDocument.ParseValue(ref reader).Deserialize(targetType, options); value = JsonDocument.ParseValue(ref reader).Deserialize(attribute.PropertyInfo.PropertyType, SerializerOptions.WithConverters);
} }
else else
{ {
@@ -47,7 +47,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
if (reader.TokenType is JsonTokenType.Number) if (reader.TokenType is JsonTokenType.Number)
{ {
var longValue = reader.GetDouble(); var longValue = reader.GetDouble();
if (longValue == 0 || longValue == -1) if (longValue == 0 || longValue < 0)
return default; return default;
return ParseFromDouble(longValue); return ParseFromDouble(longValue);
@@ -172,6 +172,13 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
return true; return true;
} }
if (objectType.IsDefined(typeof(FlagsAttribute)))
{
var intValue = int.Parse(value);
result = Enum.ToObject(objectType, intValue);
return true;
}
try try
{ {
// If no explicit mapping is found try to parse string // If no explicit mapping is found try to parse string
+3 -3
View File
@@ -6,9 +6,9 @@
<PackageId>CryptoExchange.Net</PackageId> <PackageId>CryptoExchange.Net</PackageId>
<Authors>JKorf</Authors> <Authors>JKorf</Authors>
<Description>CryptoExchange.Net is a base library which is used to implement different cryptocurrency (exchange) API's. It provides a standardized way of implementing different API's, which results in a very similar experience for users of the API implementations.</Description> <Description>CryptoExchange.Net is a base library which is used to implement different cryptocurrency (exchange) API's. It provides a standardized way of implementing different API's, which results in a very similar experience for users of the API implementations.</Description>
<PackageVersion>8.7.1</PackageVersion> <PackageVersion>8.7.3</PackageVersion>
<AssemblyVersion>8.7.1</AssemblyVersion> <AssemblyVersion>8.7.3</AssemblyVersion>
<FileVersion>8.7.1</FileVersion> <FileVersion>8.7.3</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageTags>OKX;OKX.Net;Mexc;Mexc.Net;Kucoin;Kucoin.Net;Kraken;Kraken.Net;Huobi;Huobi.Net;CoinEx;CoinEx.Net;Bybit;Bybit.Net;Bitget;Bitget.Net;Bitfinex;Bitfinex.Net;Binance;Binance.Net;CryptoCurrency;CryptoCurrency Exchange</PackageTags> <PackageTags>OKX;OKX.Net;Mexc;Mexc.Net;Kucoin;Kucoin.Net;Kraken;Kraken.Net;Huobi;Huobi.Net;CoinEx;CoinEx.Net;Bybit;Bybit.Net;Bitget;Bitget.Net;Bitfinex;Bitfinex.Net;Binance;Binance.Net;CryptoCurrency;CryptoCurrency Exchange</PackageTags>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
@@ -1,12 +1,13 @@
using CryptoExchange.Net.Objects; using CryptoExchange.Net.Objects;
using System; using System;
using System.Collections.Generic;
namespace CryptoExchange.Net.SharedApis namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// A symbol representation based on a base and quote asset /// A symbol representation based on a base and quote asset
/// </summary> /// </summary>
public class SharedSymbol public record SharedSymbol
{ {
/// <summary> /// <summary>
/// The base asset of the symbol /// The base asset of the symbol
@@ -604,7 +604,7 @@ namespace CryptoExchange.Net.Sockets
} }
catch (Exception wse) catch (Exception wse)
{ {
if (!_ctsSource.Token.IsCancellationRequested) if (!_ctsSource.Token.IsCancellationRequested && !_stopRequested)
// Connection closed unexpectedly // Connection closed unexpectedly
await (OnError?.Invoke(wse) ?? Task.CompletedTask).ConfigureAwait(false); await (OnError?.Invoke(wse) ?? Task.CompletedTask).ConfigureAwait(false);
@@ -105,7 +105,7 @@ namespace CryptoExchange.Net.Testing.Comparers
int i = 0; int i = 0;
foreach (var item in jObj.Children()) foreach (var item in jObj.Children())
{ {
var arrayProp = resultProps.Where(p => p.Item2 != null).SingleOrDefault(p => p.Item2!.Index == i).p; var arrayProp = resultProps.Where(p => p.Item2 != null).FirstOrDefault(p => p.Item2!.Index == i).p;
if (arrayProp != null) if (arrayProp != null)
CheckPropertyValue(method, item, arrayProp.GetValue(resultObj), arrayProp.PropertyType, arrayProp.Name, "Array index " + i, ignoreProperties!); CheckPropertyValue(method, item, arrayProp.GetValue(resultObj), arrayProp.PropertyType, arrayProp.Name, "Array index " + i, ignoreProperties!);
i++; i++;
@@ -264,9 +264,9 @@ namespace CryptoExchange.Net.Testing.Comparers
int i = 0; int i = 0;
foreach (var item in jtoken.Children()) foreach (var item in jtoken.Children())
{ {
var arrayProp = resultProps.Where(p => p.Item2 != null).SingleOrDefault(p => p.Item2!.Index == i).p; var arrayProp = resultProps.Where(p => p.Item2 != null).FirstOrDefault(p => p.Item2!.Index == i).p;
if (arrayProp != null) if (arrayProp != null)
CheckPropertyValue(method, item, arrayProp.GetValue(resultObj), propertyType, arrayProp.Name, "Array index " + i, ignoreProperties); CheckPropertyValue(method, item, arrayProp.GetValue(resultObj), arrayProp.PropertyType, arrayProp.Name, "Array index " + i, ignoreProperties);
i++; i++;
} }
@@ -350,7 +350,7 @@ namespace CryptoExchange.Net.Testing.Comparers
int i = 0; int i = 0;
foreach (var item in jObjs.Children()) foreach (var item in jObjs.Children())
{ {
var arrayProp = resultProps.Where(p => p.Item2 != null).SingleOrDefault(p => p.Item2!.Index == i).p; var arrayProp = resultProps.Where(p => p.Item2 != null).FirstOrDefault(p => p.Item2!.Index == i).p;
if (arrayProp != null) if (arrayProp != null)
CheckPropertyValue(method, item, arrayProp.GetValue(propertyValue), arrayProp.PropertyType, arrayProp.Name, "Array index " + i, ignoreProperties!); CheckPropertyValue(method, item, arrayProp.GetValue(propertyValue), arrayProp.PropertyType, arrayProp.Name, "Array index " + i, ignoreProperties!);
i++; i++;
+10
View File
@@ -68,6 +68,16 @@ Make a one time donation in a crypto currency of your choice. If you prefer to d
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf). Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).
## Release notes ## Release notes
* Version 8.7.3 - 05 Feb 2025
* Added handling of negative number DateTime deserialization to default
* Updated SharedSymbol from class to record
* Fixed issue with serialization of nullable types in System.Text.Json ArrayConverter
* Fix for unnecessary error message in logging when closing websocket connection
* Version 8.7.2 - 27 Jan 2025
* Some small fixes in the System.Text.Json ArrayConverter
* Added support for Flags enum deserialization in System.Text.Json EnumConverter
* Version 8.7.1 - 24 Jan 2025 * Version 8.7.1 - 24 Jan 2025
* Added Authenticated property to IBaseApiClient interface to check if a client was provided API credentials * Added Authenticated property to IBaseApiClient interface to check if a client was provided API credentials