-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix to prevent endless looping when reconnecting an authenticated web…
…socket
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,24 +131,49 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToMiniTickerUpdatesAs | |
/// <inheritdoc /> | ||
public async Task<CallResult<UpdateSubscription>> SubscribeToAccountUpdatesAsync(string listenKey, Action<DataEvent<MexcAccountUpdate>> handler, CancellationToken ct = default) | ||
{ | ||
var subscription = new MexcSubscription<MexcAccountUpdate>(_logger, new[] { "[email protected]" }, handler, false); | ||
var subscription = new MexcSubscription<MexcAccountUpdate>(_logger, new[] { "[email protected]" }, handler, true); | ||
return await SubscribeAsync(BaseAddress + "?listenKey=" + listenKey, subscription, ct).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<CallResult<UpdateSubscription>> SubscribeToOrderUpdatesAsync(string listenKey, Action<DataEvent<MexcUserOrderUpdate>> handler, CancellationToken ct = default) | ||
{ | ||
var subscription = new MexcSubscription<MexcUserOrderUpdate>(_logger, new[] { "[email protected]" }, handler, false); | ||
var subscription = new MexcSubscription<MexcUserOrderUpdate>(_logger, new[] { "[email protected]" }, handler, true); | ||
return await SubscribeAsync(BaseAddress + "?listenKey=" + listenKey, subscription, ct).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<CallResult<UpdateSubscription>> SubscribeToUserTradeUpdatesAsync(string listenKey, Action<DataEvent<MexcUserTradeUpdate>> handler, CancellationToken ct = default) | ||
{ | ||
var subscription = new MexcSubscription<MexcUserTradeUpdate>(_logger, new[] { "[email protected]" }, handler, false); | ||
var subscription = new MexcSubscription<MexcUserTradeUpdate>(_logger, new[] { "[email protected]" }, handler, true); | ||
return await SubscribeAsync(BaseAddress + "?listenKey=" + listenKey, subscription, ct).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override async Task<Uri?> GetReconnectUriAsync(SocketConnection connection) | ||
{ | ||
if (connection.Subscriptions.Any(s => s.Authenticated)) | ||
{ | ||
// If any of the subs on the connection is authenticated we request a new listenkey | ||
// to prevent endlessly looping if the listenkey happens to be expired | ||
var creds = ApiOptions.ApiCredentials ?? ClientOptions.ApiCredentials; | ||
var client = new MexcRestClient(opts => | ||
{ | ||
if (creds != null) | ||
opts.ApiCredentials = creds; | ||
}); | ||
|
||
var listenKeyResult = await client.SpotApi.Account.StartUserStreamAsync().ConfigureAwait(false); | ||
if (listenKeyResult) | ||
return new Uri(BaseAddress + "?listenKey=" + listenKeyResult.Data); | ||
} | ||
|
||
return await base.GetReconnectUriAsync(connection).ConfigureAwait(false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override Query? GetAuthenticationRequest() => null; | ||
|
||
private static string GetIntervalString(KlineInterval interval) | ||
=> interval switch | ||
{ | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.