1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-11 16:32:57 +00:00

Ratelimit changes

This commit is contained in:
Jan Korf
2018-08-12 13:34:28 +02:00
parent 9dd1b7b318
commit e45858054e
9 changed files with 56 additions and 16 deletions
+30
View File
@@ -0,0 +1,30 @@
using System;
namespace CryptoExchange.Net
{
public class ApiProxy
{
/// <summary>
/// The host address of the proxy
/// </summary>
public string Host { get; }
/// <summary>
/// The port of the proxy
/// </summary>
public int Port { get; }
/// <summary>
/// Create new settings for a proxy
/// </summary>
/// <param name="host">The proxy hostname/ip</param>
/// <param name="port">The proxy port</param>
public ApiProxy(string host, int port)
{
if(string.IsNullOrEmpty(host) || port <= 0)
throw new ArgumentException("Proxy host or port not filled");
Host = host;
Port = port;
}
}
}
+24
View File
@@ -0,0 +1,24 @@
namespace CryptoExchange.Net
{
public class CallResult<T>
{
/// <summary>
/// The data returned by the call
/// </summary>
public T Data { get; internal set; }
/// <summary>
/// An error if the call didn't succeed
/// </summary>
public Error Error { get; internal set; }
/// <summary>
/// Whether the call was successful
/// </summary>
public bool Success => Error == null;
public CallResult(T data, Error error)
{
Data = data;
Error = error;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace CryptoExchange.Net.Objects
{
public enum RateLimitingBehaviour
{
Fail,
Wait
}
}
+63
View File
@@ -0,0 +1,63 @@
namespace CryptoExchange.Net
{
public abstract class Error
{
public int Code { get; set; }
public string Message { get; set; }
protected Error(int code, string message)
{
Code = code;
Message = message;
}
public override string ToString()
{
return $"{Code}: {Message}";
}
}
public class CantConnectError : Error
{
public CantConnectError() : base(1, "Can't connect to the server") { }
}
public class NoApiCredentialsError : Error
{
public NoApiCredentialsError() : base(2, "No credentials provided for private endpoint") { }
}
public class ServerError: Error
{
public ServerError(string message) : base(3, "Server error: " + message) { }
public ServerError(int code, string message) : base(code, message)
{
}
}
public class WebError : Error
{
public WebError(string message) : base(4, "Web error: " + message) { }
}
public class DeserializeError : Error
{
public DeserializeError(string message) : base(5, "Error deserializing data: " + message) { }
}
public class UnknownError : Error
{
public UnknownError(string message) : base(6, "Unknown error occured " + message) { }
}
public class ArgumentError : Error
{
public ArgumentError(string message) : base(7, "Invalid parameter: " + message) { }
}
public class RateLimitError: Error
{
public RateLimitError(string message) : base(8, "Rate limit exceeded: " + message) { }
}
}
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.IO;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Logging;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.RateLimiter;
namespace CryptoExchange.Net
{
/// <summary>
/// Options
/// </summary>
public class ExchangeOptions
{
/// <summary>
/// The api credentials
/// </summary>
public ApiCredentials ApiCredentials { get; set; }
/// <summary>
/// Proxy to use
/// </summary>
public ApiProxy Proxy { get; set; }
/// <summary>
/// The log verbosity
/// </summary>
public LogVerbosity LogVerbosity { get; set; } = LogVerbosity.Info;
/// <summary>
/// The log writers
/// </summary>
public List<TextWriter> LogWriters { get; set; } = new List<TextWriter>() {new DebugTextWriter()};
/// <summary>
/// List of ratelimiters to use
/// </summary>
public List<IRateLimiter> RateLimiters { get; set; } = new List<IRateLimiter>();
/// <summary>
/// What to do when a call would exceed the rate limit
/// </summary>
public RateLimitingBehaviour RateLimitingBehaviour { get; set; } = RateLimitingBehaviour.Wait;
}
}