diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinAPI.REST.V1.csproj b/data-api/csharp-rest/CoinAPI.REST.V1/CoinAPI.REST.V1.csproj index 5e8782d70..4ae630774 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinAPI.REST.V1.csproj +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinAPI.REST.V1.csproj @@ -16,7 +16,7 @@ LICENSE COINAPI LTD COINAPI LTD or its affiliates - 3.2.2 + 3.2.3 17704ec2-7050-452e-99b5-0eddf76dea5d diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs index 8e19e7f48..e77cc846f 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs @@ -10,43 +10,53 @@ namespace CoinAPI.REST.V1 { + public static class HttpClientFactory + { + private static readonly Dictionary clients = new Dictionary(); + + public static HttpClient GetClient(string apiKey) + { + if (!clients.TryGetValue(apiKey, out HttpClient client)) + { + var handler = new HttpClientHandler + { + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate + }; + client = new HttpClient(handler); + client.DefaultRequestHeaders.Add("X-CoinAPI-Key", apiKey); + clients[apiKey] = client; + } + return client; + } + } public class CoinApiRestClient - { - private string apikey; + { + private string apiKey; public string DateFormat => "yyyy-MM-ddTHH:mm:ss.fff"; private string WebUrl = "https://rest.coinapi.io"; public CoinApiRestClient(string apikey) { - this.apikey = apikey; - this.WebUrl = WebUrl.TrimEnd('/'); + apiKey = apikey; + WebUrl = WebUrl.TrimEnd('/'); } public CoinApiRestClient(string apikey, string url) { - this.apikey = apikey; - this.WebUrl = url.TrimEnd('/'); + apiKey = apikey; + WebUrl = url.TrimEnd('/'); } private async Task GetData(string url) { try { - using (var handler = new HttpClientHandler()) + using (HttpResponseMessage response = await HttpClientFactory.GetClient(apiKey).GetAsync(WebUrl + url).ConfigureAwait(false)) { - handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; - using (var client = new HttpClient(handler, false)) - { - client.DefaultRequestHeaders.Add("X-CoinAPI-Key", apikey); - - using (HttpResponseMessage response = await client.GetAsync(WebUrl + url).ConfigureAwait(false)) - { - if (!response.IsSuccessStatusCode) - await RaiseError(response).ConfigureAwait(false); - - return await Deserialize(response).ConfigureAwait(false); - } - } + if (!response.IsSuccessStatusCode) + await RaiseError(response).ConfigureAwait(false); + + return await Deserialize(response).ConfigureAwait(false); } } catch (CoinApiException) @@ -113,7 +123,6 @@ public Task> Metadata_list_symbols_exchangeAsync(string exchangeId) { return GetData>(CoinApiEndpointUrls.Symbols(exchangeId)); } - public Task> Metadata_list_assets_iconsAsync(int iconSize) { return GetData>(CoinApiEndpointUrls.Assests_Icons(iconSize)); diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/DataModels/SymbolSlim.cs b/data-api/csharp-rest/CoinAPI.REST.V1/DataModels/SymbolSlim.cs new file mode 100644 index 000000000..1495a3a74 --- /dev/null +++ b/data-api/csharp-rest/CoinAPI.REST.V1/DataModels/SymbolSlim.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoinAPI.REST.V1 { + public class SymbolSlim { + public string symbol_id { get; set; } + public string exchange_id { get; set; } + public string symbol_type { get; set; } + public string asset_id_base { get; set; } + public string asset_id_quote { get; set; } + public decimal? price { get; set; } + public string symbol_id_exchange { get; set; } + public string asset_id_base_exchange { get; set; } + public string asset_id_quote_exchange { get; set; } + public decimal? price_precision { get; set; } + public decimal? size_precision { get; set; } + } +}