Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cryptoclients update #198

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public CallResult<T> Deserialize<T>(string data)
return deserializeResult;
}

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";
public override TimeSpan? GetTimeOffset() => null;
public override TimeSyncInfo GetTimeSyncInfo() => null;
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public TestRestApi1Client(TestClientOptions options) : base(new TraceLogger(), n
RequestFactory = new Mock<IRequestFactory>().Object;
}

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";

public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
{
return await SendRequestAsync<T>(new Uri("http://www.test.com"), HttpMethod.Get, ct, requestWeight: 0);
Expand Down Expand Up @@ -178,6 +181,9 @@ public TestRestApi2Client(TestClientOptions options) : base(new TraceLogger(), n
RequestFactory = new Mock<IRequestFactory>().Object;
}

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";

public async Task<CallResult<T>> Request<T>(CancellationToken ct = default) where T : class
{
return await SendRequestAsync<T>(new Uri("http://www.test.com"), HttpMethod.Get, ct, requestWeight: 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public TestSubSocketClient(TestSocketOptions options, SocketApiOptions apiOption

}

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset) => $"{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}";

internal IWebsocket CreateSocketInternal(string address)
{
return CreateSocket(address);
Expand Down
3 changes: 3 additions & 0 deletions CryptoExchange.Net/Clients/BaseApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ protected BaseApiClient(ILogger logger, bool outputOriginalData, ApiCredentials?
/// <returns></returns>
protected abstract AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials);

/// <inheritdoc />
public abstract string FormatSymbol(string baseAsset, string quoteAsset);

/// <inheritdoc />
public void SetApiCredentials<T>(T credentials) where T : ApiCredentials
{
Expand Down
8 changes: 8 additions & 0 deletions CryptoExchange.Net/Interfaces/IBaseApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public interface IBaseApiClient
/// </summary>
string BaseAddress { get; }

/// <summary>
/// Format a base and quote asset to an exchange accepted symbol
/// </summary>
/// <param name="baseAsset">The base asset</param>
/// <param name="quoteAsset">The quote asset</param>
/// <returns></returns>
string FormatSymbol(string baseAsset, string quoteAsset);

/// <summary>
/// Set the API credentials for this API client
/// </summary>
Expand Down
27 changes: 27 additions & 0 deletions CryptoExchange.Net/Interfaces/IOrderBookFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using CryptoExchange.Net.Objects.Options;
using System;

namespace CryptoExchange.Net.Interfaces
{
/// <summary>
/// Factory for ISymbolOrderBook instances
/// </summary>
public interface IOrderBookFactory<TOptions> where TOptions : OrderBookOptions
{
/// <summary>
/// Create a new order book by symbol name
/// </summary>
/// <param name="symbol">Symbol name</param>
/// <param name="options">Options for the order book</param>
/// <returns></returns>
public ISymbolOrderBook Create(string symbol, Action<TOptions>? options = null);
/// <summary>
/// Create a new order book by base and quote asset names
/// </summary>
/// <param name="baseAsset">Base asset name</param>
/// <param name="quoteAsset">Quote asset name</param>
/// <param name="options">Options for the order book</param>
/// <returns></returns>
public ISymbolOrderBook Create(string baseAsset, string quoteAsset, Action<TOptions>? options = null);
}
}
6 changes: 1 addition & 5 deletions CryptoExchange.Net/Objects/Options/OrderBookOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Base for order book options
/// </summary>
public class OrderBookOptions : ExchangeOptions
public class OrderBookOptions
{
/// <summary>
/// Whether or not checksum validation is enabled. Default is true, disabling will ignore checksum messages.
Expand All @@ -19,11 +19,7 @@ public class OrderBookOptions : ExchangeOptions
{
return new T
{
ApiCredentials = ApiCredentials?.Copy(),
OutputOriginalData = OutputOriginalData,
ChecksumValidationEnabled = ChecksumValidationEnabled,
Proxy = Proxy,
RequestTimeout = RequestTimeout
};
}
}
Expand Down
30 changes: 30 additions & 0 deletions CryptoExchange.Net/OrderBook/OrderBookFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.Objects.Options;
using System;

namespace CryptoExchange.Net.OrderBook
{
/// <inheritdoc />
public class OrderBookFactory<TOptions> : IOrderBookFactory<TOptions> where TOptions: OrderBookOptions
{
private readonly Func<string, Action<TOptions>?, ISymbolOrderBook> _symbolCtor;
private readonly Func<string, string, Action<TOptions>?, ISymbolOrderBook> _assetsCtor;

/// <summary>
/// ctor
/// </summary>
/// <param name="symbolCtor"></param>
/// <param name="assetsCtor"></param>
public OrderBookFactory(Func<string, Action<TOptions>?, ISymbolOrderBook> symbolCtor, Func<string, string, Action<TOptions>?, ISymbolOrderBook> assetsCtor)
{
_symbolCtor = symbolCtor;
_assetsCtor = assetsCtor;
}

/// <inheritdoc />
public ISymbolOrderBook Create(string symbol, Action<TOptions>? options = null) => _symbolCtor(symbol, options);

/// <inheritdoc />
public ISymbolOrderBook Create(string baseAsset, string quoteAsset, Action<TOptions>? options = null) => _assetsCtor(baseAsset, quoteAsset, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public struct SendItem
public int Id { get; set; }

/// <summary>
/// The request id
/// The request weight
/// </summary>
public int Weight { get; set; }

Expand Down
Loading