1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 16:36:15 +00:00

Fix for time offset calculation not updating when offset is < 500ms

This commit is contained in:
Jkorf 2022-02-09 13:37:12 +01:00
parent 105547d6b1
commit 9461b57daa
3 changed files with 14 additions and 15 deletions

View File

@ -129,8 +129,11 @@ namespace CryptoExchange.Net
{
var syncTimeResult = await apiClient.SyncTimeAsync().ConfigureAwait(false);
if (!syncTimeResult)
{
log.Write(LogLevel.Debug, $"[{requestId}] Failed to sync time, aborting request: " + syncTimeResult.Error);
return syncTimeResult.As<T>(default);
}
}
log.Write(LogLevel.Debug, $"[{requestId}] Creating request for " + uri);
if (signed && apiClient.AuthenticationProvider == null)

View File

@ -93,18 +93,9 @@ namespace CryptoExchange.Net
// Calculate time offset between local and server
var offset = result.Data - localTime;
if (offset.TotalMilliseconds >= 0 && offset.TotalMilliseconds < 500)
{
// Small offset, probably mainly due to ping. Don't adjust time
timeSyncParams.UpdateTimeOffset(offset);
timeSyncParams.TimeSyncState.Semaphore.Release();
}
else
{
timeSyncParams.UpdateTimeOffset(offset);
timeSyncParams.TimeSyncState.Semaphore.Release();
}
}
return new WebCallResult<bool>(null, null, null, null, null, null, null, null, true, null);
}

View File

@ -71,10 +71,15 @@ namespace CryptoExchange.Net.Objects
{
TimeSyncState.LastSyncTime = DateTime.UtcNow;
if (offset.TotalMilliseconds > 0 && offset.TotalMilliseconds < 500)
return;
{
Log.Write(LogLevel.Information, $"Time offset within limits, set offset to 0ms");
TimeSyncState.TimeOffset = TimeSpan.Zero;
}
else
{
Log.Write(LogLevel.Information, $"Time offset set to {Math.Round(offset.TotalMilliseconds)}ms");
TimeSyncState.TimeOffset = offset;
}
}
}
}