GateIO: Update websocket orderbook manager (#1989)

* gateio: websocket ob manager fix (cherry-pick me)

* fix(gateio): update websocket orderbook manager to support delay and deadline parameters
    feat(subscriptions): mv ChannelKey type for subscription management from gateio to subscriptions
    test(gateio): enhance tests for orderbook update manager and subscription keys

* ai: nits

* linter: fix

* Fix asset typo and add in case test

* cranktakular: nits

* cranktakular: nits after merge master

* bump time delay for cache

* fix bug where on error it never initiates another orderbook fetch

* lint: fix

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious: nits

* linter: fix

* Update exchanges/gateio/gateio_wrapper_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/gateio_wrapper.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/gateio_wrapper_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* gk: nits

* Update exchanges/gateio/gateio_wrapper.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* gk: nits

* bossking: nits

* Update exchanges/gateio/ws_ob_update_manager_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* gk: nits

* apply patch

* rm error state as this was on the same thread as cacheStateQueuing and had the potential to drop messages, add tests.

* linter: fix

* mock live request

* misc: fix

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/gateio/ws_ob_update_manager.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* gk: nits

* field name from mtx -> m

* lint: fix

* race: check fix

* thrasher-: patch adams

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
Ryan O'Hara-Reid
2025-11-27 12:21:17 +11:00
committed by GitHub
parent 719e6bebfe
commit cf54764cb7
11 changed files with 757 additions and 251 deletions

View File

@@ -122,3 +122,29 @@ func (k IgnoringAssetKey) Match(eachKey MatchableKey) bool {
eachSub.Levels == k.Levels &&
eachSub.Interval == k.Interval
}
// ChannelKey is a key type for finding a single subscription by its channel, this will match first found.
// For use with exchange websocket method GetSubscription.
type ChannelKey struct {
*Subscription
}
var _ MatchableKey = ChannelKey{} // Enforce ChannelKey must implement MatchableKey
// MustChannelKey is a helper function to create a ChannelKey from a subscription channel
func MustChannelKey(channel string) ChannelKey {
if channel == "" {
panic("channel must not be empty")
}
return ChannelKey{Subscription: &Subscription{Channel: channel}}
}
// Match implements MatchableKey
func (k ChannelKey) Match(eachKey MatchableKey) bool {
return k.Subscription.Channel == eachKey.GetSubscription().Channel
}
// GetSubscription returns the underlying subscription
func (k ChannelKey) GetSubscription() *Subscription {
return k.Subscription
}

View File

@@ -150,3 +150,27 @@ func TestGetSubscription(t *testing.T) {
assert.Same(t, s, ExactKey{s}.GetSubscription(), "ExactKey.GetSubscription Must return a pointer to the subscription")
assert.Same(t, s, IgnoringPairsKey{s}.GetSubscription(), "IgnorePairKeys.GetSubscription Must return a pointer to the subscription")
}
func TestMustChannelKey(t *testing.T) {
t.Parallel()
require.Panics(t, func() { MustChannelKey("") }, "no channel string must panic")
key := MustChannelKey(TickerChannel)
assert.Equal(t, TickerChannel, key.Subscription.Channel)
}
func TestChannelKeyMatch(t *testing.T) {
t.Parallel()
key := ChannelKey{&Subscription{Channel: TickerChannel}}
try := &DummyKey{&Subscription{Channel: OrderbookChannel}, t}
require.Panics(t, func() { key.Match(nil) }, "Match on a nil must panic")
require.False(t, key.Match(try), "Match must reject a different channel")
try.Channel = TickerChannel
assert.True(t, key.Match(try), "Match should accept an identical channel")
}
func TestChannelKeyGetSubscription(t *testing.T) {
t.Parallel()
key := ChannelKey{&Subscription{Channel: TickerChannel}}
assert.Same(t, key.Subscription, key.GetSubscription(), "GetSubscription should return the underlying subscription")
}