Skip to content

Commit

Permalink
Update SPDB with Bitfinex, Kraken, Binance, BinaceUS (#8516)
Browse files Browse the repository at this point in the history
* Update SPDB with Bitfinex, Kraken, Binance, BinaceUS

* Update unit test

* Added TestCase for CNHT and USD

* Fixed bug in pair comparison logic, corrected concatenation approach

* Add unit test for currency pair match

* Added test cases for currency pair comparison

* Addressed review comments
  • Loading branch information
JosueNina authored Jan 10, 2025
1 parent 8ad1016 commit f08eda3
Show file tree
Hide file tree
Showing 7 changed files with 1,491 additions and 884 deletions.
56 changes: 24 additions & 32 deletions Common/Util/CurrencyPairUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public static class CurrencyPairUtil
private static readonly Lazy<SymbolPropertiesDatabase> SymbolPropertiesDatabase =
new Lazy<SymbolPropertiesDatabase>(Securities.SymbolPropertiesDatabase.FromDataFolder);

private static readonly int[][] PotentialStableCoins = { [1, 3], [1, 2], [0, 3], [0, 2] };

/// <summary>
/// Tries to decomposes the specified currency pair into a base and quote currency provided as out parameters
/// </summary>
Expand Down Expand Up @@ -202,48 +204,38 @@ public enum Match
/// <returns>The <see cref="Match"/> member that represents the relation between the two pairs</returns>
public static Match ComparePair(this Symbol pairA, string baseCurrencyB, string quoteCurrencyB)
{
var pairAValue = pairA.ID.Symbol;

// Check for a stablecoin between the currencies
if (TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
if (!TryDecomposeCurrencyPair(pairA, out var baseCurrencyA, out var quoteCurrencyA))
{
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB};
var isThereAnyMatch = false;

// Compute all the potential stablecoins
var potentialStableCoins = new int[][]
{
new int[]{ 1, 3 },
new int[]{ 1, 2 },
new int[]{ 0, 3 },
new int[]{ 0, 2 }
};
return Match.NoMatch;
}

foreach(var pair in potentialStableCoins)
{
if (Currencies.IsStableCoinWithoutPair(currencies[pair[0]] + currencies[pair[1]], pairA.ID.Market)
|| Currencies.IsStableCoinWithoutPair(currencies[pair[1]] + currencies[pair[0]], pairA.ID.Market))
{
// If there's a stablecoin between them, assign to currency in pair A the value
// of the currency in pair B
currencies[pair[0]] = currencies[pair[1]];
isThereAnyMatch = true;
}
}
// Check for a stablecoin between the currencies
var currencies = new string[] { baseCurrencyA, quoteCurrencyA, baseCurrencyB, quoteCurrencyB };
var isThereAnyMatch = false;

// Update the value of pairAValue if there was a match
if (isThereAnyMatch)
// Compute all the potential stablecoins
foreach (var pair in PotentialStableCoins)
{
if (Currencies.IsStableCoinWithoutPair(currencies[pair[0]] + currencies[pair[1]], pairA.ID.Market)
|| Currencies.IsStableCoinWithoutPair(currencies[pair[1]] + currencies[pair[0]], pairA.ID.Market))
{
pairAValue = currencies[0] + currencies[1];
// If there's a stablecoin between them, assign to currency in pair A the value
// of the currency in pair B
currencies[pair[0]] = currencies[pair[1]];
isThereAnyMatch = true;
}
}

if (pairAValue == baseCurrencyB + quoteCurrencyB)
string pairAValue = isThereAnyMatch ? string.Concat(currencies[0], "||", currencies[1]) : string.Concat(baseCurrencyA, "||", quoteCurrencyA);

var directPair = string.Concat(baseCurrencyB, "||", quoteCurrencyB);
if (pairAValue == directPair)
{
return Match.ExactMatch;
}

if (pairAValue == quoteCurrencyB + baseCurrencyB)

var inversePair = string.Concat(quoteCurrencyB, "||", baseCurrencyB);
if (pairAValue == inversePair)
{
return Match.InverseMatch;
}
Expand Down
Loading

0 comments on commit f08eda3

Please sign in to comment.