-
Notifications
You must be signed in to change notification settings - Fork 1
/
Quotation.Market.cs
81 lines (61 loc) · 2.17 KB
/
Quotation.Market.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
using Newtonsoft.Json;
using RestSharp;
using ShareInvest.Binance.Converters;
using ShareInvest.Binance.Models;
using System.Net;
namespace ShareInvest.Binance;
public partial class Quotation
{
public override async Task<RestResponse> GetMarketAsync(bool exchangeInfo = true)
{
return await ExecuteAsync(new RestRequest(nameof(exchangeInfo)), cts.Token);
}
public async Task<ExchangeInfo?> GetMarketAsync()
{
var response = await GetMarketAsync(true);
return deserializeContent(response);
}
public async Task<ExchangeInfo?> GetMarketAsync(string[]? permissions = null, params string[] symbols)
{
if (symbols.Length == 1)
{
var res = await GetMarketAsync(symbols[0], permissions: permissions ?? []);
return res;
}
if (symbols.Length == 0)
{
return null;
}
var resource = $"exchangeInfo?{nameof(symbols)}={makeStrArrQuery(symbols)}";
if (permissions?.Length > 0)
{
resource = RebuildQuery(resource, permissions);
}
return deserializeContent(await ExecuteAsync(new RestRequest(resource), cts.Token));
}
public async Task<ExchangeInfo?> GetMarketAsync(string symbol, params string[]? permissions)
{
var res = await ExecuteAsync(new RestRequest(RebuildQuery($"exchangeInfo?{nameof(symbol)}={symbol}", permissions)), cts.Token);
if (HttpStatusCode.OK != res.StatusCode || string.IsNullOrEmpty(res.Content))
{
return null;
}
return JsonConvert.DeserializeObject<ExchangeInfo>(res.Content, new JsonSerializerSettings
{
Converters = new[] { new FilterConverter() }
});
}
string RebuildQuery(string resource, string[]? permissions)
{
if (permissions == null || permissions.Length == 0)
{
return resource;
}
resource = string.Concat(resource, '&', nameof(permissions), '=');
if (permissions.Length > 1)
{
return string.Concat(resource, makeStrArrQuery(permissions));
}
return string.Concat(resource, permissions[0]);
}
}