1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-04 02:11:11 +00:00

Added UsePublicConnectionForAuth property to SocketApiClient

This commit is contained in:
Jkorf
2026-08-21 09:44:30 +02:00
parent c2b58ab19a
commit b8bd30a09d
+10 -1
View File
@@ -97,6 +97,11 @@ namespace CryptoExchange.Net.Clients
/// </summary> /// </summary>
protected bool AllowTopicsOnTheSameConnection { get; set; } = true; protected bool AllowTopicsOnTheSameConnection { get; set; } = true;
/// <summary>
/// Whether to allow usage of a current public WebSocket connection for an authenticated request
/// </summary>
protected bool UsePublicConnectionForAuth { get; set; } = false;
/// <inheritdoc /> /// <inheritdoc />
public double IncomingKbps public double IncomingKbps
{ {
@@ -688,7 +693,7 @@ namespace CryptoExchange.Net.Clients
_logger.WaitedForReconnectingSocket((long)(DateTime.UtcNow - delayStart).TotalMilliseconds); _logger.WaitedForReconnectingSocket((long)(DateTime.UtcNow - delayStart).TotalMilliseconds);
socketQuery = socketQuery.Where(s => (s.Status == SocketStatus.None || s.Status == SocketStatus.Connected) socketQuery = socketQuery.Where(s => (s.Status == SocketStatus.None || s.Status == SocketStatus.Connected)
&& (s.Authenticated == authenticated || !authenticated) && (s.Authenticated == authenticated || !authenticated || UsePublicConnectionForAuth)
&& s.Connected).ToList(); && s.Connected).ToList();
bool maxConnectionsReached = _socketConnections.Count >= (ApiOptions.MaxSocketConnections ?? ClientOptions.MaxSocketConnections); bool maxConnectionsReached = _socketConnections.Count >= (ApiOptions.MaxSocketConnections ?? ClientOptions.MaxSocketConnections);
@@ -702,12 +707,14 @@ namespace CryptoExchange.Net.Clients
} }
if (connection == null) if (connection == null)
{
// Use an eligible non-dedicated connection for subscriptions, or as fallback when no dedicated request connection is available // Use an eligible non-dedicated connection for subscriptions, or as fallback when no dedicated request connection is available
connection = socketQuery connection = socketQuery
.Where(s => !s.DedicatedRequestConnection.IsDedicatedRequestConnection) .Where(s => !s.DedicatedRequestConnection.IsDedicatedRequestConnection)
.Where(s => IsConnectionEligible(s, individualSubscriptionCount, maxConnectionsReached)) .Where(s => IsConnectionEligible(s, individualSubscriptionCount, maxConnectionsReached))
.OrderBy(s => s.UserSubscriptionCount) .OrderBy(s => s.UserSubscriptionCount)
.FirstOrDefault(); .FirstOrDefault();
}
if (connection != null) if (connection != null)
return CallResult.Ok(connection); return CallResult.Ok(connection);
@@ -786,7 +793,9 @@ namespace CryptoExchange.Net.Clients
if ((!lessThanBatchSubCombineTarget || !lessThanIndividualSubCombineTarget) if ((!lessThanBatchSubCombineTarget || !lessThanIndividualSubCombineTarget)
&& !maxConnectionsReached) && !maxConnectionsReached)
{
return false; return false;
}
return MaxIndividualSubscriptionsPerConnection == null return MaxIndividualSubscriptionsPerConnection == null
|| currentIndividualSubscriptionCount + individualSubscriptionCount <= MaxIndividualSubscriptionsPerConnection; || currentIndividualSubscriptionCount + individualSubscriptionCount <= MaxIndividualSubscriptionsPerConnection;