Skip to content

Commit

Permalink
Fixed websocket subscription request revitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Oct 22, 2024
1 parent c669e32 commit 22c571a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 6 additions & 1 deletion Kraken.Net/Clients/SpotApi/KrakenSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,12 @@ public async Task<CallResult<KrakenCancelAfterResult>> CancelAllOrdersAfterAsync
/// <inheritdoc />
protected override async Task<CallResult> RevitalizeRequestAsync(Subscription subscription)
{
var krakenSubscription = (KrakenSubscription)subscription;
var krakenSubscription = subscription as KrakenSubscription;
if (krakenSubscription == null)
{
// Heartbeat subscription
return new CallResult(null);
}

if (!krakenSubscription.TokenRequired)
return new CallResult(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@

namespace Kraken.Net.Objects.Sockets.Subscriptions.Spot
{
internal class KrakenBalanceSubscription : Subscription<KrakenSocketResponseV2<KrakenSocketSubResponse>, KrakenSocketResponseV2<KrakenSocketSubResponse>>
internal class KrakenBalanceSubscription : KrakenSubscription
{
private static readonly MessagePath _typePath = MessagePath.Get().Property("type");

private readonly Action<DataEvent<IEnumerable<KrakenBalanceSnapshot>>>? _snapshotHandler;
private readonly Action<DataEvent<IEnumerable<KrakenBalanceUpdate>>> _updateHandler;

private bool? _snapshot;
private string _token;

public override HashSet<string> ListenerIdentifiers { get; set; }

public KrakenBalanceSubscription(ILogger logger, bool? snapshot, string token, Action<DataEvent<IEnumerable<KrakenBalanceSnapshot>>>? snapshotHandler, Action<DataEvent<IEnumerable<KrakenBalanceUpdate>>> updateHandler) : base(logger, false)
public KrakenBalanceSubscription(ILogger logger, bool? snapshot, string token, Action<DataEvent<IEnumerable<KrakenBalanceSnapshot>>>? snapshotHandler, Action<DataEvent<IEnumerable<KrakenBalanceUpdate>>> updateHandler) : base(logger, true)
{
_snapshot = snapshot;
_token = token;
Token = token;

_snapshotHandler = snapshotHandler;
_updateHandler = updateHandler;
Expand All @@ -50,7 +49,7 @@ public KrakenBalanceSubscription(ILogger logger, bool? snapshot, string token, A
{
Channel = "balances",
Snapshot = _snapshot,
Token = _token
Token = Token
}
}, false);
}
Expand All @@ -66,7 +65,7 @@ public KrakenBalanceSubscription(ILogger logger, bool? snapshot, string token, A
{
Channel = "balances",
Snapshot = _snapshot,
Token = _token
Token = Token
}
}, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@

namespace Kraken.Net.Objects.Sockets.Subscriptions.Spot
{
internal class KrakenOrderSubscription : Subscription<KrakenSocketResponseV2<KrakenSocketSubResponse>, KrakenSocketResponseV2<KrakenSocketSubResponse>>
internal class KrakenOrderSubscription : KrakenSubscription
{
private static readonly MessagePath _typePath = MessagePath.Get().Property("type");

private readonly Action<DataEvent<IEnumerable<KrakenOrderUpdate>>> _updateHandler;

private bool? _snapshotOrder;
private bool? _snapshotTrades;
private string _token;

public override HashSet<string> ListenerIdentifiers { get; set; }

public KrakenOrderSubscription(ILogger logger, bool? snapshotOrder, bool? snapshotTrades, string token, Action<DataEvent<IEnumerable<KrakenOrderUpdate>>> updateHandler) : base(logger, false)
public KrakenOrderSubscription(ILogger logger, bool? snapshotOrder, bool? snapshotTrades, string token, Action<DataEvent<IEnumerable<KrakenOrderUpdate>>> updateHandler) : base(logger, true)
{
_snapshotOrder = snapshotOrder;
_snapshotTrades = snapshotTrades;
_token = token;
Token = token;

_updateHandler = updateHandler;

Expand All @@ -47,7 +46,7 @@ public KrakenOrderSubscription(ILogger logger, bool? snapshotOrder, bool? snapsh
Channel = "executions",
SnapshotOrders = _snapshotOrder,
SnapshotTrades = _snapshotTrades,
Token = _token
Token = Token
}
}, false);
}
Expand All @@ -62,7 +61,7 @@ public KrakenOrderSubscription(ILogger logger, bool? snapshotOrder, bool? snapsh
Parameters = new KrakenSocketSubRequest
{
Channel = "executions",
Token = _token
Token = Token
}
}, false);
}
Expand Down

0 comments on commit 22c571a

Please sign in to comment.