Skip to content

Commit

Permalink
String comparison improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Mar 27, 2024
1 parent b17943a commit 3e5114d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ByBit.Net/BybitAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ internal class BybitComparer : IComparer<string>
{
public int Compare(string x, string y)
{
if (x == "sign")
if (string.Equals(x, "sign", StringComparison.Ordinal))
return 1;
if (y == "sign")
if (string.Equals(y, "sign", StringComparison.Ordinal))
return -1;

return x.CompareTo(y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
public override string? GetListenerIdentifier(IMessageAccessor message)
{
var type = message.GetValue<string>(_typePath);
if (type == "COMMAND_RESP" || type == "AUTH_RESP")
if (string.Equals(type, "COMMAND_RESP", StringComparison.Ordinal)
|| string.Equals(type, "AUTH_RESP", StringComparison.Ordinal))
{
return type;
}

return message.GetValue<string>(_opPath);
}
Expand Down
4 changes: 2 additions & 2 deletions ByBit.Net/Clients/V5/BybitSocketClientOptionApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal BybitSocketClientOptionApi(ILogger log, BybitSocketOptions options)
public override string? GetListenerIdentifier(IMessageAccessor message)
{
var type = message.GetValue<string>(_typePath);
if (type == "COMMAND_RESP")
if (string.Equals(type, "COMMAND_RESP", StringComparison.Ordinal))
{
var success = message.GetValues<string>(_successPath);
if (success == null)
Expand All @@ -47,7 +47,7 @@ internal BybitSocketClientOptionApi(ILogger log, BybitSocketOptions options)
}

var op = message.GetValue<string>(_opPath);
if (op == "pong")
if (string.Equals(op, "pong", StringComparison.Ordinal))
return "pong";

return message.GetValue<string>(_topicPath);
Expand Down
3 changes: 2 additions & 1 deletion ByBit.Net/Objects/Sockets/Queries/BybitUnifiedQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Sockets;
using CryptoExchange.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -14,7 +15,7 @@ internal class BybitUnifiedQuery : Query<BybitOptionsQueryResponse>

public BybitUnifiedQuery(string op, params object[] args) : base(new BybitRequestMessage { RequestId = ExchangeHelpers.NextId().ToString(), Operation = op, Args = args?.ToList() }, false, 1)
{
if (op == "auth")
if (string.Equals(op, "auth", StringComparison.Ordinal))
ListenerIdentifiers = new HashSet<string>() { "AUTH_RESP" };
else
ListenerIdentifiers = new HashSet<string>() { "COMMAND_RESP" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BybitOptionsSubscription(ILogger logger, string[] topics, Action<DataEven
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, data.Type == "snapshot" ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BybitSubscription(ILogger logger, string[] topics, Action<DataEvent<T>> h
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, data.Type == "snapshot" ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BybitUnifiedSubscription(ILogger logger, string[] topics, Action<DataEven
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, data.Type == "snapshot" ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down

0 comments on commit 3e5114d

Please sign in to comment.