Skip to content

Commit e5e044c

Browse files
committed
Fixed bug in pair comparison logic, corrected concatenation approach
1 parent b67df57 commit e5e044c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Common/Util/CurrencyPairUtil.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,25 @@ public enum Match
202202
/// <returns>The <see cref="Match"/> member that represents the relation between the two pairs</returns>
203203
public static Match ComparePair(this Symbol pairA, string baseCurrencyB, string quoteCurrencyB)
204204
{
205-
var pairAValue = pairA.ID.Symbol;
205+
var pairAValue = "";
206206

207207
// Check for a stablecoin between the currencies
208-
if (TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
208+
if (TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
209209
{
210-
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB};
210+
pairAValue = string.Concat(baseCurrencyA, "||", quoteCurrencyA);
211+
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB };
211212
var isThereAnyMatch = false;
212213

213214
// Compute all the potential stablecoins
214-
var potentialStableCoins = new int[][]
215+
var potentialStableCoins = new int[][]
215216
{
216217
new int[]{ 1, 3 },
217218
new int[]{ 1, 2 },
218219
new int[]{ 0, 3 },
219220
new int[]{ 0, 2 }
220221
};
221222

222-
foreach(var pair in potentialStableCoins)
223+
foreach (var pair in potentialStableCoins)
223224
{
224225
if (Currencies.IsStableCoinWithoutPair(currencies[pair[0]] + currencies[pair[1]], pairA.ID.Market)
225226
|| Currencies.IsStableCoinWithoutPair(currencies[pair[1]] + currencies[pair[0]], pairA.ID.Market))
@@ -234,16 +235,19 @@ public static Match ComparePair(this Symbol pairA, string baseCurrencyB, string
234235
// Update the value of pairAValue if there was a match
235236
if (isThereAnyMatch)
236237
{
237-
pairAValue = currencies[0] + currencies[1];
238+
pairAValue = string.Concat(currencies[0], "||", currencies[1]);
238239
}
239240
}
240241

241-
if (pairAValue == baseCurrencyB + quoteCurrencyB)
242+
var directPair = string.Concat(baseCurrencyB, "||", quoteCurrencyB);
243+
var inversePair = string.Concat(quoteCurrencyB, "||", baseCurrencyB);
244+
245+
if (pairAValue == directPair)
242246
{
243247
return Match.ExactMatch;
244248
}
245-
246-
if (pairAValue == quoteCurrencyB + baseCurrencyB)
249+
250+
if (pairAValue == inversePair)
247251
{
248252
return Match.InverseMatch;
249253
}

Tests/Common/Securities/CashTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ private static TimeKeeper TimeKeeper
667667

668668
// USDT (Tether) Cases
669669
new object[] { new BitfinexBrokerageModel(), Currencies.CNH, "USDT", false, new[] { Symbol.Create("USDTCNHT", SecurityType.Crypto, Market.Bitfinex), Symbol.Create("CNHCNHT", SecurityType.Crypto, Market.Bitfinex) } }, // No USDTCNH, but indirect conversion exists
670-
new object[] { new BitfinexBrokerageModel(), Currencies.USD, "CNHT", false, new[] { Symbol.Create("CNHTUSD", SecurityType.Crypto, Market.Bitfinex) } },
671670
new object[] { new BitfinexBrokerageModel(), Currencies.USD, "USDT", false, new[] { Symbol.Create("USDTUSD", SecurityType.Crypto, Market.Bitfinex) } },
672671
new object[] { new BitfinexBrokerageModel(), Currencies.EUR, "USDT", false, new[] { Symbol.Create("EURUSDT", SecurityType.Crypto, Market.Bitfinex) } },
673672
new object[] { new BitfinexBrokerageModel(), Currencies.GBP, "USDT", false, new[] { Symbol.Create("GBPUSDT", SecurityType.Crypto, Market.Bitfinex) } },

0 commit comments

Comments
 (0)