mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-02-16 14:13:46 +00:00
Updated time sync / time offset management for REST API's Added time offset tracking for WebSocket API's Added GetAuthenticationQuery virtual method on AuthenticationProvider Updated AuthenticationProvider GetTimestamp methods to include a one second offset by default Added AuthenticationProvider GetTimestamp methods for SocketApiClient instances Added ClientName property on BaseApiClient, resolving to the type name Added ObjectOrArrayConverter JsonConverterFactory implementation for resolving json data which might be returned as object or array Added UpdateServerTime, UpdateLocalTime and DataAge properties to (I)SymbolOrderBook Added OutputToConsoleAsync method to (I)SymbolOrderBook Updated SymbolOrderBook string representation Added DataTimeLocal and DataAge properties to DataEvent object Added SocketConnection parameter to subscription HandleSubQueryResponse and HandleUnsubQueryResponse methods
98 lines
3.7 KiB
C#
98 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
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
|
|
{
|
|
protected override IRestMessageHandler MessageHandler => throw new NotImplementedException();
|
|
|
|
public TestSubClient(RestExchangeOptions<TestEnvironment> options, RestApiOptions apiOptions) : base(new TraceLogger(), null, "https://localhost:123", options, apiOptions)
|
|
{
|
|
}
|
|
|
|
public CallResult<T> Deserialize<T>(string data)
|
|
{
|
|
var stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
|
|
var accessor = CreateAccessor();
|
|
var valid = accessor.Read(stream, true).Result;
|
|
if (!valid)
|
|
return new CallResult<T>(new ServerError(ErrorInfo.Unknown with { Message = data }));
|
|
|
|
var deserializeResult = accessor.Deserialize<T>();
|
|
return deserializeResult;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode futuresType, DateTime? deliverDate = null) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
|
|
protected override IStreamMessageAccessor CreateAccessor() => new SystemTextJsonStreamMessageAccessor(new System.Text.Json.JsonSerializerOptions());
|
|
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer(new System.Text.Json.JsonSerializerOptions());
|
|
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
|
|
protected override Task<WebCallResult<DateTime>> GetServerTimestampAsync() => throw new NotImplementedException();
|
|
}
|
|
|
|
public class TestAuthProvider : AuthenticationProvider
|
|
{
|
|
public override ApiCredentialsType[] SupportedCredentialTypes => [ApiCredentialsType.Hmac];
|
|
|
|
public TestAuthProvider(ApiCredentials credentials) : base(credentials)
|
|
{
|
|
}
|
|
|
|
public override void ProcessRequest(RestApiClient apiClient, RestRequestConfiguration requestConfig)
|
|
{
|
|
}
|
|
|
|
public string GetKey() => _credentials.Key;
|
|
public string GetSecret() => _credentials.Secret;
|
|
}
|
|
|
|
public class TestEnvironment : TradeEnvironment
|
|
{
|
|
public string TestAddress { get; }
|
|
|
|
public TestEnvironment(string name, string url) : base(name)
|
|
{
|
|
TestAddress = url;
|
|
}
|
|
}
|
|
}
|