1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 08:26:20 +00:00

Fixed api key storing in api key rate limitter

This commit is contained in:
Jkorf 2020-12-10 14:44:15 +01:00
parent df9d09630a
commit dd06f48fc1
2 changed files with 248 additions and 154 deletions

View File

@ -441,6 +441,36 @@
<member name="M:CryptoExchange.Net.Converters.UTCDateTimeConverter.CanConvert(System.Type)">
<inheritdoc />
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade">
<summary>
Common trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade.CommonId">
<summary>
Id of the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade.CommonPrice">
<summary>
Price of the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade.CommonQuantity">
<summary>
Quantity of the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade.CommonFee">
<summary>
Fee paid for the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTrade.CommonFeeAsset">
<summary>
The asset fee was paid in
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient">
<summary>
Shared interface for exchange wrappers based on the CryptoExchange.Net package
@ -448,7 +478,7 @@
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetSymbolName(System.String,System.String)">
<summary>
Get the symbol name basset on a base and quote asset
Get the symbol name based on a base and quote asset
</summary>
<param name="baseAsset"></param>
<param name="quoteAsset"></param>
@ -497,7 +527,7 @@
<param name="type">The type of the order</param>
<param name="quantity">The quantity of the order</param>
<param name="price">The price of the order, only for limit orders</param>
<param name="accountId">[Optional] The account id to place the order on, required for some exchanges</param>
<param name="accountId">[Optional] The account id to place the order on, required for some exchanges, ignored otherwise</param>
<returns>The id of the resulting order</returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetOrderAsync(System.String,System.String)">
@ -505,7 +535,7 @@
Get an order by id
</summary>
<param name="orderId">The id</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetTradesAsync(System.String,System.String)">
@ -513,23 +543,21 @@
Get trades for an order by id
</summary>
<param name="orderId">The id</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetOpenOrdersAsync(System.String)">
<summary>
Get a list of open orders
</summary>
<param name="symbol">[Optional] The symbol to get open orders for, required for some exchanges. If the symbol is not required for the call,
the result will NOT be filtered by this</param>
<param name="symbol">[Optional] The symbol to get open orders for, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.GetClosedOrdersAsync(System.String)">
<summary>
Get a list of closed orders
</summary>
<param name="symbol">[Optional] The symbol to get closed orders for, required for some exchanges. If the symbol is not required for the call,
the result will NOT be filtered by this</param>
<param name="symbol">[Optional] The symbol to get closed orders for, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="M:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.CancelOrderAsync(System.String,System.String)">
@ -537,9 +565,194 @@
Cancel an order by id
</summary>
<param name="orderId">The id</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges</param>
<param name="symbol">[Optional] The symbol the order is on, required for some exchanges, ignored otherwise</param>
<returns></returns>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderType">
<summary>
Common order id
</summary>
</member>
<member name="F:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderType.Limit">
<summary>
Limit type
</summary>
</member>
<member name="F:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderType.Market">
<summary>
Market type
</summary>
</member>
<member name="F:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderType.Other">
<summary>
Other order type
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderSide">
<summary>
Common order side
</summary>
</member>
<member name="F:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderSide.Buy">
<summary>
Buy order
</summary>
</member>
<member name="F:CryptoExchange.Net.ExchangeInterfaces.IExchangeClient.OrderSide.Sell">
<summary>
Sell order
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonKline">
<summary>
Common kline
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonKline.CommonHigh">
<summary>
High price for this kline
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonKline.CommonLow">
<summary>
Low price for this kline
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonKline.CommonOpen">
<summary>
Open price for this kline
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonKline.CommonClose">
<summary>
Close price for this kline
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder">
<summary>
Common order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonSymbol">
<summary>
Symbol of the order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonPrice">
<summary>
Price of the order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonQuantity">
<summary>
Quantity of the order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonStatus">
<summary>
Status of the order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.IsActive">
<summary>
Whether the order is active
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonSide">
<summary>
Side of the order
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrder.CommonType">
<summary>
Type of the order
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonOrderBook">
<summary>
Common order book
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrderBook.CommonBids">
<summary>
Bids
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrderBook.CommonAsks">
<summary>
Asks
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonOrderId">
<summary>
Common order id
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonOrderId.CommonId">
<summary>
Id of the order
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonRecentTrade">
<summary>
Recent trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonRecentTrade.CommonPrice">
<summary>
Price of the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonRecentTrade.CommonQuantity">
<summary>
Quantity of the trade
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonRecentTrade.CommonTradeTime">
<summary>
Trade time
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonSymbol">
<summary>
Common symbol
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonSymbol.CommonName">
<summary>
Symbol name
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonSymbol.CommonMinimumTradeSize">
<summary>
Minimum trade size
</summary>
</member>
<member name="T:CryptoExchange.Net.ExchangeInterfaces.ICommonTicker">
<summary>
Common ticker
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTicker.CommonSymbol">
<summary>
Symbol name
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTicker.CommonHigh">
<summary>
High price
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTicker.CommonLow">
<summary>
Low price
</summary>
</member>
<member name="P:CryptoExchange.Net.ExchangeInterfaces.ICommonTicker.CommonVolume">
<summary>
Volume
</summary>
</member>
<member name="T:CryptoExchange.Net.ExtensionMethods">
<summary>
Helper methods
@ -2191,6 +2404,11 @@
<member name="M:CryptoExchange.Net.RateLimiter.RateLimiterAPIKey.LimitRequest(CryptoExchange.Net.RestClient,System.String,CryptoExchange.Net.Objects.RateLimitingBehaviour)">
<inheritdoc />
</member>
<member name="M:CryptoExchange.Net.RateLimiter.RateLimiterAPIKey.Dispose">
<summary>
Dispose
</summary>
</member>
<member name="T:CryptoExchange.Net.RateLimiter.RateLimiterPerEndpoint">
<summary>
Limits the amount of requests per time period to a certain limit, counts the request per endpoint.
@ -3187,148 +3405,5 @@
<member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})">
<inheritdoc />
</member>
<member name="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute">
<summary>
Specifies that <see langword="null"/> is allowed as an input even if the
corresponding type disallows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.AllowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute">
<summary>
Specifies that <see langword="null"/> is disallowed as an input even if the
corresponding type allows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DisallowNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DisallowNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute">
<summary>
Specifies that a method that will never return under any circumstance.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute">
<summary>
Specifies that the method will not return if the associated <see cref="T:System.Boolean"/>
parameter is passed the specified value.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.ParameterValue">
<summary>
Gets the condition parameter value.
Code after the method is considered unreachable by diagnostics if the argument
to the associated parameter matches this value.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute.#ctor(System.Boolean)">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute"/>
class with the specified parameter value.
</summary>
<param name="parameterValue">
The condition parameter value.
Code after the method is considered unreachable by diagnostics if the argument
to the associated parameter matches this value.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute">
<summary>
Specifies that an output may be <see langword="null"/> even if the
corresponding type disallows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.MaybeNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.MaybeNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute">
<summary>
Specifies that when a method returns <see cref="P:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.ReturnValue"/>,
the parameter may be <see langword="null"/> even if the corresponding type disallows it.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.ReturnValue">
<summary>
Gets the return value condition.
If the method returns this value, the associated parameter may be <see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute.#ctor(System.Boolean)">
<summary>
Initializes the attribute with the specified return value condition.
</summary>
<param name="returnValue">
The return value condition.
If the method returns this value, the associated parameter may be <see langword="null"/>.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullAttribute">
<summary>
Specifies that an output is not <see langword="null"/> even if the
corresponding type allows it.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullAttribute.#ctor">
<summary>
Initializes a new instance of the <see cref="T:System.Diagnostics.CodeAnalysis.NotNullAttribute"/> class.
</summary>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute">
<summary>
Specifies that the output will be non-<see langword="null"/> if the
named parameter is non-<see langword="null"/>.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.ParameterName">
<summary>
Gets the associated parameter name.
The output will be non-<see langword="null"/> if the argument to the
parameter specified is non-<see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute.#ctor(System.String)">
<summary>
Initializes the attribute with the associated parameter name.
</summary>
<param name="parameterName">
The associated parameter name.
The output will be non-<see langword="null"/> if the argument to the
parameter specified is non-<see langword="null"/>.
</param>
</member>
<member name="T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute">
<summary>
Specifies that when a method returns <see cref="P:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.ReturnValue"/>,
the parameter will not be <see langword="null"/> even if the corresponding type allows it.
</summary>
</member>
<member name="P:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.ReturnValue">
<summary>
Gets the return value condition.
If the method returns this value, the associated parameter will not be <see langword="null"/>.
</summary>
</member>
<member name="M:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.#ctor(System.Boolean)">
<summary>
Initializes the attribute with the specified return value condition.
</summary>
<param name="returnValue">
The return value condition.
If the method returns this value, the associated parameter will not be <see langword="null"/>.
</param>
</member>
</members>
</doc>

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects;
@ -10,10 +12,11 @@ namespace CryptoExchange.Net.RateLimiter
/// <summary>
/// Limits the amount of requests per time period to a certain limit, counts the request per API key.
/// </summary>
public class RateLimiterAPIKey: IRateLimiter
public class RateLimiterAPIKey: IRateLimiter, IDisposable
{
internal Dictionary<string, RateLimitObject> history = new Dictionary<string, RateLimitObject>();
private readonly SHA256 encryptor;
private readonly int limitPerKey;
private readonly TimeSpan perTimePeriod;
private readonly object historyLock = new object();
@ -26,6 +29,7 @@ namespace CryptoExchange.Net.RateLimiter
public RateLimiterAPIKey(int limitPerApiKey, TimeSpan perTimePeriod)
{
limitPerKey = limitPerApiKey;
encryptor = SHA256.Create();
this.perTimePeriod = perTimePeriod;
}
@ -35,7 +39,14 @@ namespace CryptoExchange.Net.RateLimiter
if(client.authProvider?.Credentials?.Key == null)
return new CallResult<double>(0, null);
var key = client.authProvider.Credentials.Key.GetString();
var keyBytes = encryptor.ComputeHash(Encoding.UTF8.GetBytes(client.authProvider.Credentials.Key.GetString()));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < keyBytes.Length; i++)
{
builder.Append(keyBytes[i].ToString("x2"));
}
var key = builder.ToString();
int waitTime;
RateLimitObject rlo;
@ -69,5 +80,13 @@ namespace CryptoExchange.Net.RateLimiter
return new CallResult<double>(waitTime, null);
}
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
encryptor.Dispose();
}
}
}