mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-08-31 12:42:00 +00:00
wip
This commit is contained in:
parent
bfaea941c7
commit
837038092d
@ -41,7 +41,9 @@
|
||||
<DocumentationFile>CryptoExchange.Net.Protobuf.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CryptoExchange.Net" Version="9.4.0" />
|
||||
<PackageReference Include="protobuf-net" Version="3.2.56" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CryptoExchange.Net\CryptoExchange.Net.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,4 +1,5 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Objects.Errors;
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework.Legacy;
|
||||
using System;
|
||||
@ -16,9 +17,9 @@ namespace CryptoExchange.Net.UnitTests
|
||||
[Test]
|
||||
public void TestBasicErrorCallResult()
|
||||
{
|
||||
var result = new CallResult(new ServerError("TestError"));
|
||||
var result = new CallResult(new ServerError("TestError", ErrorInfo.Unknown));
|
||||
|
||||
ClassicAssert.AreSame(result.Error.Message, "TestError");
|
||||
ClassicAssert.AreSame(result.Error.ErrorCode, "TestError");
|
||||
ClassicAssert.IsFalse(result);
|
||||
ClassicAssert.IsFalse(result.Success);
|
||||
}
|
||||
@ -36,9 +37,9 @@ namespace CryptoExchange.Net.UnitTests
|
||||
[Test]
|
||||
public void TestCallResultError()
|
||||
{
|
||||
var result = new CallResult<object>(new ServerError("TestError"));
|
||||
var result = new CallResult<object>(new ServerError("TestError", ErrorInfo.Unknown));
|
||||
|
||||
ClassicAssert.AreSame(result.Error.Message, "TestError");
|
||||
ClassicAssert.AreSame(result.Error.ErrorCode, "TestError");
|
||||
ClassicAssert.IsNull(result.Data);
|
||||
ClassicAssert.IsFalse(result);
|
||||
ClassicAssert.IsFalse(result.Success);
|
||||
@ -71,11 +72,11 @@ namespace CryptoExchange.Net.UnitTests
|
||||
[Test]
|
||||
public void TestCallResultErrorAs()
|
||||
{
|
||||
var result = new CallResult<TestObjectResult>(new ServerError("TestError"));
|
||||
var result = new CallResult<TestObjectResult>(new ServerError("TestError", ErrorInfo.Unknown));
|
||||
var asResult = result.As<TestObject2>(default);
|
||||
|
||||
ClassicAssert.IsNotNull(asResult.Error);
|
||||
ClassicAssert.AreSame(asResult.Error.Message, "TestError");
|
||||
ClassicAssert.AreSame(asResult.Error.ErrorCode, "TestError");
|
||||
ClassicAssert.IsNull(asResult.Data);
|
||||
ClassicAssert.IsFalse(asResult);
|
||||
ClassicAssert.IsFalse(asResult.Success);
|
||||
@ -84,11 +85,11 @@ namespace CryptoExchange.Net.UnitTests
|
||||
[Test]
|
||||
public void TestCallResultErrorAsError()
|
||||
{
|
||||
var result = new CallResult<TestObjectResult>(new ServerError("TestError"));
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2"));
|
||||
var result = new CallResult<TestObjectResult>(new ServerError("TestError", ErrorInfo.Unknown));
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2", ErrorInfo.Unknown));
|
||||
|
||||
ClassicAssert.IsNotNull(asResult.Error);
|
||||
ClassicAssert.AreSame(asResult.Error.Message, "TestError2");
|
||||
ClassicAssert.AreSame(asResult.Error.ErrorCode, "TestError2");
|
||||
ClassicAssert.IsNull(asResult.Data);
|
||||
ClassicAssert.IsFalse(asResult);
|
||||
ClassicAssert.IsFalse(asResult.Success);
|
||||
@ -97,11 +98,11 @@ namespace CryptoExchange.Net.UnitTests
|
||||
[Test]
|
||||
public void TestWebCallResultErrorAsError()
|
||||
{
|
||||
var result = new WebCallResult<TestObjectResult>(new ServerError("TestError"));
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2"));
|
||||
var result = new WebCallResult<TestObjectResult>(new ServerError("TestError", ErrorInfo.Unknown));
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2", ErrorInfo.Unknown));
|
||||
|
||||
ClassicAssert.IsNotNull(asResult.Error);
|
||||
ClassicAssert.AreSame(asResult.Error.Message, "TestError2");
|
||||
ClassicAssert.AreSame(asResult.Error.ErrorCode, "TestError2");
|
||||
ClassicAssert.IsNull(asResult.Data);
|
||||
ClassicAssert.IsFalse(asResult);
|
||||
ClassicAssert.IsFalse(asResult.Success);
|
||||
@ -124,10 +125,10 @@ namespace CryptoExchange.Net.UnitTests
|
||||
ResultDataSource.Server,
|
||||
new TestObjectResult(),
|
||||
null);
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2"));
|
||||
var asResult = result.AsError<TestObject2>(new ServerError("TestError2", ErrorInfo.Unknown));
|
||||
|
||||
ClassicAssert.IsNotNull(asResult.Error);
|
||||
Assert.That(asResult.Error.Message == "TestError2");
|
||||
Assert.That(asResult.Error.ErrorCode == "TestError2");
|
||||
Assert.That(asResult.ResponseStatusCode == System.Net.HttpStatusCode.OK);
|
||||
Assert.That(asResult.ResponseTime == TimeSpan.FromSeconds(1));
|
||||
Assert.That(asResult.RequestUrl == "https://test.com/api");
|
||||
|
@ -96,7 +96,7 @@ namespace CryptoExchange.Net.UnitTests
|
||||
ClassicAssert.IsFalse(result.Success);
|
||||
Assert.That(result.Error != null);
|
||||
Assert.That(result.Error is ServerError);
|
||||
Assert.That(result.Error.Code == 123);
|
||||
Assert.That(result.Error.ErrorCode == "123");
|
||||
Assert.That(result.Error.Message == "Invalid request");
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Objects.Errors;
|
||||
using CryptoExchange.Net.Objects.Sockets;
|
||||
using CryptoExchange.Net.Sockets;
|
||||
using System;
|
||||
@ -40,7 +41,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations.Sockets
|
||||
{
|
||||
if (!message.Data.Status.Equals("confirmed", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new CallResult<SubResponse>(new ServerError(message.Data.Status));
|
||||
return new CallResult<SubResponse>(new ServerError(ErrorInfo.Unknown with { Message = message.Data.Status }));
|
||||
}
|
||||
|
||||
return message.ToCallResult();
|
||||
|
@ -10,6 +10,7 @@ using CryptoExchange.Net.Clients;
|
||||
using CryptoExchange.Net.Converters.SystemTextJson;
|
||||
using CryptoExchange.Net.Interfaces;
|
||||
using CryptoExchange.Net.Objects;
|
||||
using CryptoExchange.Net.Objects.Errors;
|
||||
using CryptoExchange.Net.Objects.Options;
|
||||
using CryptoExchange.Net.SharedApis;
|
||||
using CryptoExchange.Net.UnitTests.TestImplementations;
|
||||
@ -55,7 +56,7 @@ namespace CryptoExchange.Net.UnitTests
|
||||
var accessor = CreateAccessor();
|
||||
var valid = accessor.Read(stream, true).Result;
|
||||
if (!valid)
|
||||
return new CallResult<T>(new ServerError(data));
|
||||
return new CallResult<T>(new ServerError(ErrorInfo.Unknown with { Message = data }));
|
||||
|
||||
var deserializeResult = accessor.Deserialize<T>();
|
||||
return deserializeResult;
|
||||
|
@ -18,6 +18,7 @@ using Microsoft.Extensions.Options;
|
||||
using System.Linq;
|
||||
using CryptoExchange.Net.Converters.SystemTextJson;
|
||||
using System.Text.Json.Serialization;
|
||||
using CryptoExchange.Net.Objects.Errors;
|
||||
|
||||
namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
@ -197,7 +198,7 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
||||
{
|
||||
var errorData = accessor.Deserialize<TestError>();
|
||||
|
||||
return new ServerError(errorData.Data.ErrorCode, errorData.Data.ErrorMessage);
|
||||
return new ServerError(errorData.Data.ErrorCode, GetErrorInfo(errorData.Data.ErrorCode, errorData.Data.ErrorMessage));
|
||||
}
|
||||
|
||||
public override TimeSpan? GetTimeOffset()
|
||||
|
@ -253,7 +253,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// Default error info
|
||||
/// </summary>
|
||||
protected static readonly ErrorInfo _errorInfo = new ErrorInfo(ErrorType.RequestRateLimited, false, "Client rate limit exceeded");
|
||||
protected static readonly ErrorInfo _errorInfo = new ErrorInfo(ErrorType.RateLimitRequest, false, "Client rate limit exceeded");
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
@ -274,7 +274,7 @@ namespace CryptoExchange.Net.Objects
|
||||
/// <summary>
|
||||
/// Default error info
|
||||
/// </summary>
|
||||
protected static readonly ErrorInfo _errorInfo = new ErrorInfo(ErrorType.RequestRateLimited, false, "Server rate limit exceeded");
|
||||
protected static readonly ErrorInfo _errorInfo = new ErrorInfo(ErrorType.RateLimitRequest, false, "Server rate limit exceeded");
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
|
@ -44,7 +44,6 @@ namespace CryptoExchange.Net.Objects.Errors
|
||||
/// </summary>
|
||||
public ErrorInfo GetErrorInfo(string code, string? message)
|
||||
{
|
||||
message = message ?? code ?? "-";
|
||||
if (_directMapping.TryGetValue(code!, out var info))
|
||||
return info with { Message = message };
|
||||
|
||||
|
@ -79,27 +79,23 @@ namespace CryptoExchange.Net.Objects.Errors
|
||||
/// <summary>
|
||||
/// Request rate limit error, too many requests
|
||||
/// </summary>
|
||||
RequestRateLimited,
|
||||
RateLimitRequest,
|
||||
/// <summary>
|
||||
/// Connection rate limit error, too many connections
|
||||
/// </summary>
|
||||
ConnectionRateLimited,
|
||||
RateLimitConnection,
|
||||
/// <summary>
|
||||
/// Subscription rate limit error, too many subscriptions
|
||||
/// </summary>
|
||||
SubscriptionRateLimited,
|
||||
RateLimitSubscription,
|
||||
/// <summary>
|
||||
/// Order rate limit error, too many orders
|
||||
/// </summary>
|
||||
OrderRateLimited,
|
||||
RateLimitOrder,
|
||||
/// <summary>
|
||||
/// Timestamp invalid
|
||||
/// Request timestamp invalid
|
||||
/// </summary>
|
||||
TimestampInvalid,
|
||||
/// <summary>
|
||||
/// Request signature invalid
|
||||
/// </summary>
|
||||
SignatureInvalid,
|
||||
InvalidTimestamp,
|
||||
/// <summary>
|
||||
/// Unknown symbol
|
||||
/// </summary>
|
||||
@ -119,19 +115,19 @@ namespace CryptoExchange.Net.Objects.Errors
|
||||
/// <summary>
|
||||
/// Invalid quantity
|
||||
/// </summary>
|
||||
QuantityInvalid,
|
||||
InvalidQuantity,
|
||||
/// <summary>
|
||||
/// Invalid price
|
||||
/// </summary>
|
||||
PriceInvalid,
|
||||
InvalidPrice,
|
||||
/// <summary>
|
||||
/// Parameter(s) for stop or tp/sl order invalid
|
||||
/// </summary>
|
||||
StopParametersInvalid,
|
||||
InvalidStopParameters,
|
||||
/// <summary>
|
||||
/// Not enough balance to execute order
|
||||
/// Not enough balance to execute request
|
||||
/// </summary>
|
||||
BalanceInsufficient,
|
||||
InsufficientBalance,
|
||||
/// <summary>
|
||||
/// Client order id already in use
|
||||
/// </summary>
|
||||
@ -139,11 +135,11 @@ namespace CryptoExchange.Net.Objects.Errors
|
||||
/// <summary>
|
||||
/// Symbol is not currently trading
|
||||
/// </summary>
|
||||
SymbolNotTrading,
|
||||
UnavailableSymbol,
|
||||
/// <summary>
|
||||
/// Order rejected due to order configuration such as order type or time in force restrictions
|
||||
/// </summary>
|
||||
OrderConfigurationRejected,
|
||||
RejectedOrderConfiguration,
|
||||
/// <summary>
|
||||
/// There is no open position
|
||||
/// </summary>
|
||||
@ -155,7 +151,7 @@ namespace CryptoExchange.Net.Objects.Errors
|
||||
/// <summary>
|
||||
/// The target object is not in the correct state for an operation
|
||||
/// </summary>
|
||||
TargetIncorrectState,
|
||||
IncorrectState,
|
||||
/// <summary>
|
||||
/// Risk management error
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user