forked from alpacahq/alpaca-trade-api-csharp
/
PortfolioHistoryRequest.cs
87 lines (79 loc) · 3.21 KB
/
PortfolioHistoryRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace Alpaca.Markets;
/// <summary>
/// Encapsulates request parameters for <see cref="IAlpacaTradingClient.GetPortfolioHistoryAsync(PortfolioHistoryRequest,CancellationToken)"/> call.
/// </summary>
[UsedImplicitly]
public sealed class PortfolioHistoryRequest
{
/// <summary>
/// Gets inclusive date interval for filtering items in response.
/// </summary>
[UsedImplicitly]
[ExcludeFromCodeCoverage]
[Obsolete("Use the DateInterval property instead of this one.", true)]
public Interval<DateTime> TimeInterval => DateInterval.AsTimeInterval();
/// <summary>
/// Gets inclusive date interval for filtering items in response.
/// </summary>
[UsedImplicitly]
public Interval<DateOnly> DateInterval { get; private set; }
/// <summary>
/// Gets or sets the time frame value for desired history. Default value (if <c>null</c>) is 1 minute
/// for a period shorter than 7 days, 15 minutes for a period less than 30 days, or 1 day for a longer period.
/// </summary>
[UsedImplicitly]
public TimeFrame? TimeFrame { get; set; }
/// <summary>
/// Gets or sets period value for desired history. Default value (if <c>null</c>) is 1 month.
/// </summary>
[UsedImplicitly]
public HistoryPeriod? Period { get; set; }
/// <summary>
/// Gets or sets flags, indicating that include extended hours included in the result.
/// This is effective only for time frame less than 1 day.
/// </summary>
[UsedImplicitly]
public Boolean? ExtendedHours { get; set; }
internal async ValueTask<UriBuilder> GetUriBuilderAsync(
HttpClient httpClient) =>
new(httpClient.BaseAddress!)
{
Path = "v2/account/portfolio/history",
Query = await new QueryBuilder()
.AddParameter("start_date", DateInterval.From)
.AddParameter("end_date", DateInterval.Into)
.AddParameter("period", Period?.ToString())
// ReSharper disable once StringLiteralTypo
.AddParameter("timeframe", TimeFrame)
.AddParameter("extended_hours", ExtendedHours)
.AsStringAsync().ConfigureAwait(false)
};
/// <summary>
/// Sets time interval for filtering data returned by this request.
/// /// </summary>
/// <param name="value">New filtering interval.</param>
/// <returns>Request with applied filtering.</returns>
[UsedImplicitly]
[ExcludeFromCodeCoverage]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Obsolete("Use the override that gets Interval<DateOnly> instead of this one.", true)]
public PortfolioHistoryRequest WithInterval(
Interval<DateTime> value)
{
DateInterval = value.AsDateInterval();
return this;
}
/// <summary>
/// Sets time interval for filtering data returned by this request.
/// /// </summary>
/// <param name="value">New filtering interval.</param>
/// <returns>Request with applied filtering.</returns>
[UsedImplicitly]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public PortfolioHistoryRequest WithInterval(
Interval<DateOnly> value)
{
DateInterval = value;
return this;
}
}