From e362543a1b5f72ee77a68bedf17408e283acf46a Mon Sep 17 00:00:00 2001 From: JKorf Date: Wed, 17 Apr 2024 09:50:17 +0200 Subject: [PATCH 1/2] wip --- CoinGecko.Net.UnitTests/JsonTests.cs | 1 - .../Clients/CoinGeckoRestClientApi.cs | 72 +++++++++---------- CoinGecko.Net/CoinGecko.Net.csproj | 4 +- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/CoinGecko.Net.UnitTests/JsonTests.cs b/CoinGecko.Net.UnitTests/JsonTests.cs index 5fa362a..3250331 100644 --- a/CoinGecko.Net.UnitTests/JsonTests.cs +++ b/CoinGecko.Net.UnitTests/JsonTests.cs @@ -15,7 +15,6 @@ public class JsonTests { x.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "123"); x.ApiOptions.OutputOriginalData = true; - x.ApiOptions.RateLimiters = new List(); }, System.Net.HttpStatusCode.OK)); diff --git a/CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs b/CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs index 964c8b3..b6e91c6 100644 --- a/CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs +++ b/CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs @@ -36,7 +36,7 @@ internal CoinGeckoRestClientApi(ILogger logger, HttpClient? httpClient, CoinGeck public async Task> PingAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - var result = await SendRequestAsync>(GetUrl("api/v3/ping"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + var result = await SendRequestAsync>(GetUrl("api/v3/ping"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); if (!result) return result.As(default); @@ -53,7 +53,7 @@ public async Task>> GetAssetsAsync(boo var parameters = new Dictionary(); parameters.AddOptionalParameter("includePlatform", includePlatform); - return await SendRequestAsync>(GetUrl("api/v3/coins/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl("api/v3/coins/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -82,7 +82,7 @@ public async Task>> GetMarketsAsync( parameters.AddOptionalParameter("sparkline", sparkline); parameters.AddOptionalParameter("price_change_percentage", priceChangePercentages == null ? null : string.Join(", ", priceChangePercentages)); - return await SendRequestAsync>(GetUrl("api/v3/coins/markets"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl("api/v3/coins/markets"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -108,7 +108,7 @@ public async Task> GetAssetDetailsAsync( parameters.AddOptionalParameter("developer_data", developerData); parameters.AddOptionalParameter("sparkline", sparkline); - return await SendRequestAsync(GetUrl("api/v3/coins/" + assetId), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl("api/v3/coins/" + assetId), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -132,7 +132,7 @@ public async Task> GetTickersAsync( parameters.AddOptionalParameter("order", order); parameters.AddOptionalParameter("depth", depth); - return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/tickers"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/tickers"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -150,7 +150,7 @@ public async Task> GetAssetHistoryAsync( parameters.AddParameter("date", date.ToString("dd-MM-yyyy")); parameters.AddOptionalParameter("localization", localization); - return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/history"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/history"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -170,7 +170,7 @@ public async Task> GetMarketChartAsync( parameters.AddParameter("days", days); parameters.AddOptionalParameter("interval", interval); - return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/market_chart"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/market_chart"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -190,7 +190,7 @@ public async Task> GetMarketChartAsync( parameters.AddParameter("from", DateTimeConverter.ConvertToSeconds(from)); parameters.AddParameter("to", DateTimeConverter.ConvertToSeconds(to)); - return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/market_chart/range"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl("api/v3/coins/" + coinId + "/market_chart/range"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -208,7 +208,7 @@ public async Task>> GetOhlcAsync( parameters.AddParameter("vs_currency", quoteAsset); parameters.AddParameter("days", days); - return await SendRequestAsync>(GetUrl("api/v3/coins/" + coinId + "/ohlc"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl("api/v3/coins/" + coinId + "/ohlc"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -234,7 +234,7 @@ public async Task>> GetOhlcAsync( parameters.AddOptionalParameter("include_24hr_change", include24hrChange); parameters.AddOptionalParameter("include_last_updated_at", includeLastUpdatedAt); parameters.AddOptionalParameter("precision", precision); - return await SendRequestAsync>>(GetUrl("api/v3/simple/price"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>>(GetUrl("api/v3/simple/price"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -260,7 +260,7 @@ public async Task>> GetOhlcAsync( parameters.AddOptionalParameter("include_24hr_change", include24hrChange); parameters.AddOptionalParameter("include_last_updated_at", includeLastUpdatedAt); parameters.AddOptionalParameter("precision", precision); - return await SendRequestAsync>>(GetUrl("api/v3/simple/token_price/" + platformId), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>>(GetUrl("api/v3/simple/token_price/" + platformId), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -271,7 +271,7 @@ public async Task>> GetOhlcAsync( public async Task>> GetQuoteAssetsAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync>(GetUrl("api/v3/simple/supported_vs_currencies"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl("api/v3/simple/supported_vs_currencies"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -282,7 +282,7 @@ public async Task>> GetQuoteAssetsAsync(Cancel public async Task> GetAssetDetailsFromContractAsync(string id, string contractAddress, CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/coins/{id}/contract/{contractAddress}"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/coins/{id}/contract/{contractAddress}"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -301,7 +301,7 @@ public async Task> GetMarketChartFromContrac parameters.AddParameter("vs_currency", quoteAsset); parameters.AddParameter("days", days); - return await SendRequestAsync(GetUrl($"api/v3/coins/{coinId}/contract/{contractAddress}/market_chart"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/coins/{coinId}/contract/{contractAddress}/market_chart"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -322,7 +322,7 @@ public async Task> GetMarketChartFromContrac parameters.AddParameter("from", DateTimeConverter.ConvertToSeconds(from)); parameters.AddParameter("to", DateTimeConverter.ConvertToSeconds(to)); - return await SendRequestAsync(GetUrl($"api/v3/coins/{coinId}/contract/{contractAddress}/market_chart/range"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/coins/{coinId}/contract/{contractAddress}/market_chart/range"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -337,7 +337,7 @@ public async Task>> GetAssetPl var parameters = new Dictionary(); parameters.AddOptionalParameter("filter", filter); - return await SendRequestAsync>(GetUrl($"api/v3/asset_platforms"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/asset_platforms"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -348,7 +348,7 @@ public async Task>> GetAssetPl public async Task>> GetAssetCategoriesAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync>(GetUrl($"api/v3/coins/categories/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/coins/categories/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -360,7 +360,7 @@ public async Task>> GetMa { var parameters = new Dictionary(); parameters.AddOptionalParameter("order", order); - return await SendRequestAsync>(GetUrl($"api/v3/coins/categories"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/coins/categories"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -373,7 +373,7 @@ public async Task>> GetExchangesAsy var parameters = new Dictionary(); parameters.AddOptionalParameter("per_page", pageSize); parameters.AddOptionalParameter("page", page); - return await SendRequestAsync>(GetUrl($"api/v3/exchanges"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/exchanges"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -384,7 +384,7 @@ public async Task>> GetExchangesAsy public async Task>> GetExchangeMarketsAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync>(GetUrl($"api/v3/exchanges/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/exchanges/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -395,7 +395,7 @@ public async Task>> GetExchangeMark public async Task> GetExchangeDetailsAsync(string exchangeId, CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/exchanges/{exchangeId}"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/exchanges/{exchangeId}"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -410,7 +410,7 @@ public async Task> GetExchangeTickersAsync(strin parameters.AddOptionalParameter("page", page); parameters.AddOptionalParameter("depth", depth); parameters.AddOptionalParameter("order", order); - return await SendRequestAsync(GetUrl($"api/v3/exchanges/{exchangeId}/tickers"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/exchanges/{exchangeId}/tickers"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -421,7 +421,7 @@ public async Task>> GetExch { var parameters = new Dictionary(); parameters.AddParameter("days", days); - return await SendRequestAsync>(GetUrl($"api/v3/exchanges/{exchangeId}/volume_chart"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/exchanges/{exchangeId}/volume_chart"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -432,7 +432,7 @@ public async Task>> GetDerivative { var parameters = new Dictionary(); parameters.AddOptionalParameter("include_tickers", includeTickers); - return await SendRequestAsync>(GetUrl($"api/v3/derivatives"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/derivatives"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -445,7 +445,7 @@ public async Task>> GetEx parameters.AddOptionalParameter("page", page); parameters.AddOptionalParameter("pageSize", pageSize); parameters.AddOptionalParameter("order", order); - return await SendRequestAsync>(GetUrl($"api/v3/derivatives/exchanges"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/derivatives/exchanges"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -455,7 +455,7 @@ public async Task>> GetEx public async Task>> GetDerivativesExchangesListAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync>(GetUrl($"api/v3/derivatives/exchanges/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/derivatives/exchanges/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -465,7 +465,7 @@ public async Task>> GetDerivativesE public async Task> GetBtcExchangeRatesAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/exchange_rates"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/exchange_rates"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -475,7 +475,7 @@ public async Task> GetBtcExchangeRatesAsyn public async Task> GetGlobalDataAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - var data = await SendRequestAsync(GetUrl($"api/v3/global"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + var data = await SendRequestAsync(GetUrl($"api/v3/global"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); if (!data) return data.As(null); @@ -489,7 +489,7 @@ public async Task> GetGlobalDataAsync(Cancell public async Task> GetGlobalDefiDataAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - var data = await SendRequestAsync(GetUrl($"api/v3/global/decentralized_finance_defi"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + var data = await SendRequestAsync(GetUrl($"api/v3/global/decentralized_finance_defi"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); if (!data) return data.As(null); @@ -507,7 +507,7 @@ public async Task>> GetNftsAsync(string? parameters.AddOptionalParameter("asset_platform_id", assetPlatformId); parameters.AddOptionalParameter("page", page); parameters.AddOptionalParameter("per_page", pageSize); - return await SendRequestAsync>(GetUrl($"api/v3/nfts/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/nfts/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -517,7 +517,7 @@ public async Task>> GetNftsAsync(string? public async Task> GetNftAsync(string id, CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/nfts/{id}"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/nfts/{id}"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -527,7 +527,7 @@ public async Task> GetNftAsync(string id, Can public async Task> GetNftByContractAddressAsync(string platformId, string contractAddress, CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/nfts/{platformId}/contract/{contractAddress}"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/nfts/{platformId}/contract/{contractAddress}"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -538,7 +538,7 @@ public async Task> SearchAsync(string query { var parameters = new Dictionary(); parameters.AddParameter("query", query); - return await SendRequestAsync(GetUrl($"api/v3/search"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/search"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -548,7 +548,7 @@ public async Task> SearchAsync(string query public async Task> GetTrendingSearchesAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync(GetUrl($"api/v3/search/trending"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync(GetUrl($"api/v3/search/trending"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -560,7 +560,7 @@ public async Task>> GetIndexesAsync(in var parameters = new Dictionary(); parameters.AddOptionalParameter("page", page); parameters.AddOptionalParameter("per_page", pageSize); - return await SendRequestAsync>(GetUrl($"api/v3/indexes"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/indexes"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion @@ -570,7 +570,7 @@ public async Task>> GetIndexesAsync(in public async Task>> GetIndexesListAsync(CancellationToken ct = default) { var parameters = new Dictionary(); - return await SendRequestAsync>(GetUrl($"api/v3/indexes/list"), HttpMethod.Get, ct, parameters).ConfigureAwait(false); + return await SendRequestAsync>(GetUrl($"api/v3/indexes/list"), HttpMethod.Get, ct, parameters, requestWeight: 0).ConfigureAwait(false); } #endregion diff --git a/CoinGecko.Net/CoinGecko.Net.csproj b/CoinGecko.Net/CoinGecko.Net.csproj index b3d73d7..11903fe 100644 --- a/CoinGecko.Net/CoinGecko.Net.csproj +++ b/CoinGecko.Net/CoinGecko.Net.csproj @@ -52,6 +52,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + + + \ No newline at end of file From 607b19b3cd7b89371bfd051d86160fd03d543024 Mon Sep 17 00:00:00 2001 From: JKorf Date: Wed, 17 Apr 2024 14:24:58 +0200 Subject: [PATCH 2/2] Update CoinGecko.Net.csproj --- CoinGecko.Net/CoinGecko.Net.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CoinGecko.Net/CoinGecko.Net.csproj b/CoinGecko.Net/CoinGecko.Net.csproj index 11903fe..1ec6d57 100644 --- a/CoinGecko.Net/CoinGecko.Net.csproj +++ b/CoinGecko.Net/CoinGecko.Net.csproj @@ -52,8 +52,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + \ No newline at end of file