Skip to content

Commit 9fee55d

Browse files
committed
Addressed review comments
1 parent c8bfd98 commit 9fee55d

File tree

1 file changed

+20
-32
lines changed

1 file changed

+20
-32
lines changed

Common/Util/CurrencyPairUtil.cs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public static class CurrencyPairUtil
2929
private static readonly Lazy<SymbolPropertiesDatabase> SymbolPropertiesDatabase =
3030
new Lazy<SymbolPropertiesDatabase>(Securities.SymbolPropertiesDatabase.FromDataFolder);
3131

32+
private static readonly int[][] PotentialStableCoins = { [1, 3], [1, 2], [0, 3], [0, 2] };
33+
3234
/// <summary>
3335
/// Tries to decomposes the specified currency pair into a base and quote currency provided as out parameters
3436
/// </summary>
@@ -202,51 +204,37 @@ public enum Match
202204
/// <returns>The <see cref="Match"/> member that represents the relation between the two pairs</returns>
203205
public static Match ComparePair(this Symbol pairA, string baseCurrencyB, string quoteCurrencyB)
204206
{
205-
var pairAValue = "";
206-
207-
// Check for a stablecoin between the currencies
208-
if (TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
207+
if (!TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
209208
{
210-
pairAValue = string.Concat(baseCurrencyA, "||", quoteCurrencyA);
211-
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB };
212-
var isThereAnyMatch = false;
213-
214-
// Compute all the potential stablecoins
215-
var potentialStableCoins = new int[][]
216-
{
217-
new int[]{ 1, 3 },
218-
new int[]{ 1, 2 },
219-
new int[]{ 0, 3 },
220-
new int[]{ 0, 2 }
221-
};
209+
return Match.NoMatch;
210+
}
222211

223-
foreach (var pair in potentialStableCoins)
224-
{
225-
if (Currencies.IsStableCoinWithoutPair(currencies[pair[0]] + currencies[pair[1]], pairA.ID.Market)
226-
|| Currencies.IsStableCoinWithoutPair(currencies[pair[1]] + currencies[pair[0]], pairA.ID.Market))
227-
{
228-
// If there's a stablecoin between them, assign to currency in pair A the value
229-
// of the currency in pair B
230-
currencies[pair[0]] = currencies[pair[1]];
231-
isThereAnyMatch = true;
232-
}
233-
}
212+
// Check for a stablecoin between the currencies
213+
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB };
214+
var isThereAnyMatch = false;
234215

235-
// Update the value of pairAValue if there was a match
236-
if (isThereAnyMatch)
216+
// Compute all the potential stablecoins
217+
foreach (var pair in PotentialStableCoins)
218+
{
219+
if (Currencies.IsStableCoinWithoutPair(currencies[pair[0]] + currencies[pair[1]], pairA.ID.Market)
220+
|| Currencies.IsStableCoinWithoutPair(currencies[pair[1]] + currencies[pair[0]], pairA.ID.Market))
237221
{
238-
pairAValue = string.Concat(currencies[0], "||", currencies[1]);
222+
// If there's a stablecoin between them, assign to currency in pair A the value
223+
// of the currency in pair B
224+
currencies[pair[0]] = currencies[pair[1]];
225+
isThereAnyMatch = true;
239226
}
240227
}
241228

242-
var directPair = string.Concat(baseCurrencyB, "||", quoteCurrencyB);
243-
var inversePair = string.Concat(quoteCurrencyB, "||", baseCurrencyB);
229+
string pairAValue = isThereAnyMatch ? string.Concat(currencies[0], "||", currencies[1]) : string.Concat(baseCurrencyA, "||", quoteCurrencyA);
244230

231+
var directPair = string.Concat(baseCurrencyB, "||", quoteCurrencyB);
245232
if (pairAValue == directPair)
246233
{
247234
return Match.ExactMatch;
248235
}
249236

237+
var inversePair = string.Concat(quoteCurrencyB, "||", baseCurrencyB);
250238
if (pairAValue == inversePair)
251239
{
252240
return Match.InverseMatch;

0 commit comments

Comments
 (0)