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)
|
||||
{
|
||||
var sbinary = "";
|
||||
foreach (byte t in buff)
|
||||
foreach (var t in buff)
|
||||
sbinary += t.ToString("X2"); /* hex format */
|
||||
return sbinary;
|
||||
}
|
||||
|
@ -102,22 +102,19 @@ namespace CryptoExchange.Net
|
||||
|
||||
foreach (var limiter in rateLimiters)
|
||||
{
|
||||
double limitedBy = limiter.LimitRequest(uri.AbsolutePath);
|
||||
var limitedBy = limiter.LimitRequest(uri.AbsolutePath);
|
||||
if (limitedBy > 0)
|
||||
log.Write(LogVerbosity.Debug, $"Request {uri.AbsolutePath} was limited by {limitedBy}ms by {limiter.GetType().Name}");
|
||||
}
|
||||
|
||||
log.Write(LogVerbosity.Debug, $"Sending request to {uriString}");
|
||||
var result = await ExecuteRequest(request);
|
||||
if (result.Error != null)
|
||||
return new CallResult<T>(null, result.Error);
|
||||
|
||||
return Deserialize<T>(result.Data);
|
||||
return result.Error != null ? new CallResult<T>(null, result.Error) : Deserialize<T>(result.Data);
|
||||
}
|
||||
|
||||
private async Task<CallResult<string>> ExecuteRequest(IRequest request)
|
||||
{
|
||||
string returnedData = "";
|
||||
var returnedData = "";
|
||||
try
|
||||
{
|
||||
var response = request.GetResponse();
|
||||
@ -136,11 +133,11 @@ namespace CryptoExchange.Net
|
||||
var reader = new StreamReader(response.GetResponseStream());
|
||||
responseData = reader.ReadToEnd();
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
string infoMessage = "No response from server";
|
||||
var infoMessage = "No response from server";
|
||||
if (response == null)
|
||||
return new CallResult<string>(null, new WebError(infoMessage));
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CryptoExchange.Net.RateLimiter;
|
||||
using CryptoExchange.Net.RateLimiter;
|
||||
|
||||
namespace CryptoExchange.Net.Interfaces
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
|
||||
namespace CryptoExchange.Net.Interfaces
|
||||
namespace CryptoExchange.Net.Interfaces
|
||||
{
|
||||
public interface IRequestFactory
|
||||
{
|
||||
|
@ -15,11 +15,11 @@ namespace CryptoExchange.Net.RateLimiter
|
||||
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);
|
||||
if (Times.Count >= limit)
|
||||
return (Times.First() - (time - perTimePeriod)).TotalMilliseconds;
|
||||
return (int)Math.Round((Times.First() - (time - perTimePeriod)).TotalMilliseconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ namespace CryptoExchange.Net.RateLimiter
|
||||
{
|
||||
internal Dictionary<string, RateLimitObject> history = new Dictionary<string, RateLimitObject>();
|
||||
|
||||
private int limitPerEndpoint;
|
||||
private TimeSpan perTimePeriod;
|
||||
private object historyLock = new object();
|
||||
private readonly int limitPerEndpoint;
|
||||
private readonly TimeSpan perTimePeriod;
|
||||
private readonly object historyLock = new object();
|
||||
|
||||
/// <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.
|
||||
@ -29,7 +29,7 @@ namespace CryptoExchange.Net.RateLimiter
|
||||
|
||||
public double LimitRequest(string url)
|
||||
{
|
||||
double waitTime;
|
||||
int waitTime;
|
||||
RateLimitObject rlo;
|
||||
lock (historyLock)
|
||||
{
|
||||
@ -50,7 +50,7 @@ namespace CryptoExchange.Net.RateLimiter
|
||||
if (waitTime != 0)
|
||||
{
|
||||
Thread.Sleep(Convert.ToInt32(waitTime));
|
||||
waitTime += sw.ElapsedMilliseconds;
|
||||
waitTime += (int)sw.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
rlo.Add(DateTime.UtcNow);
|
||||
|
@ -13,9 +13,9 @@ namespace CryptoExchange.Net.RateLimiter
|
||||
{
|
||||
internal List<DateTime> history = new List<DateTime>();
|
||||
|
||||
private int limit;
|
||||
private TimeSpan perTimePeriod;
|
||||
private object requestLock = new object();
|
||||
private readonly int limit;
|
||||
private readonly TimeSpan perTimePeriod;
|
||||
private readonly object requestLock = new object();
|
||||
|
||||
/// <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.
|
||||
|
@ -23,14 +23,11 @@ namespace CryptoExchange.Net.Requests
|
||||
get => request.Method;
|
||||
set => request.Method = value;
|
||||
}
|
||||
public Uri Uri
|
||||
{
|
||||
get => request.RequestUri;
|
||||
}
|
||||
public Uri Uri => request.RequestUri;
|
||||
|
||||
public void SetProxy(string host, int port)
|
||||
{
|
||||
request.Proxy = new WebProxy(host, port); ;
|
||||
request.Proxy = new WebProxy(host, port);
|
||||
}
|
||||
|
||||
public IResponse GetResponse()
|
||||
|
Loading…
x
Reference in New Issue
Block a user