Skip to content

Commit c2b7018

Browse files
authored
Feature/system text json (#13)
Switched json (de)serialization from Newtonsoft.Json to System.Text.Json Added support for setting API key Added error parsing implementation Added pro API endpoint to CoinGeckoEnvironment Added GetMarketsAsync endpoint Added GetCompanyHoldingsAsync endpoint Added GetExchangeDerivativesDetailsAsync endpoint Added GetApiUsageAsync endpoint Added precision parameter to GetMarketChartAsync, GetOhlcAsync Updated response models Updated API doc references Removed includeTickers parameter from GetDerivativesAsync endpoint Removed assetPlatformId parameter from GetNftsAsync endpoint
1 parent 2727158 commit c2b7018

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2229
-1118
lines changed

CoinGecko.Net.UnitTests/JsonTests.cs

-39
This file was deleted.

CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs

+187-106
Large diffs are not rendered by default.

CoinGecko.Net/CoinGecko.Net.xml

+730-319
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CoinGecko.Net/CoinGeckoApi.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using CryptoExchange.Net.Objects;
2+
using CryptoExchange.Net.RateLimiting.Filters;
3+
using CryptoExchange.Net.RateLimiting.Guards;
4+
using CryptoExchange.Net.RateLimiting.Interfaces;
5+
using CryptoExchange.Net.RateLimiting;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Text;
9+
using CryptoExchange.Net.SharedApis;
10+
11+
namespace CoinGecko.Net
12+
{
13+
/// <summary>
14+
/// CoinGecko information and configuration
15+
/// </summary>
16+
public static class CoinGeckoApi
17+
{
18+
/// <summary>
19+
/// Url to the main website
20+
/// </summary>
21+
public static string Url { get; } = "https://www.coingecko.com";
22+
23+
/// <summary>
24+
/// Urls to the API documentation
25+
/// </summary>
26+
public static string[] ApiDocsUrl { get; } = new[] {
27+
"https://docs.coingecko.com/"
28+
};
29+
30+
/// <summary>
31+
/// Rate limiter configuration for the CoinGecko API
32+
/// </summary>
33+
public static CoinGeckoRateLimiters RateLimiter { get; } = new CoinGeckoRateLimiters();
34+
}
35+
36+
/// <summary>
37+
/// Rate limiter configuration for the CoinGecko API
38+
/// </summary>
39+
public class CoinGeckoRateLimiters
40+
{
41+
/// <summary>
42+
/// Event for when a rate limit is triggered
43+
/// </summary>
44+
public event Action<RateLimitEvent> RateLimitTriggered;
45+
46+
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
47+
internal CoinGeckoRateLimiters()
48+
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
49+
{
50+
Initialize();
51+
}
52+
53+
private void Initialize()
54+
{
55+
CoinGecko = new RateLimitGate("CoinGecko");
56+
CoinGecko.RateLimitTriggered += (x) => RateLimitTriggered?.Invoke(x);
57+
}
58+
59+
internal IRateLimitGate CoinGecko { get; private set; }
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net.Http;
4+
using System.Text;
5+
using CoinGecko.Net.Objects;
6+
using CryptoExchange.Net.Authentication;
7+
using CryptoExchange.Net.Clients;
8+
using CryptoExchange.Net.Objects;
9+
10+
namespace CoinGecko.Net
11+
{
12+
internal class CoinGeckoAuthenticationProvider : AuthenticationProvider<CoinGeckoApiCredentials>
13+
{
14+
/// <summary>
15+
/// Whether or not a demo key is configured
16+
/// </summary>
17+
public bool IsDemo => _credentials.DemoKey;
18+
19+
public CoinGeckoAuthenticationProvider(CoinGeckoApiCredentials credentials) : base(credentials)
20+
{
21+
}
22+
23+
public override void AuthenticateRequest(
24+
RestApiClient apiClient,
25+
Uri uri,
26+
HttpMethod method,
27+
ref IDictionary<string, object>? uriParameters,
28+
ref IDictionary<string, object>? bodyParameters,
29+
ref Dictionary<string, string>? headers,
30+
bool auth,
31+
ArrayParametersSerialization arraySerialization,
32+
HttpMethodParameterPosition parameterPosition,
33+
RequestBodyFormat requestBodyFormat)
34+
{
35+
uriParameters ??= new ParameterCollection();
36+
if (_credentials.DemoKey)
37+
uriParameters.Add("x_cg_demo_api_key", _credentials.Key);
38+
else
39+
uriParameters.Add("x_cg_pro_api_key", _credentials.Key);
40+
}
41+
}
42+
}

CoinGecko.Net/CoinGeckoEnvironment.cs

+15-9
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,38 @@ namespace CoinGecko.Net
99
public class CoinGeckoEnvironment : TradeEnvironment
1010
{
1111
/// <summary>
12-
/// Rest client address
12+
/// Rest client address public API
1313
/// </summary>
14-
public string RestApiAddress { get; }
14+
public string RestApiAddressPublic { get; }
15+
/// <summary>
16+
/// Rest client address pro API
17+
/// </summary>
18+
public string RestApiAddressPro { get; }
1519

1620
internal CoinGeckoEnvironment(string name,
17-
string restBaseAddress) : base(name)
21+
string restBaseAddressPublic,
22+
string restBaseAddressPro) : base(name)
1823
{
19-
RestApiAddress = restBaseAddress;
24+
RestApiAddressPublic = restBaseAddressPublic;
25+
RestApiAddressPro = restBaseAddressPro;
2026
}
2127

2228
/// <summary>
2329
/// Live environment
2430
/// </summary>
2531
public static CoinGeckoEnvironment Live { get; }
2632
= new CoinGeckoEnvironment(TradeEnvironmentNames.Live,
27-
CoinGeckoApiAddresses.Default.RestClientAddress);
33+
CoinGeckoApiAddresses.Default.RestClientAddressPublic,
34+
CoinGeckoApiAddresses.Default.RestClientAddressPro);
2835

2936
/// <summary>
3037
/// Create a custom environment
3138
/// </summary>
32-
/// <param name="name"></param>
33-
/// <param name="restAddress"></param>
3439
/// <returns></returns>
3540
public static CoinGeckoEnvironment CreateCustom(
3641
string name,
37-
string restAddress)
38-
=> new CoinGeckoEnvironment(name, restAddress);
42+
string restAddressPublic,
43+
string restAddressPro)
44+
=> new CoinGeckoEnvironment(name, restAddressPublic, restAddressPro);
3945
}
4046
}

CoinGecko.Net/ExtensionMethods/ServiceCollectionExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using CoinGecko.Net.Objects.Options;
44
using CryptoExchange.Net.Clients;
55
using CryptoExchange.Net.Interfaces;
6-
using Microsoft.Extensions.DependencyInjection;
76
using System;
87
using System.Net;
98
using System.Net.Http;

0 commit comments

Comments
 (0)