mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-04-07 10:11:10 +00:00
Updated API credential logic, exchange implementation are expected to provide their own credentials implementation with ApiCredentials as base class Removed ApiCredentials implementation used by most exchanges Removed ApiCredentialsType Enum Added CredentialSet base class and implementations for defining different API credentials Added optional type param to AuthenticationProvider for the specific API credential type to improve type safety Moved AuthenticationProvider/ApiCredentials from BaseApiClient to RestApiClient/SocketApiClient base classes Added optional type params to RestApiClient/SocketApiClient base class to specify the AuthenticationProvider type and credentials type to improve type safety Moved SetOptions/SetApiCredentials from BaseApiClient to RestApiClient/SocketApiClient Extracted LibraryOptions<TRestOptions, TSocketOptions, TEnvironment> without TApiCredentials for libraries without API credentials Removed ApiCredentials from ApiOptions, credentials can only be configured at library, rest or socket level Added EnvironmentName to RestApiClient/SocketApiClient property Added Unknown enum value to Shared interfaces SharedOrderStatus, SharedTransferStatus and SharedTriggerOrderStatus enums Updated Enum converter to map value to an undefined Enum value instead of the first Enum value Added support for checking for missing fields on RestIntegrationTest Added BytesToHexString and HexToBytesString to ExchangeHelpers static class Fixed bug where WebSocket connections are not reconnected when configuring Proxy with SetUpdates Removed legacy CryptoBaseClient, CryptoRestClient and CryptoSocketClient
89 lines
3.3 KiB
C#
89 lines
3.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using CryptoExchange.Net.Authentication;
|
|
using CryptoExchange.Net.Clients;
|
|
using CryptoExchange.Net.Converters.MessageParsing.DynamicConverters;
|
|
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 Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace CryptoExchange.Net.UnitTests
|
|
{
|
|
public class TestBaseClient: BaseClient
|
|
{
|
|
public TestSubClient SubClient { get; }
|
|
|
|
public TestBaseClient(): base(null, "Test")
|
|
{
|
|
var options = new TestClientOptions();
|
|
_logger = NullLogger.Instance;
|
|
Initialize(options);
|
|
SubClient = AddApiClient(new TestSubClient(options, new RestApiOptions()));
|
|
}
|
|
|
|
public TestBaseClient(TestClientOptions exchangeOptions) : base(null, "Test")
|
|
{
|
|
_logger = NullLogger.Instance;
|
|
Initialize(exchangeOptions);
|
|
SubClient = AddApiClient(new TestSubClient(exchangeOptions, new RestApiOptions()));
|
|
}
|
|
|
|
public void Log(LogLevel verbosity, string data)
|
|
{
|
|
_logger.Log(verbosity, data);
|
|
}
|
|
}
|
|
|
|
public class TestSubClient : RestApiClient<TestEnvironment, TestAuthProvider, HMACCredential>
|
|
{
|
|
protected override IRestMessageHandler MessageHandler => throw new NotImplementedException();
|
|
|
|
public TestSubClient(RestExchangeOptions<TestEnvironment, HMACCredential> options, RestApiOptions apiOptions) : base(new TraceLogger(), null, "https://localhost:123", options, apiOptions)
|
|
{
|
|
}
|
|
|
|
public CallResult<T> Deserialize<T>(string data)
|
|
{
|
|
return new CallResult<T>(JsonSerializer.Deserialize<T>(data));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
|
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
|
protected override TestAuthProvider CreateAuthenticationProvider(HMACCredential credentials) => throw new NotImplementedException();
|
|
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();
|
|
}
|
|
|
|
public class TestAuthProvider : AuthenticationProvider<HMACCredential, HMACCredential>
|
|
{
|
|
public TestAuthProvider(HMACCredential credentials) : base(credentials, credentials)
|
|
{
|
|
}
|
|
|
|
public override void ProcessRequest(RestApiClient apiClient, RestRequestConfiguration requestConfig)
|
|
{
|
|
}
|
|
|
|
public string GetKey() => Credential.Key;
|
|
public string GetSecret() => Credential.Secret;
|
|
}
|
|
|
|
public class TestEnvironment : TradeEnvironment
|
|
{
|
|
public string TestAddress { get; }
|
|
|
|
public TestEnvironment(string name, string url) : base(name)
|
|
{
|
|
TestAddress = url;
|
|
}
|
|
}
|
|
}
|