mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-04-12 16:13:12 +00:00
Compare commits
2 Commits
204bda8622
...
33c0fb26a7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33c0fb26a7 | ||
|
|
dabbb5c868 |
@ -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>10.7.1</PackageVersion>
|
||||
<AssemblyVersion>10.7.1</AssemblyVersion>
|
||||
<FileVersion>10.7.1</FileVersion>
|
||||
<PackageVersion>10.7.2</PackageVersion>
|
||||
<AssemblyVersion>10.7.2</AssemblyVersion>
|
||||
<FileVersion>10.7.2</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>
|
||||
|
||||
@ -20,6 +20,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
private readonly ExchangeParameters? _exchangeParameters;
|
||||
private readonly bool _requiresSymbolParameterOpenOrders;
|
||||
private readonly Dictionary<string, int> _openOrderNotReturnedTimes = new();
|
||||
private readonly TimeSpan _pollOverlapPeriod = TimeSpan.FromSeconds(3);
|
||||
|
||||
internal event Func<UpdateSource, SharedUserTrade[], Task>? OnTradeUpdate;
|
||||
|
||||
@ -355,17 +356,17 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
DateTime? fromTime = null;
|
||||
string? source = null;
|
||||
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time. 1 seconds buffer
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time
|
||||
if (_lastDataTimeBeforeDisconnect.HasValue && (fromTime == null || fromTime > _lastDataTimeBeforeDisconnect.Value))
|
||||
{
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.AddSeconds(-1);
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastDataTimeBeforeDisconnect";
|
||||
}
|
||||
|
||||
// If we've previously polled use that timestamp to request data from
|
||||
if (_lastPollTime.HasValue && (fromTime == null || _lastPollTime.Value > fromTime))
|
||||
{
|
||||
fromTime = _lastPollTime;
|
||||
fromTime = _lastPollTime.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastPollTime";
|
||||
}
|
||||
|
||||
@ -378,7 +379,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
{
|
||||
// Could be improved by only requesting the specific open orders if there are only a few that would be better than trying to request a long
|
||||
// history if the open order is far back
|
||||
fromTime = trackedOrdersMinOpenTime.Value.AddMilliseconds(-1);
|
||||
fromTime = trackedOrdersMinOpenTime.Value.AddSeconds(-1);
|
||||
source = "OpenOrder";
|
||||
}
|
||||
|
||||
@ -388,7 +389,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
source = "StartTime";
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(1))
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(5))
|
||||
{
|
||||
// Set it to at least 5 seconds in the past to prevent issues when local time isn't in sync
|
||||
fromTime = DateTime.UtcNow.AddSeconds(-5);
|
||||
|
||||
@ -18,6 +18,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
private readonly IFuturesOrderRestClient _restClient;
|
||||
private readonly IUserTradeSocketClient? _socketClient;
|
||||
private readonly ExchangeParameters? _exchangeParameters;
|
||||
private readonly TimeSpan _pollOverlapPeriod = TimeSpan.FromSeconds(3);
|
||||
|
||||
internal Func<string[]>? GetTrackedOrderIds { get; set; }
|
||||
|
||||
@ -106,22 +107,22 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
|
||||
private DateTime? GetTradesRequestStartTime()
|
||||
{
|
||||
// Determine the timestamp from which we need to check order status
|
||||
// Determine the timestamp from which we need to request trades from
|
||||
// Use the timestamp we last know the correct state of the data
|
||||
DateTime? fromTime = null;
|
||||
string? source = null;
|
||||
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time. 1 seconds buffer
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time.
|
||||
if (_lastDataTimeBeforeDisconnect.HasValue && (fromTime == null || fromTime > _lastDataTimeBeforeDisconnect.Value))
|
||||
{
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.AddSeconds(-1);
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastDataTimeBeforeDisconnect";
|
||||
}
|
||||
|
||||
// If we've previously polled use that timestamp to request data from
|
||||
if (_lastPollTime.HasValue && (fromTime == null || _lastPollTime.Value > fromTime))
|
||||
{
|
||||
fromTime = _lastPollTime;
|
||||
fromTime = _lastPollTime.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastPollTime";
|
||||
}
|
||||
|
||||
@ -132,7 +133,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
}
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
if (now - fromTime < TimeSpan.FromSeconds(1))
|
||||
if (now - fromTime < TimeSpan.FromSeconds(5))
|
||||
{
|
||||
// Set it to at least 5 seconds in the past to prevent issues when local time isn't in sync
|
||||
fromTime = DateTime.UtcNow.AddSeconds(-5);
|
||||
|
||||
@ -20,6 +20,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
private readonly ExchangeParameters? _exchangeParameters;
|
||||
private readonly bool _requiresSymbolParameterOpenOrders;
|
||||
private readonly Dictionary<string, int> _openOrderNotReturnedTimes = new();
|
||||
private readonly TimeSpan _pollOverlapPeriod = TimeSpan.FromSeconds(3);
|
||||
|
||||
internal event Func<UpdateSource, SharedUserTrade[], Task>? OnTradeUpdate;
|
||||
|
||||
@ -366,17 +367,17 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
DateTime? fromTime = null;
|
||||
string? source = null;
|
||||
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time. 1 seconds buffer
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time.
|
||||
if (_lastDataTimeBeforeDisconnect.HasValue && (fromTime == null || fromTime > _lastDataTimeBeforeDisconnect.Value))
|
||||
{
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.AddSeconds(-1);
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastDataTimeBeforeDisconnect";
|
||||
}
|
||||
|
||||
// If we've previously polled use that timestamp to request data from
|
||||
if (_lastPollTime.HasValue && (fromTime == null || _lastPollTime.Value > fromTime))
|
||||
{
|
||||
fromTime = _lastPollTime;
|
||||
fromTime = _lastPollTime.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastPollTime";
|
||||
}
|
||||
|
||||
@ -389,7 +390,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
{
|
||||
// Could be improved by only requesting the specific open orders if there are only a few that would be better than trying to request a long
|
||||
// history if the open order is far back
|
||||
fromTime = trackedOrdersMinOpenTime.Value.AddMilliseconds(-1);
|
||||
fromTime = trackedOrdersMinOpenTime.Value.AddSeconds(-1);
|
||||
source = "OpenOrder";
|
||||
}
|
||||
|
||||
@ -399,7 +400,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
source = "StartTime";
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(1))
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(5))
|
||||
{
|
||||
// Set it to at least 5 seconds in the past to prevent issues when local time isn't in sync
|
||||
fromTime = DateTime.UtcNow.AddSeconds(-5);
|
||||
|
||||
@ -18,6 +18,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
private readonly ISpotOrderRestClient _restClient;
|
||||
private readonly IUserTradeSocketClient? _socketClient;
|
||||
private readonly ExchangeParameters? _exchangeParameters;
|
||||
private readonly TimeSpan _pollOverlapPeriod = TimeSpan.FromSeconds(3);
|
||||
|
||||
internal Func<string[]>? GetTrackedOrderIds { get; set; }
|
||||
|
||||
@ -103,22 +104,22 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
|
||||
private DateTime? GetTradesRequestStartTime()
|
||||
{
|
||||
// Determine the timestamp from which we need to check order status
|
||||
// Determine the timestamp from which we need to request trades from
|
||||
// Use the timestamp we last know the correct state of the data
|
||||
DateTime? fromTime = null;
|
||||
string? source = null;
|
||||
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time. 1 seconds buffer
|
||||
// Use the last timestamp we we received data from the websocket as state should be correct at that time.
|
||||
if (_lastDataTimeBeforeDisconnect.HasValue && (fromTime == null || fromTime > _lastDataTimeBeforeDisconnect.Value))
|
||||
{
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.AddSeconds(-1);
|
||||
fromTime = _lastDataTimeBeforeDisconnect.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastDataTimeBeforeDisconnect";
|
||||
}
|
||||
|
||||
// If we've previously polled use that timestamp to request data from
|
||||
if (_lastPollTime.HasValue && (fromTime == null || _lastPollTime.Value > fromTime))
|
||||
{
|
||||
fromTime = _lastPollTime;
|
||||
fromTime = _lastPollTime.Value.Add(-_pollOverlapPeriod);
|
||||
source = "LastPollTime";
|
||||
}
|
||||
|
||||
@ -128,7 +129,7 @@ namespace CryptoExchange.Net.Trackers.UserData.ItemTrackers
|
||||
source = "StartTime";
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(1))
|
||||
if (DateTime.UtcNow - fromTime < TimeSpan.FromSeconds(5))
|
||||
{
|
||||
// Set it to at least 5 seconds in the past to prevent issues when local time isn't in sync
|
||||
fromTime = DateTime.UtcNow.AddSeconds(-5);
|
||||
|
||||
@ -67,6 +67,9 @@ 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).
|
||||
|
||||
## Release notes
|
||||
* Version 10.7.2 - 02 Mar 2026
|
||||
* Added small overlap in UserDataTracker polling logic to account for API endpoints not immediately having the data available
|
||||
|
||||
* Version 10.7.1 - 25 Feb 2026
|
||||
* Fixed deadlock scenario in websocket connection when subscribe and handling message concurrently
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user