Skip to content

Commit

Permalink
Huobi: Fix invalid contract type error when autoUpdatePairs is false (#…
Browse files Browse the repository at this point in the history
…1707)

We were relying on autoUpdatePairs to fetch contract types before we
need them. If the user disables it in config, we'll get them upfront.
  • Loading branch information
gbjk authored Nov 11, 2024
1 parent 4de4e3d commit 56fa304
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions exchanges/huobi/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2991,3 +2991,19 @@ func TestChannelName(t *testing.T) {
assert.Panics(t, func() { channelName(&subscription.Subscription{Channel: wsOrderbookChannel}, p) })
assert.Panics(t, func() { channelName(&subscription.Subscription{Channel: subscription.MyAccountChannel}, p) }, "Should panic on V2 endpoints until implemented")
}

func TestBootstrap(t *testing.T) {
t.Parallel()
h := new(HUOBI)
require.NoError(t, testexch.Setup(h), "Test Instance Setup must not fail")

c, err := h.Bootstrap(context.Background())
require.NoError(t, err)
assert.True(t, c, "Bootstrap should return true to continue")

h.futureContractCodes = nil
h.Features.Enabled.AutoPairUpdates = false
_, err = h.Bootstrap(context.Background())
require.NoError(t, err)
require.NotNil(t, h.futureContractCodes)
}
11 changes: 11 additions & 0 deletions exchanges/huobi/huobi_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ func (h *HUOBI) SetDefaults() {
h.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
}

// Bootstrap ensures that future contract expiry codes are loaded if AutoPairUpdates is not enabled
func (h *HUOBI) Bootstrap(_ context.Context) (continueBootstrap bool, err error) {
continueBootstrap = true

if !h.GetEnabledFeatures().AutoPairUpdates && h.SupportsAsset(asset.Futures) {
_, err = h.FetchTradablePairs(context.Background(), asset.Futures)
}

return
}

// Setup sets user configuration
func (h *HUOBI) Setup(exch *config.Exchange) error {
err := exch.Validate()
Expand Down

0 comments on commit 56fa304

Please sign in to comment.