mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-16 10:53:08 +00:00
3.0 wip
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Security;
|
||||
|
||||
namespace CryptoExchange.Net.Objects
|
||||
{
|
||||
@@ -19,25 +20,20 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// The login of the proxy
|
||||
/// </summary>
|
||||
public string Login { get; }
|
||||
public string? Login { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The password of the proxy
|
||||
/// </summary>
|
||||
public string Password { get; }
|
||||
public SecureString? Password { 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)
|
||||
public ApiProxy(string host, int port): this(host, port, null, (SecureString?)null)
|
||||
{
|
||||
if(string.IsNullOrEmpty(host) || port <= 0)
|
||||
throw new ArgumentException("Proxy host or port not filled");
|
||||
|
||||
Host = host;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -48,11 +44,28 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <param name="port">The proxy port</param>
|
||||
/// <param name="login">The proxy login</param>
|
||||
/// <param name="password">The proxy password</param>
|
||||
public ApiProxy(string host, int port, string login, string password) : this(host, port)
|
||||
public ApiProxy(string host, int port, string? login, string? password) : this(host, port, login, password?.ToSecureString())
|
||||
{
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||
throw new ArgumentException("Proxy login or password not filled");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Create new settings for a proxy
|
||||
/// </summary>
|
||||
/// <param name="host">The proxy hostname/ip</param>
|
||||
/// <param name="port">The proxy port</param>
|
||||
/// <param name="login">The proxy login</param>
|
||||
/// <param name="password">The proxy password</param>
|
||||
public ApiProxy(string host, int port, string? login, SecureString? password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(login))
|
||||
throw new ArgumentException("Proxy login not provided");
|
||||
|
||||
if (!host.StartsWith("http"))
|
||||
throw new ArgumentException("Proxy host should start with either http:// or https://");
|
||||
|
||||
Host = host;
|
||||
Port = port;
|
||||
Login = login;
|
||||
Password = password;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
|
||||
namespace CryptoExchange.Net.Objects
|
||||
@@ -17,7 +17,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// An error if the call didn't succeed
|
||||
/// </summary>
|
||||
public Error Error { get; internal set; }
|
||||
public Error? Error { get; internal set; }
|
||||
/// <summary>
|
||||
/// Whether the call was successful
|
||||
/// </summary>
|
||||
@@ -28,11 +28,20 @@ namespace CryptoExchange.Net.Objects
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="error"></param>
|
||||
public CallResult(T data, Error error)
|
||||
public CallResult([AllowNull]T data, Error? error)
|
||||
{
|
||||
Data = data;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overwrite bool check so we can use if(callResult) instead of if(callResult.Success)
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public static implicit operator bool(CallResult<T> obj)
|
||||
{
|
||||
return !ReferenceEquals(obj, null) && obj.Success;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,7 +58,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// The response headers
|
||||
/// </summary>
|
||||
public IEnumerable<Tuple<string, string>> ResponseHeaders { get; set; }
|
||||
public IEnumerable<KeyValuePair<string, IEnumerable<string>>>? ResponseHeaders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
@@ -58,7 +67,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <param name="responseHeaders"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="error"></param>
|
||||
public WebCallResult(HttpStatusCode? code, IEnumerable<Tuple<string, string>> responseHeaders, T data, Error error): base(data, error)
|
||||
public WebCallResult(HttpStatusCode? code, IEnumerable<KeyValuePair<string, IEnumerable<string>>>? responseHeaders, [AllowNull] T data, Error? error): base(data, error)
|
||||
{
|
||||
ResponseHeaders = responseHeaders;
|
||||
ResponseStatusCode = code;
|
||||
@@ -81,7 +90,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <param name="responseHeaders"></param>
|
||||
/// <param name="error"></param>
|
||||
/// <returns></returns>
|
||||
public static WebCallResult<T> CreateErrorResult(HttpStatusCode? code, IEnumerable<Tuple<string, string>> responseHeaders, Error error)
|
||||
public static WebCallResult<T> CreateErrorResult(HttpStatusCode? code, IEnumerable<KeyValuePair<string, IEnumerable<string>>> responseHeaders, Error error)
|
||||
{
|
||||
return new WebCallResult<T>(code, responseHeaders, default, error);
|
||||
}
|
||||
|
||||
@@ -5,23 +5,6 @@
|
||||
/// </summary>
|
||||
public class Constants
|
||||
{
|
||||
/// <summary>
|
||||
/// GET Http method
|
||||
/// </summary>
|
||||
public const string GetMethod = "GET";
|
||||
/// <summary>
|
||||
/// POST Http method
|
||||
/// </summary>
|
||||
public const string PostMethod = "POST";
|
||||
/// <summary>
|
||||
/// DELETE Http method
|
||||
/// </summary>
|
||||
public const string DeleteMethod = "DELETE";
|
||||
/// <summary>
|
||||
/// PUT Http method
|
||||
/// </summary>
|
||||
public const string PutMethod = "PUT";
|
||||
|
||||
/// <summary>
|
||||
/// Json content type header
|
||||
/// </summary>
|
||||
|
||||
@@ -137,4 +137,15 @@
|
||||
/// <param name="message"></param>
|
||||
public RateLimitError(string message) : base(8, "Rate limit exceeded: " + message) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancellation requested
|
||||
/// </summary>
|
||||
public class CancellationRequestedError : Error
|
||||
{
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public CancellationRequestedError() : base(9, "Cancellation requested") { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace CryptoExchange.Net.Objects
|
||||
/// The log writers
|
||||
/// </summary>
|
||||
public List<TextWriter> LogWriters { get; set; } = new List<TextWriter> { new DebugTextWriter() };
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"LogVerbosity: {LogVerbosity}, Writers: {LogWriters.Count}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,6 +53,12 @@ namespace CryptoExchange.Net.Objects
|
||||
OrderBookName = name;
|
||||
SequenceNumbersAreConsecutive = sequencesAreConsecutive;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, OrderBookName: {OrderBookName}, SequenceNumbersAreConsequtive: {SequenceNumbersAreConsecutive}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,21 +66,36 @@ namespace CryptoExchange.Net.Objects
|
||||
/// </summary>
|
||||
public class ClientOptions : BaseOptions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The api credentials
|
||||
/// </summary>
|
||||
public ApiCredentials ApiCredentials { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The base address of the client
|
||||
/// </summary>
|
||||
public string BaseAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The api credentials
|
||||
/// </summary>
|
||||
public ApiCredentials? ApiCredentials { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Proxy to use
|
||||
/// </summary>
|
||||
public ApiProxy Proxy { get; set; }
|
||||
public ApiProxy? Proxy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="baseAddress"></param>
|
||||
public ClientOptions(string baseAddress)
|
||||
{
|
||||
BaseAddress = baseAddress;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, Credentials: {(ApiCredentials == null ? "-": "Set")}, BaseAddress: {BaseAddress}, Proxy: {(Proxy == null? "-": Proxy.Host)}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -91,6 +118,14 @@ namespace CryptoExchange.Net.Objects
|
||||
/// </summary>
|
||||
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="baseAddress"></param>
|
||||
public RestClientOptions(string baseAddress): base(baseAddress)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of the options
|
||||
/// </summary>
|
||||
@@ -110,10 +145,16 @@ namespace CryptoExchange.Net.Objects
|
||||
};
|
||||
|
||||
if (ApiCredentials != null)
|
||||
copy.ApiCredentials = new ApiCredentials(ApiCredentials.Key.GetString(), ApiCredentials.Secret.GetString());
|
||||
copy.ApiCredentials = ApiCredentials.Copy();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, RateLimitters: {RateLimiters.Count}, RateLimitBehaviour: {RateLimitingBehaviour}, RequestTimeout: {RequestTimeout.ToString("c")}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -146,6 +187,14 @@ namespace CryptoExchange.Net.Objects
|
||||
/// </summary>
|
||||
public int? SocketSubscriptionsCombineTarget { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="baseAddress"></param>
|
||||
public SocketClientOptions(string baseAddress) : base(baseAddress)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a copy of the options
|
||||
/// </summary>
|
||||
@@ -166,9 +215,15 @@ namespace CryptoExchange.Net.Objects
|
||||
};
|
||||
|
||||
if (ApiCredentials != null)
|
||||
copy.ApiCredentials = new ApiCredentials(ApiCredentials.Key.GetString(), ApiCredentials.Secret.GetString());
|
||||
copy.ApiCredentials = ApiCredentials.Copy();
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, AutoReconnect: {AutoReconnect}, ReconnectInterval: {ReconnectInterval}, SocketResponseTimeout: {SocketResponseTimeout.ToString("c")}, SocketSubscriptionsCombineTarget: {SocketSubscriptionsCombineTarget}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user