Kraken: Subscription improvements (#1587)

* Convert: Fix TimeFromUnixTimestampDecimal using local

All parsed times should be in UTC

* Subscriptions: Add IgnoringAssetsKey

* Tests: Pass tb to curried WS handlers

* Websocket: Make ErrNoMessageListener a public error

* Kraken: Fix URLMap ignored for websocket URLs

* Kraken: Move SeedAssets from Setup to Bootstrap

Having SeedAssets in Setup is cruel and unusual because it calls the
API. Most other interactive data seeding happens in Bootstrap.

This made it so that fixing and creating unit tests for Kraken was
painfully slow, particularly on flaky internet.

* Kraken: Remove convert test

Duplicate of convert_test.go TestTimeFromUnixTimestampDecimal

* Kraken: Test config upgrades

* Kraken: Sub Channel improvements

* Use Websocket subscriptionChannels instead of local slice
* Remove ChannelID - Deprecated in docs
* Simplify ping handlers and hardcodes message
* Add Depth as configurable orderbook channel param
* Simplify auth/non-auth channel updates
* Add configurable Book depth
* Add configurable Candle timeframes

Kraken: Simplify all WS handlers with reqId

* Kraken: Subscription templating

* Generate N+ subs for pairs
If we generate one sub for all pairs, but then fan it out in the
responses, we end up with a mis-match between the sub store and
GenerateSubs, and when we do FlushChannels it will try to resub
everything again.

* Kraken: Rename channelName var throughout

Avoid shadowing func of same name

* Kraken: Add TestEnforceStandardChannelNames

* Websocket: Fix Resubscribe erroring Duplicate
This commit is contained in:
Gareth Kirwan
2024-10-08 00:34:10 +01:00
committed by GitHub
parent f110920d73
commit 33e82c170f
21 changed files with 1359 additions and 1776 deletions

View File

@@ -87,3 +87,38 @@ func (k IgnoringPairsKey) Match(eachKey MatchableKey) bool {
eachSub.Levels == k.Levels &&
eachSub.Interval == k.Interval
}
// IgnoringAssetKey is a key type for finding subscriptions to group together for requests
type IgnoringAssetKey struct {
*Subscription
}
var _ MatchableKey = IgnoringAssetKey{} // Enforce IgnoringAssetKey must implement MatchableKey
// GetSubscription returns the underlying subscription
func (k IgnoringAssetKey) GetSubscription() *Subscription {
return k.Subscription
}
// String implements Stringer; returns the asset and Channel name but no pairs
func (k IgnoringAssetKey) String() string {
s := k.Subscription
if s == nil {
return "Uninitialised IgnoringAssetKey"
}
return fmt.Sprintf("%s %s", s.Channel, s.Pairs)
}
// Match implements MatchableKey
func (k IgnoringAssetKey) Match(eachKey MatchableKey) bool {
if eachKey == nil {
return false
}
eachSub := eachKey.GetSubscription()
return eachSub != nil &&
eachSub.Channel == k.Channel &&
eachSub.Pairs.Equal(k.Pairs) &&
eachSub.Levels == k.Levels &&
eachSub.Interval == k.Interval
}

View File

@@ -110,6 +110,39 @@ func TestIgnoringPairsKeyString(t *testing.T) {
assert.Equal(t, "ticker spot", key.String())
}
// TestIgnoringAssetKeyMatch exercises IgnoringAssetKey.Match
func TestIgnoringAssetKeyMatch(t *testing.T) {
t.Parallel()
key := &IgnoringAssetKey{&Subscription{Channel: TickerChannel, Asset: asset.Spot}}
try := &DummyKey{&Subscription{Channel: OrderbookChannel}, t}
require.False(t, key.Match(nil), "Match on a nil must return false")
require.False(t, key.Match(try), "Gate 1: Match must reject a bad Channel")
try.Channel = TickerChannel
require.True(t, key.Match(try), "Gate 1: Match must accept a good Channel")
key.Pairs = currency.Pairs{btcusdtPair}
require.False(t, key.Match(try), "Gate 2: Match must reject bad Pairs")
try.Pairs = currency.Pairs{btcusdtPair}
require.True(t, key.Match(try), "Gate 2: Match must accept a good Pairs")
key.Levels = 4
require.False(t, key.Match(try), "Gate 3: Match must reject a bad Level")
try.Levels = 4
require.True(t, key.Match(try), "Gate 3: Match must accept a good Level")
key.Interval = kline.FiveMin
require.False(t, key.Match(try), "Gate 4: Match must reject a bad Interval")
try.Interval = kline.FiveMin
require.True(t, key.Match(try), "Gate 4: Match must accept a good Interval")
}
// TestIgnoringAssetKeyString exercises IgnoringAssetKey.String
func TestIgnoringAssetKeyString(t *testing.T) {
t.Parallel()
assert.Equal(t, "Uninitialised IgnoringAssetKey", IgnoringAssetKey{}.String())
key := &IgnoringAssetKey{&Subscription{Asset: asset.Spot, Channel: TickerChannel, Pairs: currency.Pairs{ethusdcPair, btcusdtPair}}}
assert.Equal(t, "ticker [ETHUSDC BTCUSDT]", key.String())
}
// TestGetSubscription exercises GetSubscription
func TestGetSubscription(t *testing.T) {
t.Parallel()

View File

@@ -35,11 +35,13 @@ const (
// Public errors
var (
ErrNotFound = errors.New("subscription not found")
ErrNotSinglePair = errors.New("only single pair subscriptions expected")
ErrInStateAlready = errors.New("subscription already in state")
ErrInvalidState = errors.New("invalid subscription state")
ErrDuplicate = errors.New("duplicate subscription")
ErrNotFound = errors.New("subscription not found")
ErrNotSinglePair = errors.New("only single pair subscriptions expected")
ErrBatchingNotSupported = errors.New("subscription batching not supported")
ErrInStateAlready = errors.New("subscription already in state")
ErrInvalidState = errors.New("invalid subscription state")
ErrDuplicate = errors.New("duplicate subscription")
ErrPrivateChannelName = errors.New("must use standard channel name constants")
)
// State tracks the status of a subscription channel