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

Compare commits

...

7 Commits

8 changed files with 74 additions and 34 deletions
@@ -38,6 +38,11 @@ namespace CryptoExchange.Net.Clients
/// </summary> /// </summary>
public bool OutputOriginalData { get; } public bool OutputOriginalData { get; }
/// <summary>
/// Whether or not API credentials have been configured for this client. Does not check the credentials are actually valid.
/// </summary>
public bool Authenticated => ApiOptions.ApiCredentials != null || ClientOptions.ApiCredentials != null;
/// <summary> /// <summary>
/// Api options /// Api options
/// </summary> /// </summary>
@@ -94,13 +94,15 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
if (reader.TokenType == JsonTokenType.EndArray) if (reader.TokenType == JsonTokenType.EndArray)
break; break;
var attribute = attributes.SingleOrDefault(a => a.ArrayProperty.Index == index); var indexAttributes = attributes.Where(a => a.ArrayProperty.Index == index);
if (attribute == null) if (!indexAttributes.Any())
{ {
index++; index++;
continue; continue;
} }
foreach (var attribute in indexAttributes)
{
var targetType = attribute.TargetType; var targetType = attribute.TargetType;
object? value = null; object? value = null;
if (attribute.JsonConverterType != null) if (attribute.JsonConverterType != null)
@@ -129,6 +131,7 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
} }
attribute.PropertyInfo.SetValue(result, value == null ? null : Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); attribute.PropertyInfo.SetValue(result, value == null ? null : Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture));
}
index++; index++;
} }
@@ -23,8 +23,15 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
return reader.GetDecimal().ToString(); return reader.GetDecimal().ToString();
} }
try
{
return reader.GetString(); return reader.GetString();
} }
catch (Exception)
{
return null;
}
}
/// <inheritdoc /> /// <inheritdoc />
public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options)
@@ -133,7 +133,20 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
} }
/// <inheritdoc /> /// <inheritdoc />
public List<T?>? GetValues<T>(MessagePath path) => throw new NotImplementedException(); public List<T?>? GetValues<T>(MessagePath path)
{
if (!IsJson)
throw new InvalidOperationException("Can't access json data on non-json message");
var value = GetPathNode(path);
if (value == null)
return default;
if (value.Value.ValueKind != JsonValueKind.Array)
return default;
return value.Value.Deserialize<List<T>>()!;
}
private JsonElement? GetPathNode(MessagePath path) private JsonElement? GetPathNode(MessagePath path)
{ {
+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.0.2</PackageVersion> <PackageVersion>8.0.3</PackageVersion>
<AssemblyVersion>8.0.2</AssemblyVersion> <AssemblyVersion>8.0.3</AssemblyVersion>
<FileVersion>8.0.2</FileVersion> <FileVersion>8.0.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>
@@ -18,6 +18,11 @@ namespace CryptoExchange.Net.SharedApis
/// </summary> /// </summary>
TradingMode[] SupportedTradingModes { get; } TradingMode[] SupportedTradingModes { get; }
/// <summary>
/// Whether or not API credentials have been configured for this client. Does not check the credentials are actually valid.
/// </summary>
bool Authenticated { get; }
/// <summary> /// <summary>
/// Format a base and quote asset to an exchange accepted symbol /// Format a base and quote asset to an exchange accepted symbol
/// </summary> /// </summary>
+6
View File
@@ -48,6 +48,12 @@ 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.0.3 - 14 Oct 2024
* Added support for duplicate array indexes in System.Text.Json ArrayConverter
* Added fallback for unparsable value in System.Text.Json NumberStringConverter
* Added Authenticated property on base client and shared client
* Added GetValues System.Text.Json implementation in message accessor
* Version 8.0.2 - 09 Oct 2024 * Version 8.0.2 - 09 Oct 2024
* Updated dependency versions, including System.Text.Json from 8.0.4 to 8.0.5 containing a vulnerability fix * Updated dependency versions, including System.Text.Json from 8.0.4 to 8.0.5 containing a vulnerability fix
+3 -2
View File
@@ -1964,8 +1964,9 @@ var balances = await restClient.HTX.SpotApi.SharedClient.GetBalancesAsync(new Ge
// Needs authentication: True // Needs authentication: True
// Required exchange specific parameters: [Int64] AccountId: Account id of the user | example: 123123123</code></pre> // Required exchange specific parameters: [Int64] AccountId: Account id of the user | example: 123123123</code></pre>
<h4 id="shared_interfaces">Available Interfaces</h4> <h4 id="shared_interfaces">Available Interfaces</h4>
<p>What interfaces are actually available and implemented on each exchange clients depends on what functionality is available in the specific API.</p>
<p>Available REST shared interfaces</p> <p style="font-style: italic;">Available REST shared interfaces</p>
<table class="table table-bordered"> <table class="table table-bordered">
<tr><th>Interface</th><th>Description</th></tr> <tr><th>Interface</th><th>Description</th></tr>
<tr><td><code>IAssetsRestClient</code></td><td>For requesting withdrawal and deposit info for assets</td></tr> <tr><td><code>IAssetsRestClient</code></td><td>For requesting withdrawal and deposit info for assets</td></tr>
@@ -1993,7 +1994,7 @@ var balances = await restClient.HTX.SpotApi.SharedClient.GetBalancesAsync(new Ge
<tr><td><code>IPositionModeRestClient</code></td><td>For managing the position mode for the user</td></tr> <tr><td><code>IPositionModeRestClient</code></td><td>For managing the position mode for the user</td></tr>
</table> </table>
<p>Available Socket shared interfaces</p> <p style="font-style: italic;">Available Socket shared interfaces</p>
<table class="table table-bordered"> <table class="table table-bordered">
<tr><th>Interface</th><th>Description</th></tr> <tr><th>Interface</th><th>Description</th></tr>
<tr><td><code>IBookTickerSocketClient</code></td><td>For subscribing to book ticker (best bid/ask) updates for a symbol</td></tr> <tr><td><code>IBookTickerSocketClient</code></td><td>For subscribing to book ticker (best bid/ask) updates for a symbol</td></tr>