-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
247 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using CryptoExchange.Net.Authentication; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
|
||
namespace CoinGecko.Net.Objects | ||
{ | ||
/// <summary> | ||
/// CoinGecko API credentials | ||
/// </summary> | ||
public class CoinGeckoApiCredentials : ApiCredentials | ||
{ | ||
/// <summary> | ||
/// Wheter using a demo key | ||
/// </summary> | ||
public bool DemoKey { get; } | ||
|
||
/// <summary> | ||
/// ctor | ||
/// </summary> | ||
/// <param name="apiKey">The API key</param> | ||
/// <param name="demoKey">Whether or not this is a demo key</param> | ||
public CoinGeckoApiCredentials(string apiKey, bool demoKey = false) : base(apiKey, "-") | ||
{ | ||
DemoKey = demoKey; | ||
} | ||
|
||
/// <summary> | ||
/// Copy | ||
/// </summary> | ||
/// <returns></returns> | ||
public override ApiCredentials Copy() | ||
{ | ||
return new CoinGeckoApiCredentials(Key, DemoKey); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters