-
-
Notifications
You must be signed in to change notification settings - Fork 83
Time Intervals (Obsolete)
❗❗❗ This information is actual for SDK versions up to 5.x only. ❗❗❗
Starting from version 6.0 all these interfaces were marked as obsolete. Single struct Interval<T>
is used across all the SDK for representing both date-only and date-time intervals. It provides a similar approach for specifying start/end date/time points as original interfaces.
Many request methods provided by the Alpaca and Polygon REST API client classes allow us to filter data by time. There are two possible time interval types supported by the SDK:
- Inclusive - the start (
a
) and end (b
) time points are part of the interval. This time interval represented in the SDK via the Alpaca.Markets.IInclusiveTimeInterval interface. Formally speaking it denotes as[a … b]
interval and means - Exclusive - the start (
a
) and end (b
) time points are not part of the interval. This time interval represented in the SDK via the Alpaca.Markets.IExclusiveTimeInterval interface. Formally speaking it denotes as(a … b)
interval and means
The SDK contains the helper class Alpaca.Markets.TimeInterval that provides a set of factory and extension methods for handling different time intervals in the requests.
If you specify only a one-time point for the interval you create the open time interval. If you do not specify any time interval at all in the request you formally use the empty time interval. From the SDK perspective, the empty time interval is not the same as the interval with two open sides.
You are unable to create the ordinal (not open) time interval directly. Instead, you have to use fluent extension methods SetInclusiveTimeInterval and SetExclusiveTimeInterval that defined for all requests that supports time interval-based filtering. These methods get two System.DateTime values, construct the appropriate time interval object and apply it to the target request. If you want to specify an open time interval you can use one of these extension methods defined for the System.DateTime structure: GetInclusiveIntervalFromThat, GetInclusiveIntervalTillThat, GetExclusiveIntervalFromThat, and GetExclusiveIntervalTillThat. These methods construct the appropriate time interval object and you can apply the constructed object to the request using the fluent extension method SetTimeInterval defined for both types of intervals for all appropriate requests.
Requesting a list of all orders for the specified (exclusive) time interval. Please, note that you have to specify the Alpaca.Markets.OrderStatusFilter value explicitly in this case for receiving valid data from the server.
var orders = await _alpacaTradingClient
.ListOrdersAsync(new ListOrdersRequest
{
RollUpNestedOrders = true,
OrderStatusFilter = OrderStatusFilter.All,
OrderListSorting = SortDirection.Ascending
}.SetExclusiveTimeInterval(
new DateTime(2020, 10, 1),
new DateTime(2020, 10, 20)));