From c36bb36047db75a9fcab3a99031502380eee4d45 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 11 Nov 2024 08:38:11 +0700 Subject: [PATCH] Huobi: Fix invalid contract type err when autoUpdatePairs is false 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. --- exchanges/huobi/huobi_test.go | 16 ++++++++++++++++ exchanges/huobi/huobi_wrapper.go | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index bb0c17da0c0..a3a9edfacf9 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -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) +} diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 9a62d91a0e2..1e16dea2a03 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -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()