Skip to content

Commit

Permalink
Orderbook current limit request added; using In HttpResponseMessage (#…
Browse files Browse the repository at this point in the history
…183)

Co-authored-by: kgrudzien <k.grudzien@eot.pl>
  • Loading branch information
kgrudzien and kgrudzien authored Jun 25, 2024
1 parent 7b42d1f commit 8454a73
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
35 changes: 35 additions & 0 deletions data-api/csharp-rest/CoinAPI.REST.V1.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,41 @@ static void Main(string[] args)
Console.Write("--------------------------------------------------------------------------------------------------------");
Console.Write(Environment.NewLine);

Console.Write("Orderbooks current data symbol (limit 10):");
Console.Write(Environment.NewLine);
var orderbooks_current_data_btc_usd_2 = coinApiEndpointTester.Orderbooks_current_data_symbolAsync(symbolId, 10).GetAwaiter().GetResult().Data;
Console.Write("symbol_id:" + orderbooks_current_data_btc_usd_2.symbol_id);
Console.Write(Environment.NewLine);
Console.Write("time_exchange:" + orderbooks_current_data_btc_usd.time_exchange);
Console.Write(Environment.NewLine);
Console.Write("time_coinapi:" + orderbooks_current_data_btc_usd_2.time_coinapi);
Console.Write(Environment.NewLine);

Console.Write("Asks:");
Console.Write(Environment.NewLine);
foreach (var itm in orderbooks_current_data_btc_usd_2.asks)
{
Console.Write("price:" + itm.price);
Console.Write(Environment.NewLine);
Console.Write("size:" + itm.size);
Console.Write(Environment.NewLine);

}
Console.Write("Bids:");
Console.Write(Environment.NewLine);
foreach (var itm in orderbooks_current_data_btc_usd_2.bids)
{
Console.Write("price:" + itm.price);
Console.Write(Environment.NewLine);
Console.Write("size:" + itm.size);
Console.Write(Environment.NewLine);

}

Console.Write("--------------------------------------------------------------------------------------------------------");
Console.Write(Environment.NewLine);


Console.Write("Orderbooks last data:");
Console.Write(Environment.NewLine);
var orderbooks_latest_data_btc_usd = coinApiEndpointTester.Orderbooks_last_dataAsync(symbolId).GetAwaiter().GetResult().Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static class CoinApiEndpointUrls
public static string Quotes_HistoricalData(string symbolId, string start, int limit) => string.Format("/v1/quotes/{0}/history?time_start={1}&limit={2}", symbolId, start, limit);
public static string Orderbooks_CurrentFilteredBitstamp() => "/v1/orderbooks/current?filter_symbol_id=BITSTAMP";
public static string Orderbooks_CurrentSymbol(string symbolId) => string.Format("/v1/orderbooks/{0}/current", symbolId);
public static string Orderbooks_CurrentSymbol(string symbolId, int limit) => string.Format("/v1/orderbooks/{0}/current?limit={1}", symbolId, limit);
public static string Orderbooks_LatestData(string symbolId, int limit) => string.Format("/v1/orderbooks/{0}/latest?limit={1}", symbolId, limit);
public static string Orderbooks_LatestData(string symbolId) => string.Format("/v1/orderbooks/{0}/latest", symbolId);
public static string Orderbooks_HistoricalData(string symbolId, string start, string end, int limit) => string.Format("/v1/orderbooks/{0}/history?time_start={1}&time_end={2}&limit={3}", symbolId, start, end, limit);
Expand Down
17 changes: 11 additions & 6 deletions data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ private async Task<T> GetData<T>(string url)
{
client.DefaultRequestHeaders.Add("X-CoinAPI-Key", apikey);

HttpResponseMessage response = await client.GetAsync(WebUrl + url).ConfigureAwait(false);
using (HttpResponseMessage response = await client.GetAsync(WebUrl + url).ConfigureAwait(false))
{
if (!response.IsSuccessStatusCode)
await RaiseError(response).ConfigureAwait(false);

if (!response.IsSuccessStatusCode)
await RaiseError(response).ConfigureAwait(false);

return await Deserialize<T>(response).ConfigureAwait(false);
return await Deserialize<T>(response).ConfigureAwait(false);
}
}
}
}
Expand Down Expand Up @@ -291,7 +292,11 @@ public Task<Orderbook> Orderbooks_current_data_symbolAsync(string symbolId)
var url = CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId);
return GetData<Orderbook>(url);
}

public Task<Orderbook> Orderbooks_current_data_symbolAsync(string symbolId, int limit)
{
var url = CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId, limit);
return GetData<Orderbook>(url);
}
public Task<List<Orderbook>> Orderbooks_last_dataAsync(string symbolId, int limit)
{
var url = CoinApiEndpointUrls.Orderbooks_LatestData(symbolId, limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public Task<EndpointCheckResult<Orderbook>> Orderbooks_current_data_symbolAsync(
{
return HandleCheck(CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId), _coinApi.Orderbooks_current_data_symbolAsync(symbolId));
}
public Task<EndpointCheckResult<Orderbook>> Orderbooks_current_data_symbolAsync(string symbolId, int limit)
{
return HandleCheck(CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId, 10), _coinApi.Orderbooks_current_data_symbolAsync(symbolId, 10));
}

public Task<EndpointCheckResult<List<Orderbook>>> Orderbooks_last_dataAsync(string symbolId)
{
Expand Down

0 comments on commit 8454a73

Please sign in to comment.