Skip to content

Commit

Permalink
Merge pull request #185 from coinapi/orderbook-current-limit-request
Browse files Browse the repository at this point in the history
Orderbook current limit request
  • Loading branch information
kgrudzien authored Jun 25, 2024
2 parents 857f2b8 + ea8e18a commit cbfe5a4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Company>COINAPI LTD</Company>
<Copyright>COINAPI LTD or its affiliates</Copyright>
<Version>3.2.2</Version>
<Version>3.2.3</Version>
<UserSecretsId>17704ec2-7050-452e-99b5-0eddf76dea5d</UserSecretsId>
</PropertyGroup>

Expand Down
51 changes: 30 additions & 21 deletions data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,53 @@

namespace CoinAPI.REST.V1
{
public static class HttpClientFactory
{
private static readonly Dictionary<string, HttpClient> clients = new Dictionary<string, HttpClient>();

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<T> GetData<T>(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<T>(response).ConfigureAwait(false);
}
}
if (!response.IsSuccessStatusCode)
await RaiseError(response).ConfigureAwait(false);

return await Deserialize<T>(response).ConfigureAwait(false);
}
}
catch (CoinApiException)
Expand Down Expand Up @@ -113,7 +123,6 @@ public Task<List<Symbol>> Metadata_list_symbols_exchangeAsync(string exchangeId)
{
return GetData<List<Symbol>>(CoinApiEndpointUrls.Symbols(exchangeId));
}

public Task<List<Icon>> Metadata_list_assets_iconsAsync(int iconSize)
{
return GetData<List<Icon>>(CoinApiEndpointUrls.Assests_Icons(iconSize));
Expand Down
21 changes: 21 additions & 0 deletions data-api/csharp-rest/CoinAPI.REST.V1/DataModels/SymbolSlim.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}

0 comments on commit cbfe5a4

Please sign in to comment.