Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orderbook current limit request added; using In HttpResponseMessage #183

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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