exchanges/engine: Add multichain deposit/withdrawal support (#794)

* Add exchange multichain support

* Start tidying up

* Add multichain transfer support for Bitfinex and fix poloniex bug

* Add Coinbene multichain support

* Start adjusting the deposit address manager

* Fix deposit tests and further enhancements

* Cleanup

* Add bypass flag, expand tests plus error coverage for Huobi

Adjust helpers

* Address nitterinos

* BFX wd changes

* Address nitterinos

* Minor fixes rebasing on master

* Fix BFX acceptableMethods test

* Add some TO-DOs for 2 tests WRT races

* Fix acceptableMethods test round 2

* Address nitterinos
This commit is contained in:
Adrian Gallagher
2021-10-15 15:55:38 +11:00
committed by GitHub
parent b093a7df19
commit 0c00b7e1df
145 changed files with 46329 additions and 5507 deletions

View File

@@ -271,10 +271,10 @@ func (b *Bithumb) GetAccountBalance(ctx context.Context, c string) (FullBalance,
// GetWalletAddress returns customer wallet address
//
// currency e.g. btc, ltc or "", will default to btc without currency specified
func (b *Bithumb) GetWalletAddress(ctx context.Context, currency string) (WalletAddressRes, error) {
func (b *Bithumb) GetWalletAddress(ctx context.Context, curr currency.Code) (WalletAddressRes, error) {
response := WalletAddressRes{}
params := url.Values{}
params.Set("currency", strings.ToUpper(currency))
params.Set("currency", curr.Upper().String())
err := b.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, privateWalletAdd, params, &response)
if err != nil {
@@ -284,7 +284,30 @@ func (b *Bithumb) GetWalletAddress(ctx context.Context, currency string) (Wallet
if response.Data.WalletAddress == "" {
return response,
fmt.Errorf("deposit address needs to be created via the Bithumb website before retrieval for currency %s",
currency)
curr.String())
}
var address, tag string
switch curr {
case currency.XRP:
splitStr := "&dt="
if !strings.Contains(response.Data.WalletAddress, splitStr) {
return response, errors.New("unable to parse XRP deposit address")
}
splitter := strings.Split(response.Data.WalletAddress, splitStr)
address, tag = splitter[0], splitter[1]
case currency.XLM, currency.BNB:
splitStr := "&memo="
if !strings.Contains(response.Data.WalletAddress, splitStr) {
return response, fmt.Errorf("unable to parse %s deposit address", curr.String())
}
splitter := strings.Split(response.Data.WalletAddress, splitStr)
address, tag = splitter[0], splitter[1]
}
if tag != "" {
response.Data.WalletAddress = address
response.Data.Tag = tag
}
return response, nil

View File

@@ -132,7 +132,7 @@ func TestGetWalletAddress(t *testing.T) {
t.Skip()
}
_, err := b.GetWalletAddress(context.Background(), "")
_, err := b.GetWalletAddress(context.Background(), currency.BTC)
if err == nil {
t.Error("Bithumb GetWalletAddress() Expected error")
}
@@ -514,6 +514,7 @@ func TestWithdraw(t *testing.T) {
}
withdrawCryptoRequest := withdraw.Request{
Exchange: b.Name,
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
@@ -575,12 +576,12 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
t.Parallel()
if areTestAPIKeysSet() {
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "")
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "", "")
if err != nil {
t.Error("GetDepositAddress() error", err)
}
} else {
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "")
_, err := b.GetDepositAddress(context.Background(), currency.BTC, "", "")
if err == nil {
t.Error("GetDepositAddress() error cannot be nil")
}

View File

@@ -93,6 +93,7 @@ type WalletAddressRes struct {
Status string `json:"status"`
Data struct {
WalletAddress string `json:"wallet_address"`
Tag string // custom field we populate
Currency string `json:"currency"`
} `json:"data"`
Message string `json:"message"`

View File

@@ -18,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/currencystate"
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
@@ -594,13 +595,16 @@ func (b *Bithumb) GetOrderInfo(ctx context.Context, orderID string, pair currenc
}
// GetDepositAddress returns a deposit address for a specified currency
func (b *Bithumb) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
addr, err := b.GetWalletAddress(ctx, cryptocurrency.String())
func (b *Bithumb) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _, _ string) (*deposit.Address, error) {
addr, err := b.GetWalletAddress(ctx, cryptocurrency)
if err != nil {
return "", err
return nil, err
}
return addr.Data.WalletAddress, nil
return &deposit.Address{
Address: addr.Data.WalletAddress,
Tag: addr.Data.Tag,
}, nil
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is