mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 23:16:52 +00:00
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:
@@ -483,7 +483,7 @@ func ExchangeOrderSubmit(args ...objects.Object) (objects.Object, error) {
|
||||
|
||||
// ExchangeDepositAddress returns deposit address (if supported by exchange)
|
||||
func ExchangeDepositAddress(args ...objects.Object) (objects.Object, error) {
|
||||
if len(args) != 2 {
|
||||
if len(args) != 3 {
|
||||
return nil, objects.ErrWrongNumArguments
|
||||
}
|
||||
|
||||
@@ -495,15 +495,24 @@ func ExchangeDepositAddress(args ...objects.Object) (objects.Object, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, currencyCode)
|
||||
}
|
||||
chain, ok := objects.ToString(args[2])
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(ErrParameterConvertFailed, chain)
|
||||
}
|
||||
|
||||
currCode := currency.NewCode(currencyCode)
|
||||
|
||||
rtn, err := wrappers.GetWrapper().DepositAddress(exchangeName, currCode)
|
||||
rtn, err := wrappers.GetWrapper().DepositAddress(exchangeName, chain, currCode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &objects.String{Value: rtn}, nil
|
||||
data := make(map[string]objects.Object, 2)
|
||||
data["address"] = &objects.String{Value: rtn.Address}
|
||||
data["tag"] = &objects.String{Value: rtn.Tag}
|
||||
return &objects.Map{
|
||||
Value: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ExchangeWithdrawCrypto submit request to withdraw crypto assets
|
||||
|
||||
@@ -245,12 +245,13 @@ func TestExchangeDepositAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
currCode := &objects.String{Value: "BTC"}
|
||||
_, err = ExchangeDepositAddress(exch, currCode)
|
||||
chain := &objects.String{Value: ""}
|
||||
_, err = ExchangeDepositAddress(exch, currCode, chain)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = ExchangeDepositAddress(exchError, currCode)
|
||||
_, err = ExchangeDepositAddress(exchError, currCode, chain)
|
||||
if err != nil && !errors.Is(err, errTestFailed) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"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"
|
||||
@@ -40,7 +41,7 @@ type Exchange interface {
|
||||
SubmitOrder(ctx context.Context, submit *order.Submit) (*order.SubmitResponse, error)
|
||||
CancelOrder(ctx context.Context, exch, orderid string, pair currency.Pair, item asset.Item) (bool, error)
|
||||
AccountInformation(ctx context.Context, exch string, assetType asset.Item) (account.Holdings, error)
|
||||
DepositAddress(exch string, currencyCode currency.Code) (string, error)
|
||||
DepositAddress(exch, chain string, currencyCode currency.Code) (*deposit.Address, error)
|
||||
WithdrawalFiatFunds(ctx context.Context, bankAccountID string, request *withdraw.Request) (out string, err error)
|
||||
WithdrawalCryptoFunds(ctx context.Context, request *withdraw.Request) (out string, err error)
|
||||
OHLCV(ctx context.Context, exch string, pair currency.Pair, item asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)
|
||||
|
||||
@@ -12,6 +12,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"
|
||||
@@ -135,11 +136,12 @@ func (e Exchange) AccountInformation(ctx context.Context, exch string, assetType
|
||||
}
|
||||
|
||||
// DepositAddress gets the address required to deposit funds for currency type
|
||||
func (e Exchange) DepositAddress(exch string, currencyCode currency.Code) (out string, err error) {
|
||||
func (e Exchange) DepositAddress(exch, chain string, currencyCode currency.Code) (depositAddr *deposit.Address, err error) {
|
||||
if currencyCode.IsEmpty() {
|
||||
return "", errors.New("currency code is empty")
|
||||
return nil, errors.New("currency code is empty")
|
||||
}
|
||||
return engine.Bot.DepositAddressManager.GetDepositAddressByExchangeAndCurrency(exch, currencyCode)
|
||||
resp, err := engine.Bot.DepositAddressManager.GetDepositAddressByExchangeAndCurrency(exch, chain, currencyCode)
|
||||
return &deposit.Address{Address: resp.Address, Tag: resp.Tag}, err
|
||||
}
|
||||
|
||||
// WithdrawalFiatFunds withdraw funds from exchange to requested fiat source
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
engine.Bot.DepositAddressManager = engine.SetupDepositAddressManager()
|
||||
err = engine.Bot.DepositAddressManager.Sync(engine.Bot.GetExchangeCryptocurrencyDepositAddresses())
|
||||
err = engine.Bot.DepositAddressManager.Sync(engine.Bot.GetAllExchangeCryptocurrencyDepositAddresses())
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
os.Exit(1)
|
||||
@@ -261,7 +261,8 @@ func TestExchangeDepositAddress(t *testing.T) {
|
||||
}
|
||||
|
||||
currCode := &objects.String{Value: "BTC"}
|
||||
_, err = gct.ExchangeDepositAddress(exch, currCode)
|
||||
chain := &objects.String{Value: ""}
|
||||
_, err = gct.ExchangeDepositAddress(exch, currCode, chain)
|
||||
if err != nil && err.Error() != "deposit address store is nil" {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import (
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"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"
|
||||
@@ -216,12 +218,12 @@ func (w Wrapper) AccountInformation(ctx context.Context, exch string, assetType
|
||||
}
|
||||
|
||||
// DepositAddress validator for test execution/scripts
|
||||
func (w Wrapper) DepositAddress(exch string, _ currency.Code) (string, error) {
|
||||
func (w Wrapper) DepositAddress(exch, chain string, _ currency.Code) (*deposit.Address, error) {
|
||||
if exch == exchError.String() {
|
||||
return exch, errTestFailed
|
||||
return nil, errTestFailed
|
||||
}
|
||||
|
||||
return exch, nil
|
||||
return &deposit.Address{Address: core.BitcoinDonationAddress}, nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptoFunds validator for test execution/scripts
|
||||
|
||||
@@ -112,12 +112,12 @@ func TestWrapper_CancelOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWrapper_DepositAddress(t *testing.T) {
|
||||
_, err := testWrapper.DepositAddress(exchError.String(), currency.NewCode("BTC"))
|
||||
_, err := testWrapper.DepositAddress(exchError.String(), "", currency.NewCode("BTC"))
|
||||
if err == nil {
|
||||
t.Fatal("expected DepositAddress to return error on invalid name")
|
||||
}
|
||||
|
||||
_, err = testWrapper.DepositAddress(exchName, currency.NewCode("BTC"))
|
||||
_, err = testWrapper.DepositAddress(exchName, "", currency.NewCode("BTC"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user