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 6daa8be commit c1a0c73
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Bitfinex.Net/Clients/SpotApi/BitfinexSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public async Task<CallResult<BitfinexFundingOffer>> CancelFundingOfferAsync(long
return message.GetValue<int>(_0Path).ToString();

var evnt = message.GetValue<string>(_eventPath);
if (evnt == "info")
if (string.Equals(evnt, "info", StringComparison.Ordinal))
return "info";

var channel = message.GetValue<string>(_channelPath);
Expand All @@ -366,7 +366,7 @@ public async Task<CallResult<BitfinexFundingOffer>> CancelFundingOfferAsync(long
var freq = message.GetValue<string>(_freqPath);
var len = message.GetValue<string>(_lenPath);
var key = message.GetValue<string>(_keyPath);
var chanId = evnt == "unsubscribed" ? message.GetValue<string>(_chanIdPath) : "";
var chanId = string.Equals(evnt, "unsubscribed", StringComparison.Ordinal) ? message.GetValue<string>(_chanIdPath) : "";
return chanId + evnt + channel + symbol + prec + freq + len + key;
}

Expand Down
5 changes: 3 additions & 2 deletions Bitfinex.Net/Objects/Sockets/Queries/BitfinexSubQuery.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Objects.Sockets;
using CryptoExchange.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -21,7 +22,7 @@ public BitfinexSubQuery(string evnt, string channel, string? symbol, string? pre
Key = key
}, false, 1)
{
if (evnt == "subscribe" || evnt == "unsubscribe")
if (string.Equals(evnt, "subscribe", StringComparison.Ordinal) || string.Equals(evnt, "unsubscribe", StringComparison.Ordinal))
evnt += "d";

ListenerIdentifiers = new HashSet<string>
Expand All @@ -33,7 +34,7 @@ public BitfinexSubQuery(string evnt, string channel, string? symbol, string? pre

public override CallResult<BitfinexResponse> HandleMessage(SocketConnection connection, DataEvent<BitfinexResponse> message)
{
if (message.Data.Event == "error")
if (string.Equals(message.Data.Event, "error", StringComparison.Ordinal))
return new CallResult<BitfinexResponse>(new ServerError(message.Data.Message!));

return new CallResult<BitfinexResponse>(message.Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public BitfinexSubscription(ILogger logger,
{
var identifier = message.GetValue<string>(_1Path);

if (identifier == "cs")
if (string.Equals(identifier, "cs", StringComparison.Ordinal))
return typeof(BitfinexChecksum);

if (identifier == "hb")
if (string.Equals(identifier, "hb", StringComparison.Ordinal))
return typeof(BitfinexUpdate<string>);

if (identifier == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,80 @@ internal class BitfinexUserSubscription : Subscription<BitfinexResponse, Bitfine
{
var identifier = message.GetValue<string>(_messagePath);

if (identifier == "hb")
if (string.Equals(identifier, "hb", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<string>);

if (identifier == "ps")
if (string.Equals(identifier, "ps", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexPosition>>);
if (identifier == "pn" || identifier == "pu" || identifier == "pc")
if (string.Equals(identifier, "pn", StringComparison.Ordinal)
|| string.Equals(identifier, "pu", StringComparison.Ordinal)
|| string.Equals(identifier, "pc", StringComparison.Ordinal))
{
return typeof(BitfinexSocketEvent<BitfinexPosition>);
}

if (identifier == "bu")
if (string.Equals(identifier, "bu", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexBalance>);

if (identifier == "miu")
if (string.Equals(identifier, "miu", StringComparison.Ordinal))
{
var marginInfoType = message.GetValue<string>(_marginInfoPath);
return marginInfoType == "base" ? typeof(BitfinexSocketEvent<BitfinexMarginBase>) : typeof(BitfinexSocketEvent<BitfinexMarginSymbol>);
return string.Equals(marginInfoType, "base", StringComparison.Ordinal) ? typeof(BitfinexSocketEvent<BitfinexMarginBase>) : typeof(BitfinexSocketEvent<BitfinexMarginSymbol>);
}

if (identifier == "fiu")
if (string.Equals(identifier, "fiu", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexFundingInfo>);

if (identifier == "ws")
if (string.Equals(identifier, "ws", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexWallet>>);
if (identifier == "wu")
if (string.Equals(identifier, "wu", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexWallet>);

if (identifier == "os")
if (string.Equals(identifier, "os", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexOrder>>);
if (identifier == "on" || identifier == "ou" || identifier == "oc")
if (string.Equals(identifier, "on", StringComparison.Ordinal)
|| string.Equals(identifier, "ou", StringComparison.Ordinal)
|| string.Equals(identifier, "oc", StringComparison.Ordinal))
{
return typeof(BitfinexSocketEvent<BitfinexOrder>);
}

if (identifier == "te")
if (string.Equals(identifier, "te", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexTradeDetails>);
if (identifier == "tu")
if (string.Equals(identifier, "tu", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexTradeDetails>);

if (identifier == "fte")
if (string.Equals(identifier, "fte", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexFundingTrade>);
if (identifier == "ftu")
if (string.Equals(identifier, "ftu", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<BitfinexFundingTrade>);

if (identifier == "fos")
if (string.Equals(identifier, "fos", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexFundingOffer>>);
if (identifier == "fon" || identifier == "fou" || identifier == "foc")
if (string.Equals(identifier, "fon", StringComparison.Ordinal)
|| string.Equals(identifier, "fou", StringComparison.Ordinal)
|| string.Equals(identifier, "foc", StringComparison.Ordinal))
{
return typeof(BitfinexSocketEvent<BitfinexFundingOffer>);
}

if (identifier == "fcs")
if (string.Equals(identifier, "fcs", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexFundingCredit>>);
if (identifier == "fcn" || identifier == "fcu" || identifier == "fcc")
if (string.Equals(identifier, "fcn", StringComparison.Ordinal)
|| string.Equals(identifier, "fcu", StringComparison.Ordinal)
|| string.Equals(identifier, "fcc", StringComparison.Ordinal))
{
return typeof(BitfinexSocketEvent<BitfinexFundingCredit>);
}

if (identifier == "fls")
if (string.Equals(identifier, "fls", StringComparison.Ordinal))
return typeof(BitfinexSocketEvent<List<BitfinexFunding>>);
if (identifier == "fln" || identifier == "flu" || identifier == "flc")
if (string.Equals(identifier, "fln", StringComparison.Ordinal)
|| string.Equals(identifier, "flu", StringComparison.Ordinal)
|| string.Equals(identifier, "flc", StringComparison.Ordinal))
{
return typeof(BitfinexSocketEvent<BitfinexFunding>);
}

return null;
}
Expand Down

0 comments on commit c1a0c73

Please sign in to comment.