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 3b6fd4e commit 0cfb578
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Kucoin.Net/Clients/FuturesApi/KucoinSocketClientFuturesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ internal KucoinSocketClientFuturesApi(ILogger logger, KucoinSocketClient baseCli
public override string GetListenerIdentifier(IMessageAccessor message)
{
var type = message.GetValue<string>(_typePath);
if (type == "welcome")
return type;
if (string.Equals(type, "welcome", StringComparison.Ordinal))
return type!;

var id = message.GetValue<string>(_idPath);
if (type != "message" && id != null)
if (!string.Equals(type, "message", StringComparison.Ordinal) && id != null)
return id;

return message.GetValue<string>(_topicPath)!;
Expand Down
8 changes: 4 additions & 4 deletions Kucoin.Net/Clients/SpotApi/KucoinSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
public override string GetListenerIdentifier(IMessageAccessor message)
{
var type = message.GetValue<string>(_typePath);
if (type == "welcome")
return type;
if (string.Equals(type, "welcome", StringComparison.Ordinal))
return type!;

var topic = message.GetValue<string>(_topicPath);
var id = message.GetValue<string>(_idPath);
if (id != null)
{
if (topic == "/account/balance")
if (string.Equals(topic, "/account/balance", StringComparison.Ordinal))
// This update also contain an id field, but should be identified by the topic regardless
return topic;
return topic!;

return id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Kucoin.Net.Enums;
using Newtonsoft.Json;
using System;

namespace Kucoin.Net.Objects.Models.Futures.Socket
{
Expand All @@ -21,7 +22,7 @@ public class KucoinFuturesOrderBookChange
/// <summary>
/// Side
/// </summary>
public OrderSide Side => Change.Split(',')[1] == "sell" ? OrderSide.Sell : OrderSide.Buy;
public OrderSide Side => string.Equals(Change.Split(',')[1], "sell", StringComparison.Ordinal) ? OrderSide.Sell : OrderSide.Buy;
/// <summary>
/// Quantity
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion Kucoin.Net/Objects/Sockets/Queries/KucoinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CryptoExchange.Net.Objects.Sockets;
using CryptoExchange.Net.Sockets;
using Kucoin.Net.Objects.Internal;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -20,7 +21,7 @@ public KucoinQuery(string type, string topic, bool auth) : base(new KucoinReques
public override CallResult<KucoinSocketResponse> HandleMessage(SocketConnection connection, DataEvent<KucoinSocketResponse> message)
{
var kucoinResponse = message.Data;
if (kucoinResponse.Type == "error")
if (string.Equals(kucoinResponse.Type, "error", StringComparison.Ordinal))
return new CallResult<KucoinSocketResponse>(new ServerError(kucoinResponse.Code ?? 0, kucoinResponse.Data!));

return base.HandleMessage(connection, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
public override Type? GetMessageType(IMessageAccessor message)
{
var subject = message.GetValue<string>(_subjectPath);
if (subject == "orderMargin.change")
if (string.Equals(subject, "orderMargin.change", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinStreamOrderMarginUpdate>);
if (subject == "availableBalance.change")
if (string.Equals(subject, "availableBalance.change", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinStreamFuturesBalanceUpdate>);
return typeof(KucoinSocketUpdate<KucoinStreamFuturesWithdrawableUpdate>);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
public override Type? GetMessageType(IMessageAccessor message)
{
var subject = message.GetValue<string>(_subjectPath);
if (subject == "mark.index.price")
if (string.Equals(subject, "mark.index.price", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinStreamFuturesMarkIndexPrice>);
return typeof(KucoinSocketUpdate<KucoinStreamFuturesFundingRate>);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
public override Type? GetMessageType(IMessageAccessor message)
{
var type = message.GetValue<string>(_typePath);
if (type == "match")
if (string.Equals(type, "match", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinStreamOrderMatchUpdate>);
if (type == "received")
if (string.Equals(type, "received", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinStreamOrderNewUpdate>);
return typeof(KucoinSocketUpdate<KucoinStreamOrderUpdate>);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
public override Type? GetMessageType(IMessageAccessor message)
{
var subject = message.GetValue<string>(_subjectPath);
if (subject == "position.change")
if (string.Equals(subject, "position.change", StringComparison.Ordinal))
{
var change = message.GetValue<string>(_changeReasonPath);
if (change == null || change == "markPriceChange")
if (change == null || string.Equals(change, "markPriceChange", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinPositionMarkPriceUpdate>);
else
return typeof(KucoinSocketUpdate<KucoinPositionUpdate>);
}
if (subject == "position.settlement")
if (string.Equals(subject, "position.settlement", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinPositionFundingSettlementUpdate>);
if (subject == "position.adjustRiskLimit")
if (string.Equals(subject, "position.adjustRiskLimit", StringComparison.Ordinal))
return typeof(KucoinSocketUpdate<KucoinPositionRiskAdjustResultUpdate>);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
{
var data = (KucoinSocketUpdate<T>)message.Data;
string? topic = data.Topic.Contains(":") ? data.Topic.Split(':').Last() : null;
if (topic == "all")
if (string.Equals(topic, "all", StringComparison.Ordinal))
topic = data.Subject;

_handler.Invoke(message.As(data.Data, topic, SocketUpdateType.Update));
Expand Down

0 comments on commit 0cfb578

Please sign in to comment.