1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-15 18:33:06 +00:00

Added code docs, added ContinueOnQueryResponse

This commit is contained in:
Jan Korf
2019-08-06 13:19:34 +02:00
parent 11016bc213
commit 780da53475
50 changed files with 2545 additions and 30 deletions
+3
View File
@@ -2,6 +2,9 @@
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// Proxy info
/// </summary>
public class ApiProxy
{
/// <summary>
@@ -3,8 +3,17 @@ using System.Collections.Generic;
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// Comparer for byte order
/// </summary>
public class ByteOrderComparer : IComparer<byte[]>
{
/// <summary>
/// Compare function
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public int Compare(byte[] x, byte[] y)
{
// Shortcuts: If both are null, they are the same.
+36
View File
@@ -4,6 +4,10 @@ using System.Net;
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// The result of an operation
/// </summary>
/// <typeparam name="T"></typeparam>
public class CallResult<T>
{
/// <summary>
@@ -19,6 +23,11 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public bool Success => Error == null;
/// <summary>
/// ctor
/// </summary>
/// <param name="data"></param>
/// <param name="error"></param>
public CallResult(T data, Error error)
{
Data = data;
@@ -26,6 +35,10 @@ namespace CryptoExchange.Net.Objects
}
}
/// <summary>
/// The result of a request
/// </summary>
/// <typeparam name="T"></typeparam>
public class WebCallResult<T>: CallResult<T>
{
/// <summary>
@@ -33,18 +46,41 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public HttpStatusCode? ResponseStatusCode { get; set; }
/// <summary>
/// The response headers
/// </summary>
public IEnumerable<Tuple<string, string>> ResponseHeaders { get; set; }
/// <summary>
/// ctor
/// </summary>
/// <param name="code"></param>
/// <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)
{
ResponseHeaders = responseHeaders;
ResponseStatusCode = code;
}
/// <summary>
/// Create an error result
/// </summary>
/// <param name="error"></param>
/// <returns></returns>
public static WebCallResult<T> CreateErrorResult(Error error)
{
return new WebCallResult<T>(null, null, default(T), error);
}
/// <summary>
/// Create an error result
/// </summary>
/// <param name="code"></param>
/// <param name="responseHeaders"></param>
/// <param name="error"></param>
/// <returns></returns>
public static WebCallResult<T> CreateErrorResult(HttpStatusCode? code, IEnumerable<Tuple<string, string>> responseHeaders, Error error)
{
return new WebCallResult<T>(code, responseHeaders, default(T), error);
+21
View File
@@ -1,13 +1,34 @@
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// Constants
/// </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>
public const string JsonContentHeader = "application/json";
/// <summary>
/// Form content type header
/// </summary>
public const string FormContentHeader = "application/x-www-form-urlencoded";
}
}
+51
View File
@@ -1,34 +1,85 @@
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// What to do when a request would exceed the rate limit
/// </summary>
public enum RateLimitingBehaviour
{
/// <summary>
/// Fail the request
/// </summary>
Fail,
/// <summary>
/// Wait till the request can be send
/// </summary>
Wait
}
/// <summary>
/// Where the post parameters should be added
/// </summary>
public enum PostParameters
{
/// <summary>
/// Post parameters in body
/// </summary>
InBody,
/// <summary>
/// Post parameters in url
/// </summary>
InUri
}
/// <summary>
/// The format of the request body
/// </summary>
public enum RequestBodyFormat
{
/// <summary>
/// Form data
/// </summary>
FormData,
/// <summary>
/// Json
/// </summary>
Json
}
/// <summary>
/// Status of the order book
/// </summary>
public enum OrderBookStatus
{
/// <summary>
/// Not connected
/// </summary>
Disconnected,
/// <summary>
/// Connecting
/// </summary>
Connecting,
/// <summary>
/// Syncing data
/// </summary>
Syncing,
/// <summary>
/// Data synced, order book is up to date
/// </summary>
Synced,
}
/// <summary>
/// Order book entry type
/// </summary>
public enum OrderBookEntryType
{
/// <summary>
/// Ask
/// </summary>
Ask,
/// <summary>
/// Bid
/// </summary>
Bid
}
}
+71
View File
@@ -1,5 +1,8 @@
namespace CryptoExchange.Net.Objects
{
/// <summary>
/// Base class for errors
/// </summary>
public abstract class Error
{
/// <summary>
@@ -11,59 +14,127 @@
/// </summary>
public string Message { get; set; }
/// <summary>
/// ctor
/// </summary>
/// <param name="code"></param>
/// <param name="message"></param>
protected Error(int code, string message)
{
Code = code;
Message = message;
}
/// <summary>
/// String representation
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"{Code}: {Message}";
}
}
/// <summary>
/// Cant reach server error
/// </summary>
public class CantConnectError : Error
{
/// <summary>
/// ctor
/// </summary>
public CantConnectError() : base(1, "Can't connect to the server") { }
}
/// <summary>
/// No api credentials provided while trying to access private endpoint
/// </summary>
public class NoApiCredentialsError : Error
{
/// <summary>
/// ctor
/// </summary>
public NoApiCredentialsError() : base(2, "No credentials provided for private endpoint") { }
}
/// <summary>
/// Error returned by the server
/// </summary>
public class ServerError: Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public ServerError(string message) : base(3, "Server error: " + message) { }
/// <summary>
/// ctor
/// </summary>
/// <param name="code"></param>
/// <param name="message"></param>
public ServerError(int code, string message) : base(code, message)
{
}
}
/// <summary>
/// Web error returned by the server
/// </summary>
public class WebError : Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public WebError(string message) : base(4, "Web error: " + message) { }
}
/// <summary>
/// Error while deserializing data
/// </summary>
public class DeserializeError : Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public DeserializeError(string message) : base(5, "Error deserializing data: " + message) { }
}
/// <summary>
/// Unknown error
/// </summary>
public class UnknownError : Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public UnknownError(string message) : base(6, "Unknown error occured " + message) { }
}
/// <summary>
/// An invalid parameter has been provided
/// </summary>
public class ArgumentError : Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public ArgumentError(string message) : base(7, "Invalid parameter: " + message) { }
}
/// <summary>
/// Rate limit exceeded
/// </summary>
public class RateLimitError: Error
{
/// <summary>
/// ctor
/// </summary>
/// <param name="message"></param>
public RateLimitError(string message) : base(8, "Rate limit exceeded: " + message) { }
}
}
+10
View File
@@ -91,6 +91,11 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Create a copy of the options
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T Copy<T>() where T:RestClientOptions, new()
{
var copy = new T
@@ -141,6 +146,11 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public int? SocketSubscriptionsCombineTarget { get; set; }
/// <summary>
/// Create a copy of the options
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T Copy<T>() where T : SocketClientOptions, new()
{
var copy = new T