Skip to content

Commit

Permalink
Huobi: Fix GetAvailableTransferChains returning unavailable chains (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk authored Nov 11, 2024
1 parent 56fa304 commit fb0fd2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
10 changes: 3 additions & 7 deletions exchanges/huobi/huobi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion exchanges/huobi/huobi_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
19 changes: 11 additions & 8 deletions exchanges/huobi/huobi_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fb0fd2e

Please sign in to comment.