mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
BTCMarkets: Add subscription configuration (#1624)
* Subscription: Add List.GroupByPairs * BTCMarkets: Add subscription conf * BTCMarkets: Upgrade test config
This commit is contained in:
@@ -46,6 +46,22 @@ func (l List) GroupPairs() (n List) {
|
||||
return s.List()
|
||||
}
|
||||
|
||||
// GroupByPairs groups subscriptions which have the same Pairs
|
||||
func (l List) GroupByPairs() []List {
|
||||
n := []List{}
|
||||
outer:
|
||||
for _, a := range l {
|
||||
for i, b := range n {
|
||||
if a.Pairs.Equal(b[0].Pairs) { // Note: b is guaranteed to have 1 element by the append(n) below
|
||||
n[i] = append(n[i], a)
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
n = append(n, List{a})
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// Clone returns a deep clone of the List
|
||||
func (l List) Clone() List {
|
||||
n := make(List, len(l))
|
||||
|
||||
@@ -26,7 +26,7 @@ func TestListStrings(t *testing.T) {
|
||||
},
|
||||
}
|
||||
exp := []string{"orderbook ETH/USDC", "ticker spot ETH/USDC,BTC/USDT"}
|
||||
assert.ElementsMatch(t, exp, l.Strings(), "String must return correct sorted list")
|
||||
assert.ElementsMatch(t, exp, l.Strings(), "String should return correct sorted list")
|
||||
}
|
||||
|
||||
// TestQualifiedChannels exercises List.QualifiedChannels()
|
||||
@@ -63,7 +63,26 @@ func TestListGroupPairs(t *testing.T) {
|
||||
assert.Len(t, l, 5, "Orig list should not be changed")
|
||||
assert.Len(t, n, 2, "New list should be grouped")
|
||||
exp := []string{"ticker spot ETH/USDC,BTC/USDT", "orderbook spot ETH/USDC,BTC/USDT"}
|
||||
assert.ElementsMatch(t, exp, n.Strings(), "String must return correct sorted list")
|
||||
assert.ElementsMatch(t, exp, n.Strings(), "String should return correct sorted list")
|
||||
}
|
||||
|
||||
// TestListGroupByPairs exercises List.GroupByPairs()
|
||||
func TestListGroupByPairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := List{
|
||||
{Asset: asset.Spot, Channel: TickerChannel, Pairs: currency.Pairs{ethusdcPair, btcusdtPair}},
|
||||
{Asset: asset.Spot, Channel: OrderbookChannel, Pairs: currency.Pairs{ethusdcPair, btcusdtPair}},
|
||||
{Asset: asset.Spot, Channel: CandlesChannel, Pairs: currency.Pairs{ltcusdcPair, btcusdtPair}},
|
||||
}
|
||||
n := l.GroupByPairs()
|
||||
assert.Len(t, l, 3, "Orig list should not be changed")
|
||||
require.Len(t, n, 2, "New list must be grouped")
|
||||
require.Len(t, n[0], 2, "New list must be grouped")
|
||||
require.Len(t, n[1], 1, "New list must be grouped")
|
||||
exp := []string{"ticker spot ETH/USDC,BTC/USDT", "orderbook spot ETH/USDC,BTC/USDT"}
|
||||
assert.ElementsMatch(t, exp, n[0].Strings(), "String should return correct sorted list")
|
||||
exp = []string{"candles spot LTC/USDC,BTC/USDT"}
|
||||
assert.ElementsMatch(t, exp, n[1].Strings(), "String should return correct sorted list")
|
||||
}
|
||||
|
||||
// TestListSetStates exercises List.SetState()
|
||||
@@ -99,9 +118,9 @@ func TestListClone(t *testing.T) {
|
||||
t.Parallel()
|
||||
l := List{{Channel: TickerChannel}, {Channel: OrderbookChannel}}
|
||||
n := l.Clone()
|
||||
assert.NotSame(t, &n, &l, "Slices must not be the same")
|
||||
assert.NotSame(t, &n, &l, "Slices should not be the same")
|
||||
require.NotEmpty(t, n, "List must not be empty")
|
||||
assert.NotSame(t, n[0], l[0], "Subscriptions must be cloned")
|
||||
assert.NotSame(t, n[0], l[0], "Subscriptions should be cloned")
|
||||
assert.Equal(t, n[0], l[0], "Subscriptions should be equal")
|
||||
l[0].Interval = kline.OneHour
|
||||
assert.NotEqual(t, n[0], l[0], "Subscriptions should be cloned")
|
||||
|
||||
@@ -33,6 +33,7 @@ const (
|
||||
MyOrdersChannel = "myOrders"
|
||||
MyWalletChannel = "myWallet"
|
||||
MyAccountChannel = "myAccount"
|
||||
HeartbeatChannel = "heartbeat"
|
||||
)
|
||||
|
||||
// Public errors
|
||||
|
||||
Reference in New Issue
Block a user