mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-02-16 14:13:46 +00:00
Added AutoTimestamp option for socket client, fixed socket client timestamp offset bug
This commit is contained in:
parent
74e5cf6fc9
commit
40d480e1fc
@ -518,11 +518,14 @@ namespace CryptoExchange.Net.Authentication
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected DateTime GetTimestamp(SocketApiClient apiClient, bool includeOneSecondOffset = true)
|
protected DateTime GetTimestamp(SocketApiClient apiClient, bool includeOneSecondOffset = true)
|
||||||
{
|
{
|
||||||
var result = TimeProvider.GetTime().Add(TimeOffsetManager.GetSocketOffset(apiClient.ClientName) ?? TimeSpan.Zero)!;
|
var timestamp = TimeProvider.GetTime();
|
||||||
if (includeOneSecondOffset)
|
if(apiClient.ApiOptions.AutoTimestamp ?? apiClient.ClientOptions.AutoTimestamp)
|
||||||
result = result.AddSeconds(-1);
|
timestamp = timestamp.Add(-TimeOffsetManager.GetSocketOffset(apiClient.ClientName) ?? TimeSpan.Zero)!;
|
||||||
|
|
||||||
return result;
|
if (includeOneSecondOffset)
|
||||||
|
timestamp = timestamp.AddSeconds(-1);
|
||||||
|
|
||||||
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -13,7 +13,10 @@ namespace CryptoExchange.Net.Clients
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class BaseApiClient : IDisposable, IBaseApiClient
|
public abstract class BaseApiClient : IDisposable, IBaseApiClient
|
||||||
{
|
{
|
||||||
private string? _clientName;
|
/// <summary>
|
||||||
|
/// Client name
|
||||||
|
/// </summary>
|
||||||
|
protected string? _clientName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logger
|
/// Logger
|
||||||
|
|||||||
@ -7,6 +7,11 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ApiOptions
|
public class ApiOptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to automatically sync the local time with the server time
|
||||||
|
/// </summary>
|
||||||
|
public bool? AutoTimestamp { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If true, the CallResult and DataEvent objects will also include the originally received string data in the OriginalData property.
|
/// If true, the CallResult and DataEvent objects will also include the originally received string data in the OriginalData property.
|
||||||
/// Note that this comes at a performance cost
|
/// Note that this comes at a performance cost
|
||||||
|
|||||||
@ -8,6 +8,10 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ExchangeOptions
|
public class ExchangeOptions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not to automatically sync the local time with the server time
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoTimestamp { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Proxy settings
|
/// Proxy settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -8,11 +8,6 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RestApiOptions : ApiOptions
|
public class RestApiOptions : ApiOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Whether or not to automatically sync the local time with the server time
|
|
||||||
/// </summary>
|
|
||||||
public bool? AutoTimestamp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How often the timestamp adjustment between client and server is recalculated. If you need a very small TimeSpan here you're probably better of syncing your server time more often
|
/// How often the timestamp adjustment between client and server is recalculated. If you need a very small TimeSpan here you're probably better of syncing your server time more often
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -8,11 +8,6 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RestExchangeOptions: ExchangeOptions
|
public class RestExchangeOptions: ExchangeOptions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Whether or not to automatically sync the local time with the server time
|
|
||||||
/// </summary>
|
|
||||||
public bool AutoTimestamp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How often the timestamp adjustment between client and server is recalculated. If you need a very small TimeSpan here you're probably better of syncing your server time more often
|
/// How often the timestamp adjustment between client and server is recalculated. If you need a very small TimeSpan here you're probably better of syncing your server time more often
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -27,6 +27,7 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
item.ApiCredentials = ApiCredentials?.Copy();
|
item.ApiCredentials = ApiCredentials?.Copy();
|
||||||
item.OutputOriginalData = OutputOriginalData;
|
item.OutputOriginalData = OutputOriginalData;
|
||||||
item.SocketNoDataTimeout = SocketNoDataTimeout;
|
item.SocketNoDataTimeout = SocketNoDataTimeout;
|
||||||
|
item.AutoTimestamp = AutoTimestamp;
|
||||||
item.MaxSocketConnections = MaxSocketConnections;
|
item.MaxSocketConnections = MaxSocketConnections;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,6 +75,15 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public int? ReceiveBufferSize { get; set; }
|
public int? ReceiveBufferSize { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
public SocketExchangeOptions()
|
||||||
|
{
|
||||||
|
// Enable auto timestamping by default for sockets
|
||||||
|
AutoTimestamp = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a copy of this options
|
/// Create a copy of this options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -83,6 +92,7 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
public T Set<T>(T item) where T : SocketExchangeOptions, new()
|
public T Set<T>(T item) where T : SocketExchangeOptions, new()
|
||||||
{
|
{
|
||||||
item.ApiCredentials = ApiCredentials?.Copy();
|
item.ApiCredentials = ApiCredentials?.Copy();
|
||||||
|
item.AutoTimestamp = AutoTimestamp;
|
||||||
item.OutputOriginalData = OutputOriginalData;
|
item.OutputOriginalData = OutputOriginalData;
|
||||||
item.ReconnectPolicy = ReconnectPolicy;
|
item.ReconnectPolicy = ReconnectPolicy;
|
||||||
item.DelayAfterConnect = DelayAfterConnect;
|
item.DelayAfterConnect = DelayAfterConnect;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user