From fb0fd2e51498a8dc446bb5bb07cef70562cf2276 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 11 Nov 2024 06:18:27 +0100 Subject: [PATCH] Huobi: Fix GetAvailableTransferChains returning unavailable chains (#1709) --- exchanges/huobi/huobi_test.go | 10 +++------- exchanges/huobi/huobi_types.go | 2 +- exchanges/huobi/huobi_wrapper.go | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/exchanges/huobi/huobi_test.go b/exchanges/huobi/huobi_test.go index a3a9edfacf9..15dec4ba245 100644 --- a/exchanges/huobi/huobi_test.go +++ b/exchanges/huobi/huobi_test.go @@ -2625,13 +2625,9 @@ func TestGetHistoricTrades(t *testing.T) { func TestGetAvailableTransferChains(t *testing.T) { t.Parallel() - r, err := h.GetAvailableTransferChains(context.Background(), currency.USDT) - if err != nil { - t.Error(err) - } - if len(r) < 2 { - t.Error("expected more than one result") - } + c, err := h.GetAvailableTransferChains(context.Background(), currency.USDT) + require.NoError(t, err) + require.Greater(t, len(c), 2, "Must get more than 2 chains") } func TestFormatFuturesPair(t *testing.T) { diff --git a/exchanges/huobi/huobi_types.go b/exchanges/huobi/huobi_types.go index dd37bd396c6..948e23d3e24 100644 --- a/exchanges/huobi/huobi_types.go +++ b/exchanges/huobi/huobi_types.go @@ -35,7 +35,7 @@ type CurrenciesChainData struct { Currency string `json:"currency"` AssetType uint8 `json:"assetType"` InstStatus string `json:"instStatus"` - ChainData []struct { + ChainData []*struct { Chain string `json:"chain"` DisplayName string `json:"displayName"` BaseChain string `json:"baseChain"` diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 1e16dea2a03..76c461cb196 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -2116,21 +2116,24 @@ func compatibleVars(side, orderPriceType string, status int64) (OrderVars, error return resp, nil } -// GetAvailableTransferChains returns the available transfer blockchains for the specific -// cryptocurrency +// GetAvailableTransferChains returns the available transfer blockchains for the specific cryptocurrency func (h *HUOBI) GetAvailableTransferChains(ctx context.Context, cryptocurrency currency.Code) ([]string, error) { - chains, err := h.GetCurrenciesIncludingChains(ctx, cryptocurrency) + resp, err := h.GetCurrenciesIncludingChains(ctx, cryptocurrency) if err != nil { return nil, err } - if len(chains) == 0 { - return nil, errors.New("chain data isn't populated") + if len(resp) == 0 { + return nil, errors.New("no chains returned from currencies API") } - availableChains := make([]string, len(chains[0].ChainData)) - for x := range chains[0].ChainData { - availableChains[x] = chains[0].ChainData[x].Chain + chains := resp[0].ChainData + + availableChains := make([]string, 0, len(chains)) + for _, c := range chains { + if c.DepositStatus == "allowed" || c.WithdrawStatus == "allowed" { + availableChains = append(availableChains, c.Chain) + } } return availableChains, nil }