mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
adjusted some resharper things
This commit is contained in:
parent
488eb1cd48
commit
e89beed9ef
@ -17,7 +17,7 @@ namespace CryptoExchange.Net.Authentication
|
|||||||
protected string ByteToString(byte[] buff)
|
protected string ByteToString(byte[] buff)
|
||||||
{
|
{
|
||||||
var sbinary = "";
|
var sbinary = "";
|
||||||
foreach (byte t in buff)
|
foreach (var t in buff)
|
||||||
sbinary += t.ToString("X2"); /* hex format */
|
sbinary += t.ToString("X2"); /* hex format */
|
||||||
return sbinary;
|
return sbinary;
|
||||||
}
|
}
|
||||||
|
@ -102,22 +102,19 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
foreach (var limiter in rateLimiters)
|
foreach (var limiter in rateLimiters)
|
||||||
{
|
{
|
||||||
double limitedBy = limiter.LimitRequest(uri.AbsolutePath);
|
var limitedBy = limiter.LimitRequest(uri.AbsolutePath);
|
||||||
if (limitedBy > 0)
|
if (limitedBy > 0)
|
||||||
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitedBy}ms by {limiter.GetType().Name}");
|
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitedBy}ms by {limiter.GetType().Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Write(LogVerbosity.Debug, $"Sending request to {uriString}");
|
log.Write(LogVerbosity.Debug, $"Sending request to {uriString}");
|
||||||
var result = await ExecuteRequest(request);
|
var result = await ExecuteRequest(request);
|
||||||
if (result.Error != null)
|
return result.Error != null ? new CallResult<T>(null, result.Error) : Deserialize<T>(result.Data);
|
||||||
return new CallResult<T>(null, result.Error);
|
|
||||||
|
|
||||||
return Deserialize<T>(result.Data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<CallResult<string>> ExecuteRequest(IRequest request)
|
private async Task<CallResult<string>> ExecuteRequest(IRequest request)
|
||||||
{
|
{
|
||||||
string returnedData = "";
|
var returnedData = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var response = request.GetResponse();
|
var response = request.GetResponse();
|
||||||
@ -136,11 +133,11 @@ namespace CryptoExchange.Net
|
|||||||
var reader = new StreamReader(response.GetResponseStream());
|
var reader = new StreamReader(response.GetResponseStream());
|
||||||
responseData = reader.ReadToEnd();
|
responseData = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string infoMessage = "No response from server";
|
var infoMessage = "No response from server";
|
||||||
if (response == null)
|
if (response == null)
|
||||||
return new CallResult<string>(null, new WebError(infoMessage));
|
return new CallResult<string>(null, new WebError(infoMessage));
|
||||||
|
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using CryptoExchange.Net.RateLimiter;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using CryptoExchange.Net.RateLimiter;
|
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Interfaces
|
namespace CryptoExchange.Net.Interfaces
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
|
namespace CryptoExchange.Net.Interfaces
|
||||||
namespace CryptoExchange.Net.Interfaces
|
|
||||||
{
|
{
|
||||||
public interface IRequestFactory
|
public interface IRequestFactory
|
||||||
{
|
{
|
||||||
|
@ -15,11 +15,11 @@ namespace CryptoExchange.Net.RateLimiter
|
|||||||
Times = new List<DateTime>();
|
Times = new List<DateTime>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetWaitTime(DateTime time, int limit, TimeSpan perTimePeriod)
|
public int GetWaitTime(DateTime time, int limit, TimeSpan perTimePeriod)
|
||||||
{
|
{
|
||||||
Times.RemoveAll(d => d < time - perTimePeriod);
|
Times.RemoveAll(d => d < time - perTimePeriod);
|
||||||
if (Times.Count >= limit)
|
if (Times.Count >= limit)
|
||||||
return (Times.First() - (time - perTimePeriod)).TotalMilliseconds;
|
return (int)Math.Round((Times.First() - (time - perTimePeriod)).TotalMilliseconds);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ namespace CryptoExchange.Net.RateLimiter
|
|||||||
{
|
{
|
||||||
internal Dictionary<string, RateLimitObject> history = new Dictionary<string, RateLimitObject>();
|
internal Dictionary<string, RateLimitObject> history = new Dictionary<string, RateLimitObject>();
|
||||||
|
|
||||||
private int limitPerEndpoint;
|
private readonly int limitPerEndpoint;
|
||||||
private TimeSpan perTimePeriod;
|
private readonly TimeSpan perTimePeriod;
|
||||||
private object historyLock = new object();
|
private readonly object historyLock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new RateLimiterPerEndpoint. This rate limiter limits the amount of requests per time period to a certain limit, counts the request per endpoint.
|
/// Create a new RateLimiterPerEndpoint. This rate limiter limits the amount of requests per time period to a certain limit, counts the request per endpoint.
|
||||||
@ -29,7 +29,7 @@ namespace CryptoExchange.Net.RateLimiter
|
|||||||
|
|
||||||
public double LimitRequest(string url)
|
public double LimitRequest(string url)
|
||||||
{
|
{
|
||||||
double waitTime;
|
int waitTime;
|
||||||
RateLimitObject rlo;
|
RateLimitObject rlo;
|
||||||
lock (historyLock)
|
lock (historyLock)
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ namespace CryptoExchange.Net.RateLimiter
|
|||||||
if (waitTime != 0)
|
if (waitTime != 0)
|
||||||
{
|
{
|
||||||
Thread.Sleep(Convert.ToInt32(waitTime));
|
Thread.Sleep(Convert.ToInt32(waitTime));
|
||||||
waitTime += sw.ElapsedMilliseconds;
|
waitTime += (int)sw.ElapsedMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
rlo.Add(DateTime.UtcNow);
|
rlo.Add(DateTime.UtcNow);
|
||||||
|
@ -13,9 +13,9 @@ namespace CryptoExchange.Net.RateLimiter
|
|||||||
{
|
{
|
||||||
internal List<DateTime> history = new List<DateTime>();
|
internal List<DateTime> history = new List<DateTime>();
|
||||||
|
|
||||||
private int limit;
|
private readonly int limit;
|
||||||
private TimeSpan perTimePeriod;
|
private readonly TimeSpan perTimePeriod;
|
||||||
private object requestLock = new object();
|
private readonly object requestLock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new RateLimiterTotal. This rate limiter limits the amount of requests per time period to a certain limit, counts the total amount of requests.
|
/// Create a new RateLimiterTotal. This rate limiter limits the amount of requests per time period to a certain limit, counts the total amount of requests.
|
||||||
|
@ -23,14 +23,11 @@ namespace CryptoExchange.Net.Requests
|
|||||||
get => request.Method;
|
get => request.Method;
|
||||||
set => request.Method = value;
|
set => request.Method = value;
|
||||||
}
|
}
|
||||||
public Uri Uri
|
public Uri Uri => request.RequestUri;
|
||||||
{
|
|
||||||
get => request.RequestUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetProxy(string host, int port)
|
public void SetProxy(string host, int port)
|
||||||
{
|
{
|
||||||
request.Proxy = new WebProxy(host, port); ;
|
request.Proxy = new WebProxy(host, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IResponse GetResponse()
|
public IResponse GetResponse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user