Skip to content

Commit

Permalink
Feature/system text json (#13)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JKorf authored Nov 11, 2024
1 parent 2727158 commit c2b7018
Show file tree
Hide file tree
Showing 56 changed files with 2,229 additions and 1,118 deletions.
39 changes: 0 additions & 39 deletions CoinGecko.Net.UnitTests/JsonTests.cs

This file was deleted.

293 changes: 187 additions & 106 deletions CoinGecko.Net/Clients/CoinGeckoRestClientApi.cs

Large diffs are not rendered by default.

1,049 changes: 730 additions & 319 deletions CoinGecko.Net/CoinGecko.Net.xml

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions CoinGecko.Net/CoinGeckoApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.RateLimiting.Filters;
using CryptoExchange.Net.RateLimiting.Guards;
using CryptoExchange.Net.RateLimiting.Interfaces;
using CryptoExchange.Net.RateLimiting;
using System;
using System.Collections.Generic;
using System.Text;
using CryptoExchange.Net.SharedApis;

namespace CoinGecko.Net
{
/// <summary>
/// CoinGecko information and configuration
/// </summary>
public static class CoinGeckoApi
{
/// <summary>
/// Url to the main website
/// </summary>
public static string Url { get; } = "https://www.coingecko.com";

/// <summary>
/// Urls to the API documentation
/// </summary>
public static string[] ApiDocsUrl { get; } = new[] {
"https://docs.coingecko.com/"
};

/// <summary>
/// Rate limiter configuration for the CoinGecko API
/// </summary>
public static CoinGeckoRateLimiters RateLimiter { get; } = new CoinGeckoRateLimiters();
}

/// <summary>
/// Rate limiter configuration for the CoinGecko API
/// </summary>
public class CoinGeckoRateLimiters
{
/// <summary>
/// Event for when a rate limit is triggered
/// </summary>
public event Action<RateLimitEvent> RateLimitTriggered;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
internal CoinGeckoRateLimiters()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
Initialize();
}

private void Initialize()
{
CoinGecko = new RateLimitGate("CoinGecko");
CoinGecko.RateLimitTriggered += (x) => RateLimitTriggered?.Invoke(x);
}

internal IRateLimitGate CoinGecko { get; private set; }
}
}
42 changes: 42 additions & 0 deletions CoinGecko.Net/CoinGeckoAuthenticationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using CoinGecko.Net.Objects;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Objects;

namespace CoinGecko.Net
{
internal class CoinGeckoAuthenticationProvider : AuthenticationProvider<CoinGeckoApiCredentials>
{
/// <summary>
/// Whether or not a demo key is configured
/// </summary>
public bool IsDemo => _credentials.DemoKey;

public CoinGeckoAuthenticationProvider(CoinGeckoApiCredentials credentials) : base(credentials)
{
}

public override void AuthenticateRequest(
RestApiClient apiClient,
Uri uri,
HttpMethod method,
ref IDictionary<string, object>? uriParameters,
ref IDictionary<string, object>? bodyParameters,
ref Dictionary<string, string>? headers,
bool auth,
ArrayParametersSerialization arraySerialization,
HttpMethodParameterPosition parameterPosition,
RequestBodyFormat requestBodyFormat)
{
uriParameters ??= new ParameterCollection();
if (_credentials.DemoKey)
uriParameters.Add("x_cg_demo_api_key", _credentials.Key);
else
uriParameters.Add("x_cg_pro_api_key", _credentials.Key);
}
}
}
24 changes: 15 additions & 9 deletions CoinGecko.Net/CoinGeckoEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,38 @@ namespace CoinGecko.Net
public class CoinGeckoEnvironment : TradeEnvironment
{
/// <summary>
/// Rest client address
/// Rest client address public API
/// </summary>
public string RestApiAddress { get; }
public string RestApiAddressPublic { get; }
/// <summary>
/// Rest client address pro API
/// </summary>
public string RestApiAddressPro { get; }

internal CoinGeckoEnvironment(string name,
string restBaseAddress) : base(name)
string restBaseAddressPublic,
string restBaseAddressPro) : base(name)
{
RestApiAddress = restBaseAddress;
RestApiAddressPublic = restBaseAddressPublic;
RestApiAddressPro = restBaseAddressPro;
}

/// <summary>
/// Live environment
/// </summary>
public static CoinGeckoEnvironment Live { get; }
= new CoinGeckoEnvironment(TradeEnvironmentNames.Live,
CoinGeckoApiAddresses.Default.RestClientAddress);
CoinGeckoApiAddresses.Default.RestClientAddressPublic,
CoinGeckoApiAddresses.Default.RestClientAddressPro);

/// <summary>
/// Create a custom environment
/// </summary>
/// <param name="name"></param>
/// <param name="restAddress"></param>
/// <returns></returns>
public static CoinGeckoEnvironment CreateCustom(
string name,
string restAddress)
=> new CoinGeckoEnvironment(name, restAddress);
string restAddressPublic,
string restAddressPro)
=> new CoinGeckoEnvironment(name, restAddressPublic, restAddressPro);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CoinGecko.Net.Objects.Options;
using CryptoExchange.Net.Clients;
using CryptoExchange.Net.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net;
using System.Net.Http;
Expand Down
Loading

0 comments on commit c2b7018

Please sign in to comment.