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

Feature/system text json #13

Merged
merged 6 commits into from
Nov 11, 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
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
Loading