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

@@ -16,6 +16,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"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"
@@ -85,6 +86,7 @@ func (z *ZB) SetDefaults() {
TradeFee: true,
CryptoDepositFee: true,
CryptoWithdrawalFee: true,
MultiChainDeposits: true,
},
WebsocketCapabilities: protocol.Features{
TickerFetching: true,
@@ -622,13 +624,31 @@ func (z *ZB) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pai
}
// GetDepositAddress returns a deposit address for a specified currency
func (z *ZB) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _ string) (string, error) {
func (z *ZB) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, _, chain string) (*deposit.Address, error) {
if chain != "" {
addresses, err := z.GetMultiChainDepositAddress(ctx, cryptocurrency)
if err != nil {
return nil, err
}
for x := range addresses {
if strings.EqualFold(addresses[x].Blockchain, chain) {
return &deposit.Address{
Address: addresses[x].Address,
Tag: addresses[x].Memo,
}, nil
}
}
return nil, fmt.Errorf("%s does not support chain %s", cryptocurrency.String(), chain)
}
address, err := z.GetCryptoAddress(ctx, cryptocurrency)
if err != nil {
return "", err
return nil, err
}
return address.Message.Data.Key, nil
return &deposit.Address{
Address: address.Message.Data.Address,
Tag: address.Message.Data.Tag,
}, nil
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
@@ -959,3 +979,25 @@ func (z *ZB) validateCandlesRequest(p currency.Pair, a asset.Item, start, end ti
Interval: interval,
}, nil
}
// GetAvailableTransferChains returns the available transfer blockchains for the specific
// cryptocurrency
func (z *ZB) GetAvailableTransferChains(ctx context.Context, cryptocurrency currency.Code) ([]string, error) {
chains, err := z.GetMultiChainDepositAddress(ctx, cryptocurrency)
if err != nil {
// returned on valid currencies like BTC, despite having a deposit
// address created it will advise the user to create one via their
// app or website. In this case, we'll just return nil transfer
// chains and no error message
if strings.Contains(err.Error(), "APP") {
return nil, nil
}
return nil, err
}
var availableChains []string
for x := range chains {
availableChains = append(availableChains, chains[x].Blockchain)
}
return availableChains, nil
}