mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-12 17:03:10 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4accc8039b | |||
| 87c86ec0c0 | |||
| d9850da282 | |||
| c4a8b02054 |
@@ -6,9 +6,9 @@
|
||||
<PackageId>CryptoExchange.Net</PackageId>
|
||||
<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>
|
||||
<PackageVersion>12.0.2</PackageVersion>
|
||||
<AssemblyVersion>12.0.2</AssemblyVersion>
|
||||
<FileVersion>12.0.2</FileVersion>
|
||||
<PackageVersion>12.1.0</PackageVersion>
|
||||
<AssemblyVersion>12.1.0</AssemblyVersion>
|
||||
<FileVersion>12.1.0</FileVersion>
|
||||
<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;CryptoExchange.Net</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
|
||||
@@ -24,8 +24,9 @@ namespace CryptoExchange.Net.Interfaces
|
||||
/// <param name="interval">Kline interval</param>
|
||||
/// <param name="limit">The max amount of klines to retain</param>
|
||||
/// <param name="period">The max period the data should be retained</param>
|
||||
/// <param name="exchangeParameters">Exchange parameters</param>
|
||||
/// <returns></returns>
|
||||
IKlineTracker CreateKlineTracker(SharedSymbol symbol, SharedKlineInterval interval, int? limit = null, TimeSpan? period = null);
|
||||
IKlineTracker CreateKlineTracker(SharedSymbol symbol, SharedKlineInterval interval, int? limit = null, TimeSpan? period = null, ExchangeParameters? exchangeParameters = null);
|
||||
|
||||
/// <summary>
|
||||
/// Whether the factory supports creating a TradeTracker instance for this symbol
|
||||
@@ -39,7 +40,8 @@ namespace CryptoExchange.Net.Interfaces
|
||||
/// <param name="symbol">The symbol</param>
|
||||
/// <param name="limit">The max amount of trades to retain</param>
|
||||
/// <param name="period">The max period the data should be retained</param>
|
||||
/// <param name="exchangeParameters">Exchange parameters</param>
|
||||
/// <returns></returns>
|
||||
ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null, TimeSpan? period = null);
|
||||
ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null, TimeSpan? period = null, ExchangeParameters? exchangeParameters = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// Add key as comma separated values
|
||||
/// </summary>
|
||||
#if NET5_0_OR_GREATER
|
||||
public void AddCommaSeparated<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] T>(string key, IEnumerable<T> values)
|
||||
public void AddCommaSeparated<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields)] T>(string key, IEnumerable<T>? values)
|
||||
#else
|
||||
public void AddCommaSeparated<T>(string key, IEnumerable<T>? values)
|
||||
#endif
|
||||
|
||||
@@ -63,7 +63,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
foreach (var dictProp in jObj.EnumerateObject())
|
||||
{
|
||||
if (!dict.Contains(dictProp.Name))
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Dictionary has no value for {dictProp.Name} while input json `{dictProp.Name}` has value {dictProp.Value}"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dictProp.Value.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
@@ -80,6 +83,7 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
|
||||
// Property value not correct
|
||||
outputExceptions.Add(new Exception($"{method}: Dictionary entry `{dictProp.Name}` has no value while input json has value {dictProp.Value}"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,7 +135,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
{
|
||||
var value = enumerator.Current;
|
||||
if (value == default && jObj.ValueKind != JsonValueKind.Null)
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Array has no value while input json array has value {jObj}"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +174,7 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Successfully validated {method}");
|
||||
return outputExceptions;
|
||||
return outputExceptions.Distinct().ToList();
|
||||
}
|
||||
|
||||
private static void CheckObject(string method, JsonProperty prop, object obj, List<string>? ignoreProperties, List<Exception> outputExceptions)
|
||||
@@ -225,7 +232,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
|
||||
// Property value not correct
|
||||
if (propValue.ToString() != "0")
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Property `{propertyName}` has no value while input json `{propName}` has value {propValue}"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ((propertyValue == default && (propValue.ValueKind == JsonValueKind.Null || string.IsNullOrEmpty(propValue.ToString()))) || propValue.ToString() == "0")
|
||||
@@ -237,7 +247,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
foreach (var dictProp in propValue.EnumerateObject())
|
||||
{
|
||||
if (!dict.Contains(dictProp.Name))
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Property `{propertyName}` has no value while input json `{propName}` has value {propValue}"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dictProp.Value.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
@@ -246,8 +259,11 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
else
|
||||
{
|
||||
if (dict[dictProp.Name] == default && dictProp.Value.ValueKind != JsonValueKind.Null)
|
||||
{
|
||||
// Property value not correct
|
||||
outputExceptions.Add(new Exception($"{method}: Dictionary entry `{dictProp.Name}` has no value while input json has value {propValue} for"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +320,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
{
|
||||
var value = enumerator.Current;
|
||||
if (value == default && jToken.ValueKind != JsonValueKind.Null)
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Property `{propertyName}` has no value while input json `{propName}` has value {jToken}"));
|
||||
return;
|
||||
}
|
||||
|
||||
CheckValues(method, propertyName!, propertyType, jToken, value!, outputExceptions);
|
||||
}
|
||||
@@ -368,7 +387,10 @@ namespace CryptoExchange.Net.Testing.Comparers
|
||||
{
|
||||
var value = enumerator.Current;
|
||||
if (value == default && jObj.ValueKind != JsonValueKind.Null)
|
||||
{
|
||||
outputExceptions.Add(new Exception($"{method}: Array has no value while input json array has value {jObj}"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace CryptoExchange.Net.Trackers.Klines
|
||||
private readonly IKlineRestClient _restClient;
|
||||
private SyncStatus _status;
|
||||
private bool _startWithSnapshot;
|
||||
private ExchangeParameters? _exchangeParameters;
|
||||
|
||||
/// <summary>
|
||||
/// The internal data structure
|
||||
@@ -157,9 +158,11 @@ namespace CryptoExchange.Net.Trackers.Klines
|
||||
SharedSymbol symbol,
|
||||
SharedKlineInterval interval,
|
||||
int? limit = null,
|
||||
TimeSpan? period = null)
|
||||
TimeSpan? period = null,
|
||||
ExchangeParameters? exchangeParameters = null)
|
||||
{
|
||||
_logger = logger ?? new NullLogger<KlineTracker>();
|
||||
_exchangeParameters = exchangeParameters;
|
||||
Symbol = symbol;
|
||||
SymbolName = socketClient.FormatSymbol(symbol.BaseAsset, symbol.QuoteAsset, symbol.TradingMode, symbol.DeliverTime);
|
||||
Exchange = restClient.Exchange;
|
||||
@@ -180,7 +183,7 @@ namespace CryptoExchange.Net.Trackers.Klines
|
||||
Status = SyncStatus.Syncing;
|
||||
_logger.KlineTrackerStarting(SymbolName);
|
||||
|
||||
var subResult = await _socketClient.SubscribeToKlineUpdatesAsync(new SubscribeKlineRequest(Symbol, Interval),
|
||||
var subResult = await _socketClient.SubscribeToKlineUpdatesAsync(new SubscribeKlineRequest(Symbol, Interval, exchangeParameters: _exchangeParameters),
|
||||
update =>
|
||||
{
|
||||
AddOrUpdate(update.Data);
|
||||
@@ -237,7 +240,7 @@ namespace CryptoExchange.Net.Trackers.Klines
|
||||
|
||||
var limit = Math.Min(_restClient.GetKlinesOptions.MaxLimit, Limit ?? 100);
|
||||
|
||||
var request = new GetKlinesRequest(Symbol, Interval, startTime, DateTime.UtcNow, limit: limit);
|
||||
var request = new GetKlinesRequest(Symbol, Interval, startTime, DateTime.UtcNow, limit: limit, exchangeParameters: _exchangeParameters);
|
||||
var data = new List<SharedKline>();
|
||||
await foreach (var result in ExchangeHelpers.ExecutePages(_restClient.GetKlinesAsync, request).ConfigureAwait(false))
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace CryptoExchange.Net.Trackers.Trades
|
||||
private SyncStatus _status;
|
||||
private long _snapshotId;
|
||||
private bool _startWithSnapshot;
|
||||
private ExchangeParameters? _exchangeParameters;
|
||||
|
||||
/// <summary>
|
||||
/// The internal data structure
|
||||
@@ -154,12 +155,14 @@ namespace CryptoExchange.Net.Trackers.Trades
|
||||
ITradeSocketClient socketClient,
|
||||
SharedSymbol symbol,
|
||||
int? limit = null,
|
||||
TimeSpan? period = null)
|
||||
TimeSpan? period = null,
|
||||
ExchangeParameters? exchangeParameters = null)
|
||||
{
|
||||
_logger = logger ?? new NullLogger<TradeTracker>();
|
||||
_recentRestClient = recentRestClient;
|
||||
_historyRestClient = historyRestClient;
|
||||
_socketClient = socketClient;
|
||||
_exchangeParameters = exchangeParameters;
|
||||
Exchange = socketClient.Exchange;
|
||||
Symbol = symbol;
|
||||
SymbolName = socketClient.FormatSymbol(symbol.BaseAsset, symbol.QuoteAsset, symbol.TradingMode, symbol.DeliverTime);
|
||||
@@ -203,7 +206,7 @@ namespace CryptoExchange.Net.Trackers.Trades
|
||||
_startWithSnapshot = startWithSnapshot;
|
||||
Status = SyncStatus.Syncing;
|
||||
_logger.TradeTrackerStarting(SymbolName);
|
||||
var subResult = await _socketClient.SubscribeToTradeUpdatesAsync(new SubscribeTradeRequest(Symbol),
|
||||
var subResult = await _socketClient.SubscribeToTradeUpdatesAsync(new SubscribeTradeRequest(Symbol, exchangeParameters: _exchangeParameters),
|
||||
update =>
|
||||
{
|
||||
AddData(update.Data);
|
||||
@@ -257,7 +260,7 @@ namespace CryptoExchange.Net.Trackers.Trades
|
||||
if (_historyRestClient != null)
|
||||
{
|
||||
var startTime = Period == null ? DateTime.UtcNow.AddMinutes(-5) : DateTime.UtcNow.Add(-Period.Value);
|
||||
var request = new GetTradeHistoryRequest(Symbol, startTime, DateTime.UtcNow);
|
||||
var request = new GetTradeHistoryRequest(Symbol, startTime, DateTime.UtcNow, exchangeParameters: _exchangeParameters);
|
||||
var data = new List<SharedTrade>();
|
||||
await foreach (var result in ExchangeHelpers.ExecutePages(_historyRestClient.GetTradeHistoryAsync, request).ConfigureAwait(false))
|
||||
{
|
||||
@@ -278,7 +281,7 @@ namespace CryptoExchange.Net.Trackers.Trades
|
||||
if (Limit.HasValue)
|
||||
limit = Math.Min(_recentRestClient.GetRecentTradesOptions.MaxLimit, Limit.Value);
|
||||
|
||||
var snapshot = await _recentRestClient.GetRecentTradesAsync(new GetRecentTradesRequest(Symbol, limit)).ConfigureAwait(false);
|
||||
var snapshot = await _recentRestClient.GetRecentTradesAsync(new GetRecentTradesRequest(Symbol, limit, exchangeParameters: _exchangeParameters)).ConfigureAwait(false);
|
||||
if (!snapshot.Success)
|
||||
{
|
||||
return CallResult.Fail(snapshot.Error);
|
||||
|
||||
@@ -127,6 +127,11 @@ Various:
|
||||
* PlatformInfo now required support environment names in the constructor
|
||||
|
||||
## Release notes
|
||||
* Version 12.1.0 - 09 Jul 2026
|
||||
* Added ExchangeParameters parameter to KlineTracker, TradeTracker and ITrackerFactory methods
|
||||
* Updated some testing logic
|
||||
* Fixed nullability operator on Parameters.AddCommaSeperated
|
||||
|
||||
* Version 12.0.2 - 01 Jul 2026
|
||||
* Updated test validation to output a list of issues instead of throwing on the first
|
||||
|
||||
|
||||
Reference in New Issue
Block a user