Skip to content

Commit

Permalink
CryptoExchange.Net update
Browse files Browse the repository at this point in the history
Updated CryptoExchange.Net to version 8.8.0, see https://github.com/JKorf/CryptoExchange.Net/releases/
Added support for more SharedKlineInterval values
Added setting of DataTime value on websocket DataEvent updates
Fix Mono runtime exception on rest client construction using DI
  • Loading branch information
JKorf committed Feb 10, 2025
1 parent 7736243 commit a2b9eb2
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Bitfinex.Net.UnitTests/BitfinexRestIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Bitfinex.Net.UnitTests
{
[NonParallelizable]
internal class BitfinexRestIntegrationTests : RestIntergrationTest<BitfinexRestClient>
internal class BitfinexRestIntegrationTests : RestIntegrationTest<BitfinexRestClient>
{
public override bool Run { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Bitfinex.Net/Bitfinex.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="8.7.3" />
<PackageReference Include="CryptoExchange.Net" Version="8.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions Bitfinex.Net/Clients/SpotApi/BitfinexSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToRawFundingOrderBook
/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToTradeUpdatesAsync(string symbol, Action<DataEvent<IEnumerable<BitfinexTradeSimple>>> handler, CancellationToken ct = default)
{
var subscription = new BitfinexSubscription<BitfinexTradeSimple>(_logger, "trades", symbol, handler);
var subscription = new BitfinexSubscription<BitfinexTradeSimple>(_logger, "trades", symbol, x => handler(x.WithDataTimestamp(x.Data.Max(x => x.Timestamp))));
return await SubscribeAsync(BaseAddress.AppendPath("ws/2"), subscription, ct).ConfigureAwait(false);
}

Expand All @@ -163,14 +163,14 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToKlineUpdatesAsync(s
/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToLiquidationUpdatesAsync(Action<DataEvent<IEnumerable<BitfinexLiquidation>>> handler, CancellationToken ct = default)
{
var subscription = new BitfinexSubscription<BitfinexLiquidation>(_logger, "status", null, handler, key: $"liq:global");
var subscription = new BitfinexSubscription<BitfinexLiquidation>(_logger, "status", null, x => handler(x.WithDataTimestamp(x.Data.Max(x => x.Timestamp))), key: $"liq:global");
return await SubscribeAsync(BaseAddress.AppendPath("ws/2"), subscription, ct).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToDerivativesUpdatesAsync(string symbol, Action<DataEvent<BitfinexDerivativesStatusUpdate>> handler, CancellationToken ct = default)
{
var subscription = new BitfinexSubscription<BitfinexDerivativesStatusUpdate>(_logger, "status", null, x => handler(x.As(x.Data.Single())), key: $"deriv:" + symbol);
var subscription = new BitfinexSubscription<BitfinexDerivativesStatusUpdate>(_logger, "status", null, x => handler(x.As(x.Data.Single()).WithDataTimestamp(x.Data.Single().Timestamp)), key: $"deriv:" + symbol);
return await SubscribeAsync(BaseAddress.AppendPath("ws/2"), subscription, ct).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ async Task<ExchangeResult<UpdateSubscription>> IUserTradeSocketClient.SubscribeT
#endregion

#region Kline client
SubscribeKlineOptions IKlineSocketClient.SubscribeKlineOptions { get; } = new SubscribeKlineOptions(false);
SubscribeKlineOptions IKlineSocketClient.SubscribeKlineOptions { get; } = new SubscribeKlineOptions(false,
SharedKlineInterval.OneMinute,
SharedKlineInterval.ThreeMinutes,
SharedKlineInterval.FiveMinutes,
SharedKlineInterval.FifteenMinutes,
SharedKlineInterval.ThirtyMinutes,
SharedKlineInterval.OneHour,
SharedKlineInterval.SixHours,
SharedKlineInterval.TwelveHours,
SharedKlineInterval.OneDay,
SharedKlineInterval.OneWeek,
SharedKlineInterval.OneMonth);
async Task<ExchangeResult<UpdateSubscription>> IKlineSocketClient.SubscribeToKlineUpdatesAsync(SubscribeKlineRequest request, Action<ExchangeEvent<SharedKline>> handler, CancellationToken ct)
{
var interval = (Enums.KlineInterval)request.Interval;
Expand Down
4 changes: 2 additions & 2 deletions Bitfinex.Net/ExtensionMethods/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private static IServiceCollection AddBitfinexCore(
handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
handler.DefaultProxyCredentials = CredentialCache.DefaultCredentials;
}
catch (PlatformNotSupportedException)
{ }
catch (PlatformNotSupportedException) { }
catch (NotImplementedException) { } // Mono runtime throws NotImplementedException for DefaultProxyCredentials setting

var options = serviceProvider.GetRequiredService<IOptions<BitfinexRestOptions>>().Value;
if (options.Proxy != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Bitfinex.Net.Objects.Sockets.Subscriptions
{
Expand Down Expand Up @@ -151,35 +152,35 @@ public BitfinexUserSubscription(ILogger logger,
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
if (message.Data is BitfinexSocketEvent<List<BitfinexPosition>> positionSnapshot)
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(positionSnapshot.Data, "ps", null, SocketUpdateType.Snapshot));
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(positionSnapshot.Data, "ps", null, SocketUpdateType.Snapshot).WithDataTimestamp(positionSnapshot.Data.Max(x => x.UpdateTime)));
else if (message.Data is BitfinexSocketEvent<BitfinexPosition> positionUpdate)
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(new[] { positionUpdate.Data }, EnumConverter.GetString(positionUpdate.EventType), positionUpdate.Data.Symbol, SocketUpdateType.Update));
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(new[] { positionUpdate.Data }, EnumConverter.GetString(positionUpdate.EventType), positionUpdate.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(positionUpdate.Data.UpdateTime));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFunding>> loanSnapshot)
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(loanSnapshot.Data, "fls", null, SocketUpdateType.Snapshot));
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(loanSnapshot.Data, "fls", null, SocketUpdateType.Snapshot).WithDataTimestamp(loanSnapshot.Data.Max(x => x.UpdateTime)));
else if (message.Data is BitfinexSocketEvent<BitfinexFunding> loanUpdate)
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(new[] { loanUpdate.Data }, EnumConverter.GetString(loanUpdate.EventType), loanUpdate.Data.Symbol, SocketUpdateType.Update));
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(new[] { loanUpdate.Data }, EnumConverter.GetString(loanUpdate.EventType), loanUpdate.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(loanUpdate.Data.UpdateTime));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFundingCredit>> creditSnapshot)
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(creditSnapshot.Data, "fcs", null, SocketUpdateType.Snapshot));
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(creditSnapshot.Data, "fcs", null, SocketUpdateType.Snapshot).WithDataTimestamp(creditSnapshot.Data.Max(x => x.UpdateTime)));
else if (message.Data is BitfinexSocketEvent<BitfinexFundingCredit> creditUpdate)
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(new[] { creditUpdate.Data }, EnumConverter.GetString(creditUpdate.EventType), creditUpdate.Data.Symbol, SocketUpdateType.Update));
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(new[] { creditUpdate.Data }, EnumConverter.GetString(creditUpdate.EventType), creditUpdate.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(creditUpdate.Data.UpdateTime));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFundingOffer>> offerSnapshot)
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(offerSnapshot.Data, "fos", null, SocketUpdateType.Snapshot));
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(offerSnapshot.Data, "fos", null, SocketUpdateType.Snapshot).WithDataTimestamp(offerSnapshot.Data.Max(x => x.UpdateTime)));
else if (message.Data is BitfinexSocketEvent<BitfinexFundingOffer> offerUpdate)
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(new[] { offerUpdate.Data }, EnumConverter.GetString(offerUpdate.EventType), offerUpdate.Data.Symbol, SocketUpdateType.Update));
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(new[] { offerUpdate.Data }, EnumConverter.GetString(offerUpdate.EventType), offerUpdate.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(offerUpdate.Data.UpdateTime));

else if (message.Data is BitfinexSocketEvent<List<BitfinexOrder>> orderSnapshot)
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(orderSnapshot.Data, "os", null, SocketUpdateType.Snapshot));
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(orderSnapshot.Data, "os", null, SocketUpdateType.Snapshot).WithDataTimestamp(orderSnapshot.Data.Max(x => x.UpdateTime)));
else if (message.Data is BitfinexSocketEvent<BitfinexOrder> orderUpdate)
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(new[] { orderUpdate.Data }, EnumConverter.GetString(orderUpdate.EventType), orderUpdate.Data.Symbol, SocketUpdateType.Update));
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(new[] { orderUpdate.Data }, EnumConverter.GetString(orderUpdate.EventType), orderUpdate.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(orderUpdate.Data.UpdateTime));

else if (message.Data is BitfinexSocketEvent<BitfinexFundingTrade> fundingTrade)
_fundingTradeHandler?.Invoke(message.As(fundingTrade.Data, EnumConverter.GetString(fundingTrade.EventType), null, SocketUpdateType.Update));
_fundingTradeHandler?.Invoke(message.As(fundingTrade.Data, EnumConverter.GetString(fundingTrade.EventType), null, SocketUpdateType.Update).WithDataTimestamp(fundingTrade.Data.Timestamp));

else if (message.Data is BitfinexSocketEvent<BitfinexTradeDetails> trade)
_tradeHandler?.Invoke(message.As(trade.Data, EnumConverter.GetString(trade.EventType), trade.Data.Symbol, SocketUpdateType.Update));
_tradeHandler?.Invoke(message.As(trade.Data, EnumConverter.GetString(trade.EventType), trade.Data.Symbol, SocketUpdateType.Update).WithDataTimestamp(trade.Data.Timestamp));

else if (message.Data is BitfinexSocketEvent<List<BitfinexWallet>> walletSnapshot)
_walletHandler?.Invoke(message.As<IEnumerable<BitfinexWallet>>(walletSnapshot.Data, "ws", null, SocketUpdateType.Snapshot));
Expand Down

0 comments on commit a2b9eb2

Please sign in to comment.