Skip to content

Commit

Permalink
CryptoExchange.Net testing update (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf authored May 1, 2024
1 parent c184f1f commit 6430998
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 332 deletions.
60 changes: 29 additions & 31 deletions Huobi.Net.UnitTests/HuobiClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
using Huobi.Net.ExtensionMethods;
using CryptoExchange.Net.Objects.Sockets;
using NUnit.Framework.Legacy;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Clients;
using System.Net.Http;
using System.Collections.Generic;
using CryptoExchange.Net.Converters.JsonNet;

namespace Huobi.Net.UnitTests
{
Expand Down Expand Up @@ -54,44 +59,37 @@ public string SerializeExpected<T>(T data, bool tick)
}

[Test]
public void CheckRestInterfaces()
public void CheckSignatureExample()
{
var assembly = Assembly.GetAssembly(typeof(HuobiRestClientSpotApi));
var ignore = new string[] { "IHuobiClientSpot" };
var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IHuobiClientSpot") && !ignore.Contains(t.Name));
var authProvider = new HuobiAuthenticationProvider(
new ApiCredentials("e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx", "XXXXXXXXXX"),
false
);
var client = (RestApiClient)new HuobiRestClient().SpotApi;

foreach (var clientInterface in clientInterfaces)
{
var implementation = assembly.GetTypes().Single(t => t.IsAssignableTo(clientInterface) && t != clientInterface);
int methods = 0;
foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task))))
CryptoExchange.Net.Testing.TestHelpers.CheckSignature(
client,
authProvider,
HttpMethod.Get,
"/v1/order/orders",
(uriParams, bodyParams, headers) =>
{
var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray());
ClassicAssert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}");
methods++;
}
Debug.WriteLine($"{clientInterface.Name} {methods} methods validated");
}
return uriParams["Signature"].ToString();
},
"2ZQ7/roKBjdnAv8z5DymwzgSaOPyPgJl0BIlq9fa94w=",
new Dictionary<string, object>
{
{ "order-id", "1234567890" }
},
time: new DateTime(2017, 5, 11, 15, 19, 30, DateTimeKind.Utc),
host: "https://api.huobi.pro");
}

[Test]
public void CheckSocketInterfaces()
public void CheckInterfaces()
{
var assembly = Assembly.GetAssembly(typeof(HuobiSocketClient));
var clientInterfaces = assembly.GetTypes().Where(t => t.Name.StartsWith("IHuobiSocketClientSpot"));

foreach (var clientInterface in clientInterfaces)
{
var implementation = assembly.GetTypes().Single(t => t.IsAssignableTo(clientInterface) && t != clientInterface);
int methods = 0;
foreach (var method in implementation.GetMethods().Where(m => m.ReturnType.IsAssignableTo(typeof(Task<CallResult<UpdateSubscription>>))))
{
var interfaceMethod = clientInterface.GetMethod(method.Name, method.GetParameters().Select(p => p.ParameterType).ToArray());
ClassicAssert.NotNull(interfaceMethod, $"Missing interface for method {method.Name} in {implementation.Name} implementing interface {clientInterface.Name}");
methods++;
}
Debug.WriteLine($"{clientInterface.Name} {methods} methods validated");
}
CryptoExchange.Net.Testing.TestHelpers.CheckForMissingRestInterfaces<HuobiRestClient>();
CryptoExchange.Net.Testing.TestHelpers.CheckForMissingSocketInterfaces<HuobiSocketClient>();
}
}
}
6 changes: 3 additions & 3 deletions Huobi.Net/Clients/HuobiRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class HuobiRestClient : BaseRestClient, IHuobiRestClient
#region Api clients

/// <inheritdoc />
public IHuobiClientSpotApi SpotApi { get; }
public IHuobiRestClientSpotApi SpotApi { get; }

/// <inheritdoc />
public IHuobiClientUsdtMarginSwapApi UsdtMarginSwapApi { get; }
public IHuobiRestClientUsdtMarginSwapApi UsdtMarginSwapApi { get; }

#endregion

Expand Down Expand Up @@ -49,7 +49,7 @@ public HuobiRestClient(HttpClient? httpClient, ILoggerFactory? loggerFactory, Ac
Initialize(options);

SpotApi = AddApiClient(new HuobiRestClientSpotApi(_logger, httpClient, options));
UsdtMarginSwapApi = AddApiClient(new HuobiClientUsdtMarginSwapApi(_logger, httpClient, options));
UsdtMarginSwapApi = AddApiClient(new HuobiRestClientUsdtMarginSwapApi(_logger, httpClient, options));
}
#endregion

Expand Down
8 changes: 4 additions & 4 deletions Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Huobi.Net.Clients.SpotApi
{
/// <inheritdoc />
public class HuobiRestClientSpotApi : RestApiClient, IHuobiClientSpotApi, ISpotClient
public class HuobiRestClientSpotApi : RestApiClient, IHuobiRestClientSpotApi, ISpotClient
{
/// <inheritdoc />
public new HuobiRestOptions ClientOptions => (HuobiRestOptions)base.ClientOptions;
Expand All @@ -45,11 +45,11 @@ public class HuobiRestClientSpotApi : RestApiClient, IHuobiClientSpotApi, ISpotC
#region Api clients

/// <inheritdoc />
public IHuobiClientSpotApiAccount Account { get; }
public IHuobiRestClientSpotApiAccount Account { get; }
/// <inheritdoc />
public IHuobiClientSpotApiExchangeData ExchangeData { get; }
public IHuobiRestClientSpotApiExchangeData ExchangeData { get; }
/// <inheritdoc />
public IHuobiClientSpotApiTrading Trading { get; }
public IHuobiRestClientSpotApiTrading Trading { get; }

#endregion

Expand Down
2 changes: 1 addition & 1 deletion Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Huobi.Net.Clients.SpotApi
{
/// <inheritdoc />
public class HuobiRestClientSpotApiAccount : IHuobiClientSpotApiAccount
public class HuobiRestClientSpotApiAccount : IHuobiRestClientSpotApiAccount
{
private const string GetUserId = "user/uid";
private const string GetSubAccountUsers = "sub-user/user-list";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace Huobi.Net.Clients.SpotApi
{
/// <inheritdoc />
public class HuobiRestClientSpotApiExchangeData : IHuobiClientSpotApiExchangeData
public class HuobiRestClientSpotApiExchangeData : IHuobiRestClientSpotApiExchangeData
{
private const string MarketTickerEndpoint = "market/tickers";
private const string MarketTickerMergedEndpoint = "market/detail/merged";
Expand Down
2 changes: 1 addition & 1 deletion Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Huobi.Net.Clients.SpotApi
{
/// <inheritdoc />
public class HuobiRestClientSpotApiTrading : IHuobiClientSpotApiTrading
public class HuobiRestClientSpotApiTrading : IHuobiRestClientSpotApiTrading
{
private const string PlaceOrderEndpoint = "order/orders/place";
private const string OpenOrdersEndpoint = "order/openOrders";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Huobi.Net.Clients.FuturesApi
{
/// <inheritdoc />
public class HuobiClientUsdtMarginSwapApi : RestApiClient, IHuobiClientUsdtMarginSwapApi
public class HuobiRestClientUsdtMarginSwapApi : RestApiClient, IHuobiRestClientUsdtMarginSwapApi
{
/// <inheritdoc />
public new HuobiRestOptions ClientOptions => (HuobiRestOptions)base.ClientOptions;
Expand All @@ -42,21 +42,21 @@ public class HuobiClientUsdtMarginSwapApi : RestApiClient, IHuobiClientUsdtMargi
#region Api clients

/// <inheritdoc />
public IHuobiClientUsdtMarginSwapApiAccount Account { get; }
public IHuobiRestClientUsdtMarginSwapApiAccount Account { get; }
/// <inheritdoc />
public HuobiClientUsdtMarginSwapApiExchangeData ExchangeData { get; }
public HuobiRestClientUsdtMarginSwapApiExchangeData ExchangeData { get; }
/// <inheritdoc />
public HuobiClientUsdtMarginSwapApiTrading Trading { get; }
public HuobiRestClientUsdtMarginSwapApiTrading Trading { get; }

#endregion

#region constructor/destructor
internal HuobiClientUsdtMarginSwapApi(ILogger log, HttpClient? httpClient, HuobiRestOptions options)
internal HuobiRestClientUsdtMarginSwapApi(ILogger log, HttpClient? httpClient, HuobiRestOptions options)
: base(log, httpClient, options.Environment.UsdtMarginSwapRestBaseAddress, options, options.UsdtMarginSwapOptions)
{
Account = new HuobiClientUsdtMarginSwapApiAccount(this);
ExchangeData = new HuobiClientUsdtMarginSwapApiExchangeData(this);
Trading = new HuobiClientUsdtMarginSwapApiTrading(this);
Account = new HuobiRestClientUsdtMarginSwapApiAccount(this);
ExchangeData = new HuobiRestClientUsdtMarginSwapApiExchangeData(this);
Trading = new HuobiRestClientUsdtMarginSwapApiTrading(this);

_brokerId = !string.IsNullOrEmpty(options.BrokerId) ? options.BrokerId! : "AA1ef14811";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
namespace Huobi.Net.Clients.UsdtMarginSwapApi
{
/// <inheritdoc />
public class HuobiClientUsdtMarginSwapApiAccount : IHuobiClientUsdtMarginSwapApiAccount
public class HuobiRestClientUsdtMarginSwapApiAccount : IHuobiRestClientUsdtMarginSwapApiAccount
{
private readonly HuobiClientUsdtMarginSwapApi _baseClient;
private readonly HuobiRestClientUsdtMarginSwapApi _baseClient;

internal HuobiClientUsdtMarginSwapApiAccount(HuobiClientUsdtMarginSwapApi baseClient)
internal HuobiRestClientUsdtMarginSwapApiAccount(HuobiRestClientUsdtMarginSwapApi baseClient)
{
_baseClient = baseClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
namespace Huobi.Net.Clients.UsdtMarginSwapApi
{
/// <inheritdoc />
public class HuobiClientUsdtMarginSwapApiExchangeData : IHuobiClientUsdtMarginSwapApiExchangeData
public class HuobiRestClientUsdtMarginSwapApiExchangeData : IHuobiRestClientUsdtMarginSwapApiExchangeData
{
private readonly HuobiClientUsdtMarginSwapApi _baseClient;
private readonly HuobiRestClientUsdtMarginSwapApi _baseClient;

internal HuobiClientUsdtMarginSwapApiExchangeData(HuobiClientUsdtMarginSwapApi baseClient)
internal HuobiRestClientUsdtMarginSwapApiExchangeData(HuobiRestClientUsdtMarginSwapApi baseClient)
{
_baseClient = baseClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace Huobi.Net.Clients.UsdtMarginSwapApi
{
/// <inheritdoc />
public class HuobiClientUsdtMarginSwapApiTrading : IHuobiClientUsdtMarginSwapApiTrading
public class HuobiRestClientUsdtMarginSwapApiTrading : IHuobiRestClientUsdtMarginSwapApiTrading
{
private readonly HuobiClientUsdtMarginSwapApi _baseClient;
private readonly HuobiRestClientUsdtMarginSwapApi _baseClient;

internal HuobiClientUsdtMarginSwapApiTrading(HuobiClientUsdtMarginSwapApi baseClient)
internal HuobiRestClientUsdtMarginSwapApiTrading(HuobiRestClientUsdtMarginSwapApi baseClient)
{
_baseClient = baseClient;
}
Expand Down
2 changes: 1 addition & 1 deletion Huobi.Net/Huobi.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.4.0" />
</ItemGroup>
</Project>
Loading

0 comments on commit 6430998

Please sign in to comment.