Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Nov 11, 2024
1 parent b044d02 commit 0243116
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 419 deletions.
34 changes: 29 additions & 5 deletions CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using CryptoExchange.Net;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Converters;
using CryptoExchange.Net.Converters.MessageParsing;
using CryptoExchange.Net.Converters.SystemTextJson;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.SharedApis;
Expand Down Expand Up @@ -620,6 +618,28 @@ public async Task<WebCallResult<CoinGeckoTrendingSearch>> GetTrendingSearchesAsy

#endregion

#region Get Company Holdings

/// <inheritdoc />
public async Task<WebCallResult<CoinGeckoCompanyHolding>> GetCompanyHoldingsAsync(string asset, CancellationToken ct = default)
{
var request = _definitions.GetOrCreate(HttpMethod.Get, $"/api/v3/companies/public_treasury/{asset}", CoinGeckoApi.RateLimiter.CoinGecko, 1, false);
var result = await SendAsync<CoinGeckoCompanyHolding>(GetBaseAddress(), request, null, ct).ConfigureAwait(false);
return result;
}

#endregion

#region Get Api Usage
/// <inheritdoc />
public async Task<WebCallResult<CoinGeckoApiUsage>> GetApiUsageAsync(CancellationToken ct = default)
{
var request = _definitions.GetOrCreate(HttpMethod.Get, $"api/v3/key", CoinGeckoApi.RateLimiter.CoinGecko, 1, true);
return await SendAsync<CoinGeckoApiUsage>(GetBaseAddress(), request, null, ct).ConfigureAwait(false);
}

#endregion

protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable<KeyValuePair<string, IEnumerable<string>>> responseHeaders, IMessageAccessor accessor)
{
if (!accessor.IsJson)
Expand All @@ -628,10 +648,14 @@ protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable<KeyV
var code = accessor.GetValue<int?>(MessagePath.Get().Property("error_code"));
var msg = accessor.GetValue<string?>(MessagePath.Get().Property("status").Property("error_message"));

if (code == null || msg == null)
return new ServerError(httpStatusCode, accessor.GetOriginalString());
if (code != null && msg != null)
return new ServerError(code.Value, msg);

code = accessor.GetValue<int?>(MessagePath.Get().Property("status").Property("error_code"));
if (code != null && msg != null)
return new ServerError(code.Value, msg);

return new ServerError(code.Value, msg);
return new ServerError(httpStatusCode, accessor.GetOriginalString());
}

private string GetBaseAddress()
Expand Down
292 changes: 117 additions & 175 deletions CoinGecko.Net/CoinGecko.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions CoinGecko.Net/CoinGeckoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ private void Initialize()
CoinGecko.RateLimitTriggered += (x) => RateLimitTriggered?.Invoke(x);
}


internal IRateLimitGate CoinGecko { get; private set; }

}
}
Loading

0 comments on commit 0243116

Please sign in to comment.