Skip to content

Commit

Permalink
Feature/cryptoclients update (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf authored Apr 28, 2024
1 parent 5be63bd commit 3505318
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Bitfinex.Net/Bitfinex.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.3.3" />
<PackageReference Include="CryptoExchange.Net" Version="7.4.0" />
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions Bitfinex.Net/Bitfinex.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Bitfinex.Net/BitfinexExchange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Bitfinex.Net
{
/// <summary>
/// Bitfinex exchange information and configuration
/// </summary>
public static class BitfinexExchange
{
/// <summary>
/// Exchange name
/// </summary>
public static string ExchangeName => "Bitfinex";

/// <summary>
/// Url to the main website
/// </summary>
public static string Url { get; } = "https://www.bitfinex.com";

/// <summary>
/// Urls to the API documentation
/// </summary>
public static string[] ApiDocsUrl { get; } = new[] {
"https://docs.bitfinex.com/docs/introduction"
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ internal Uri GetUrl(string endpoint, string version)
return new Uri(BaseAddress.AppendPath($"v{version}", endpoint));
}

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

/// <inheritdoc />
protected override Error ParseErrorResponse(int httpStatusCode, IEnumerable<KeyValuePair<string, IEnumerable<string>>> responseHeaders, IMessageAccessor accessor)
{
Expand Down
3 changes: 3 additions & 0 deletions Bitfinex.Net/Clients/SpotApi/BitfinexRestClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ internal BitfinexRestClientSpotApi(ILogger logger, HttpClient? httpClient, Bitfi
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
=> new BitfinexAuthenticationProvider(credentials, ClientOptions.NonceProvider ?? new BitfinexNonceProvider());

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

#region common interface

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Bitfinex.Net/Clients/SpotApi/BitfinexSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ internal BitfinexSocketClientSpotApi(ILogger logger, BitfinexSocketOptions optio
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
=> new BitfinexAuthenticationProvider(credentials, ClientOptions.NonceProvider ?? new BitfinexNonceProvider());

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

/// <inheritdoc />
protected override Query GetAuthenticationRequest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IServiceCollection AddBitfinex(
return handler;
});

services.AddSingleton<IBitfinexOrderBookFactory, BitfinexOrderBookFactory>();
services.AddTransient<IBitfinexOrderBookFactory, BitfinexOrderBookFactory>();
services.AddTransient<IBitfinexRestClient, BitfinexRestClient>();
services.AddTransient(x => x.GetRequiredService<IBitfinexRestClient>().SpotApi.CommonSpotClient);
if (socketClientLifeTime == null)
Expand Down
5 changes: 5 additions & 0 deletions Bitfinex.Net/Interfaces/IBitfinexOrderBookFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace Bitfinex.Net.Interfaces
/// </summary>
public interface IBitfinexOrderBookFactory
{
/// <summary>
/// Spot order book factory methods
/// </summary>
public IOrderBookFactory<BitfinexOrderBookOptions> Spot { get; }

/// <summary>
/// Create a SymbolOrderBook
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions Bitfinex.Net/SymbolOrderBooks/BitfinexOrderBookFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Bitfinex.Net.Interfaces.Clients;
using Bitfinex.Net.Objects.Options;
using CryptoExchange.Net.Interfaces;
using CryptoExchange.Net.OrderBook;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
Expand All @@ -22,8 +23,13 @@ public class BitfinexOrderBookFactory : IBitfinexOrderBookFactory
public BitfinexOrderBookFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;

Spot = new OrderBookFactory<BitfinexOrderBookOptions>((symbol, options) => Create(symbol, options), (baseAsset, quoteAsset, options) => Create($"t{baseAsset.ToUpperInvariant()}{quoteAsset.ToUpperInvariant()}", options));
}

/// <inheritdoc />
public IOrderBookFactory<BitfinexOrderBookOptions> Spot { get; }

/// <inheritdoc />
public ISymbolOrderBook Create(string symbol, Action<BitfinexOrderBookOptions>? options = null)
=> new BitfinexSymbolOrderBook(symbol,
Expand Down

0 comments on commit 3505318

Please sign in to comment.