diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs
index 6332398..a4deba7 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetClosedOrdersOptions.cs
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Objects;
+using System;
using System.Text;
namespace CryptoExchange.Net.SharedApis
@@ -19,8 +20,22 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetClosedOrdersRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetClosedOrdersRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
}
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs
index 17e0ce5..a6a0da0 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetDepositsOptions.cs
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Objects;
+using System;
using System.Text;
namespace CryptoExchange.Net.SharedApis
@@ -19,8 +20,22 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetDepositsRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
}
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs
index bc7fded..7a9088a 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetFundingRateHistoryOptions.cs
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Objects;
+using System;
using System.Text;
namespace CryptoExchange.Net.SharedApis
@@ -19,8 +20,22 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetFundingRateHistoryRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
}
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs
index c42d11c..766ab95 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetKlinesOptions.cs
@@ -70,8 +70,22 @@ namespace CryptoExchange.Net.SharedApis
if (!IsSupported(request.Interval))
return ArgumentError.Invalid(nameof(GetKlinesRequest.Interval), "Interval not supported");
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
if (MaxAge.HasValue && request.StartTime < DateTime.UtcNow.Add(-MaxAge.Value))
return ArgumentError.Invalid(nameof(GetKlinesRequest.StartTime), $"Only the most recent {MaxAge} klines are available");
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs
index 4d5ccbe..d125876 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetPositionHistoryOptions.cs
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Objects;
+using System;
using System.Text;
namespace CryptoExchange.Net.SharedApis
@@ -19,8 +20,22 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetPositionHistoryRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
}
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs
index 805e44f..41ceca5 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetTradeHistoryOptions.cs
@@ -25,6 +25,12 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetTradeHistoryRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
if (MaxAge.HasValue && request.StartTime < DateTime.UtcNow.Add(-MaxAge.Value))
return ArgumentError.Invalid(nameof(GetTradeHistoryRequest.StartTime), $"Only the most recent {MaxAge} trades are available");
diff --git a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs
index e95de79..4717cdc 100644
--- a/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Options/Endpoints/GetWithdrawalsOptions.cs
@@ -1,4 +1,5 @@
using CryptoExchange.Net.Objects;
+using System;
using System.Text;
namespace CryptoExchange.Net.SharedApis
@@ -19,8 +20,22 @@ namespace CryptoExchange.Net.SharedApis
///
public override Error? ValidateRequest(string exchange, GetWithdrawalsRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
{
- if (!TimePeriodFilterSupport && request.StartTime != null)
- return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.StartTime), $"Time filter is not supported");
+ if (!SupportsAscending && request.Direction == DataDirection.Ascending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Ascending direction is not supported");
+
+ if (!SupportsDescending && request.Direction == DataDirection.Descending)
+ return ArgumentError.Invalid(nameof(GetWithdrawalsRequest.Direction), $"Descending direction is not supported");
+
+ if (!TimePeriodFilterSupport)
+ {
+ // When going descending we can still allow startTime filter to limit the results
+ var now = DateTime.UtcNow;
+ if ((request.Direction != DataDirection.Descending && request.StartTime != null)
+ || (request.EndTime != null && now - request.EndTime > TimeSpan.FromSeconds(5)))
+ {
+ return ArgumentError.Invalid(nameof(GetDepositsRequest.StartTime), $"Time filter is not supported");
+ }
+ }
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
}
diff --git a/CryptoExchange.Net/SharedApis/Models/Pagination.cs b/CryptoExchange.Net/SharedApis/Models/Pagination.cs
index a7def01..1bd2b8a 100644
--- a/CryptoExchange.Net/SharedApis/Models/Pagination.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Pagination.cs
@@ -93,7 +93,13 @@ namespace CryptoExchange.Net.SharedApis
)
{
if (HasNextPage(resultCount, timestamps, requestStartTime, requestEndTime, limit, direction))
- return nextPageRequest();
+ {
+ var result = nextPageRequest();
+#warning correct?
+ result.StartTime ??= lastPaginationData.StartTime;
+ result.EndTime ??= lastPaginationData.EndTime;
+ return result;
+ }
if (maxTimespan != null)
{
@@ -143,7 +149,7 @@ namespace CryptoExchange.Net.SharedApis
public static PageRequest NextPageFromPage(PaginationParameters lastPaginationData)
{
- return new PageRequest { Page = lastPaginationData.Page + 1 };
+ return new PageRequest { Page = (lastPaginationData.Page ?? 1) + 1 };
}
public static PageRequest NextPageFromOffset(PaginationParameters lastPaginationData, int resultCount)
{
@@ -161,7 +167,7 @@ namespace CryptoExchange.Net.SharedApis
{
return new PageRequest { FromId = nextFromId };
}
- public static PageRequest NextPageFromTime(PaginationParameters lastPaginationData, DateTime lastTimestamp, bool setOtherTimeLimiter)
+ public static PageRequest NextPageFromTime(PaginationParameters lastPaginationData, DateTime lastTimestamp, bool setOtherTimeLimiter = true)
{
if (lastPaginationData.Direction == DataDirection.Ascending)
return new PageRequest { StartTime = lastTimestamp.AddMilliseconds(1), EndTime = setOtherTimeLimiter ? lastPaginationData.EndTime : null };
diff --git a/CryptoExchange.Net/SharedApis/Models/Rest/GetTradeHistoryRequest.cs b/CryptoExchange.Net/SharedApis/Models/Rest/GetTradeHistoryRequest.cs
index 1a19955..2eaea31 100644
--- a/CryptoExchange.Net/SharedApis/Models/Rest/GetTradeHistoryRequest.cs
+++ b/CryptoExchange.Net/SharedApis/Models/Rest/GetTradeHistoryRequest.cs
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
///
/// Filter by end time
///
- public DateTime EndTime { get; set; }
+ public DateTime? EndTime { get; set; }
///
/// Max number of results
///
@@ -33,7 +33,7 @@ namespace CryptoExchange.Net.SharedApis
/// Max number of results
/// Data direction
/// Exchange specific parameters
- public GetTradeHistoryRequest(SharedSymbol symbol, DateTime startTime, DateTime endTime, int? limit = null, DataDirection? direction = null, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
+ public GetTradeHistoryRequest(SharedSymbol symbol, DateTime startTime, DateTime? endTime = null, int? limit = null, DataDirection? direction = null, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
{
StartTime = startTime;
EndTime = endTime;