From ef0f398455783248e79fb57a021fa7e96fc34db9 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Mon, 24 Feb 2025 14:26:11 +1100 Subject: [PATCH] exchanges/btse: Handle TRUMPSOL in MarketPair.Pair and add test coverage (#1808) * exchanges/btse: Handle TRUMPSOL in MarketPair.Pair and add test coverage * BTSE: Update test table * nits: Make slight adjustments to test table --- exchanges/btse/btse_test.go | 23 +++++++++++++++++++++++ exchanges/btse/btse_wrapper.go | 13 +++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/exchanges/btse/btse_test.go b/exchanges/btse/btse_test.go index 28f493c0..0572e529 100644 --- a/exchanges/btse/btse_test.go +++ b/exchanges/btse/btse_test.go @@ -752,6 +752,29 @@ func TestStripExponent(t *testing.T) { assert.ErrorIs(t, err, errInvalidPairSymbol, "Should error on a symbol with too many underscores") } +func TestMarketPair(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + symbol string + base string + futures bool + expectedErr error + expectedSymbol string + }{ + {symbol: "RUNEPFC", base: currency.RUNE.String(), futures: true, expectedSymbol: "RUNEPFC"}, + {symbol: "TRUMPPFC", base: "TRUMPSOL", futures: true, expectedSymbol: "TRUMPPFC"}, + {symbol: "BTCUSD", base: "NAUGHTYBASE", futures: true, expectedErr: errInvalidPairSymbol}, + {symbol: "NAUGHTYSYMBOL", base: currency.BTC.String(), expectedErr: errInvalidPairSymbol}, + {symbol: "BTC-USD", base: currency.BTC.String(), expectedSymbol: "BTCUSD"}, + } { + mp := MarketPair{Symbol: tt.symbol, Base: tt.base, Quote: "USD", Futures: tt.futures} + p, err := mp.Pair() + assert.ErrorIs(t, err, tt.expectedErr, "Pair should not error") + assert.Equal(t, tt.expectedSymbol, p.String(), "Pair should return the expected symbol") + } +} + func TestGenerateSubscriptions(t *testing.T) { t.Parallel() diff --git a/exchanges/btse/btse_wrapper.go b/exchanges/btse/btse_wrapper.go index a96959c6..e9b6cac8 100644 --- a/exchanges/btse/btse_wrapper.go +++ b/exchanges/btse/btse_wrapper.go @@ -1051,11 +1051,16 @@ func (m *MarketPair) Pair() (currency.Pair, error) { baseCurr := m.Base var quoteCurr string if m.Futures { - s := strings.Split(m.Symbol, m.Base) // e.g. RUNEPFC for RUNE-USD futures pair - if len(s) <= 1 { - return currency.EMPTYPAIR, errInvalidPairSymbol + if baseCurr == "TRUMPSOL" { // Only base currency which is different to the rest + baseCurr = "TRUMP" + quoteCurr = strings.TrimPrefix(m.Symbol, baseCurr) + } else { + s := strings.Split(m.Symbol, m.Base) // e.g. RUNEPFC for RUNE-USD futures pair + if len(s) <= 1 { + return currency.EMPTYPAIR, errInvalidPairSymbol + } + quoteCurr = s[1] } - quoteCurr = s[1] } else { s := strings.Split(m.Symbol, currency.DashDelimiter) if len(s) != 2 {