diff --git a/data-api/csharp-rest/CoinAPI.REST.V1.Example/Program.cs b/data-api/csharp-rest/CoinAPI.REST.V1.Example/Program.cs index d1c0dcc14..e0a63a506 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1.Example/Program.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1.Example/Program.cs @@ -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; diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiEndpointUrls.cs b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiEndpointUrls.cs index 759181dc0..4fe1d798a 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiEndpointUrls.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiEndpointUrls.cs @@ -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); diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs index 45da2ca5e..8e19e7f48 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestClient.cs @@ -39,12 +39,13 @@ private async Task GetData(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(response).ConfigureAwait(false); + return await Deserialize(response).ConfigureAwait(false); + } } } } @@ -291,7 +292,11 @@ public Task Orderbooks_current_data_symbolAsync(string symbolId) var url = CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId); return GetData(url); } - + public Task Orderbooks_current_data_symbolAsync(string symbolId, int limit) + { + var url = CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId, limit); + return GetData(url); + } public Task> Orderbooks_last_dataAsync(string symbolId, int limit) { var url = CoinApiEndpointUrls.Orderbooks_LatestData(symbolId, limit); diff --git a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestEndpointsTester.cs b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestEndpointsTester.cs index c2cbcf814..0a67a7977 100644 --- a/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestEndpointsTester.cs +++ b/data-api/csharp-rest/CoinAPI.REST.V1/CoinApiRestEndpointsTester.cs @@ -126,6 +126,10 @@ public Task> Orderbooks_current_data_symbolAsync( { return HandleCheck(CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId), _coinApi.Orderbooks_current_data_symbolAsync(symbolId)); } + public Task> Orderbooks_current_data_symbolAsync(string symbolId, int limit) + { + return HandleCheck(CoinApiEndpointUrls.Orderbooks_CurrentSymbol(symbolId, 10), _coinApi.Orderbooks_current_data_symbolAsync(symbolId, 10)); + } public Task>> Orderbooks_last_dataAsync(string symbolId) {