forked from alpacahq/alpaca-trade-api-csharp
/
LatestDataListRequest.cs
65 lines (58 loc) · 2.36 KB
/
LatestDataListRequest.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
namespace Alpaca.Markets;
/// <summary>
/// Encapsulates data for latest crypto data requests on Alpaca Data API v2.
/// </summary>
public sealed class LatestDataListRequest : Validation.IRequest
{
private readonly HashSet<String> _symbols = new(StringComparer.Ordinal);
/// <summary>
/// Creates new instance of <see cref="LatestDataListRequest"/> object.
/// </summary>
/// <param name="symbols">Asset symbol for data retrieval.</param>
/// <exception cref="ArgumentNullException">
/// The <paramref name="symbols"/> argument is <c>null</c>.
/// </exception>
public LatestDataListRequest(
IEnumerable<String> symbols) =>
_symbols.UnionWith(symbols.EnsureNotNull());
/// <summary>
/// Creates new instance of <see cref="LatestDataListRequest"/> object.
/// </summary>
/// <param name="symbols">Asset symbol for data retrieval.</param>
/// <param name="exchange">Crypto exchange for data retrieval.</param>
/// <exception cref="ArgumentNullException">
/// The <paramref name="symbols"/> argument is <c>null</c>.
/// </exception>
[ExcludeFromCodeCoverage]
[Obsolete("This constructor will be removed in the next major release of SDK.", true)]
public LatestDataListRequest(
IEnumerable<String> symbols,
CryptoExchange exchange)
: this(symbols) =>
Exchange = exchange;
/// <summary>
/// Gets asset symbols for data retrieval.
/// </summary>
[UsedImplicitly]
public IReadOnlyCollection<String> Symbols => _symbols;
/// <summary>
/// Gets crypto exchange for data retrieval.
/// </summary>
[UsedImplicitly]
[ExcludeFromCodeCoverage]
[Obsolete("This query parameter doesn't support anymore, the property will be removed in the next minor release of SDK.", true)]
public CryptoExchange Exchange { get; }
internal async ValueTask<UriBuilder> GetUriBuilderAsync(
HttpClient httpClient,
String lastPathSegment) =>
new UriBuilder(httpClient.BaseAddress!)
{
Query = await new QueryBuilder()
.AddParameter("symbols", Symbols)
.AsStringAsync().ConfigureAwait(false)
}.AppendPath($"latest/{lastPathSegment}");
IEnumerable<RequestValidationException?> Validation.IRequest.GetExceptions()
{
yield return Symbols.TryValidateSymbolName();
}
}