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

@@ -514,13 +514,13 @@ func (b *BTCMarkets) GetTransfer(ctx context.Context, id string) (TransferData,
}
// FetchDepositAddress gets deposit address for the given asset
func (b *BTCMarkets) FetchDepositAddress(ctx context.Context, assetName string, before, after, limit int64) (DepositAddress, error) {
func (b *BTCMarkets) FetchDepositAddress(ctx context.Context, curr currency.Code, before, after, limit int64) (*DepositAddress, error) {
var resp DepositAddress
if (before > 0) && (after >= 0) {
return resp, errors.New("BTCMarkets only supports either before or after, not both")
return nil, errors.New("BTCMarkets only supports either before or after, not both")
}
params := url.Values{}
params.Set("assetName", assetName)
params.Set("assetName", curr.Upper().String())
if before > 0 {
params.Set("before", strconv.FormatInt(before, 10))
}
@@ -530,11 +530,24 @@ func (b *BTCMarkets) FetchDepositAddress(ctx context.Context, assetName string,
if limit > 0 {
params.Set("limit", strconv.FormatInt(limit, 10))
}
return resp, b.SendAuthenticatedRequest(ctx, http.MethodGet,
if err := b.SendAuthenticatedRequest(ctx,
http.MethodGet,
common.EncodeURLValues(btcMarketsAddresses, params),
nil,
&resp,
request.Auth)
request.Auth); err != nil {
return nil, err
}
if curr == currency.XRP {
splitStr := "?dt="
if !strings.Contains(resp.Address, splitStr) {
return nil, errors.New("unable to find split string for XRP")
}
splitter := strings.Split(resp.Address, splitStr)
resp.Address = splitter[0]
resp.Tag = splitter[1]
}
return &resp, nil
}
// GetWithdrawalFees gets withdrawal fees for all assets
@@ -703,9 +716,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(ctx context.Context, method, path
}
newRequest := func() (*request.Item, error) {
now := time.Now()
strTime := strconv.FormatInt(now.UTC().UnixMilli(), 10)
strTime := strconv.FormatInt(time.Now().UnixMilli(), 10)
var body io.Reader
var payload, hmac []byte
switch data.(type) {

View File

@@ -340,11 +340,11 @@ func TestFetchDepositAddress(t *testing.T) {
if !areTestAPIKeysSet() {
t.Skip("API keys required but not set, skipping test")
}
_, err := b.FetchDepositAddress(context.Background(), "LTC", -1, -1, -1)
_, err := b.FetchDepositAddress(context.Background(), currency.XRP, -1, -1, -1)
if err != nil {
t.Error(err)
}
_, err = b.FetchDepositAddress(context.Background(), fakePair, -1, -1, -1)
_, err = b.FetchDepositAddress(context.Background(), currency.NewCode("MOOCOW"), -1, -1, -1)
if err != nil {
t.Error("expected an error due to invalid assetID")
}

View File

@@ -184,6 +184,7 @@ type TransferData struct {
type DepositAddress struct {
Address string `json:"address"`
AssetName string `json:"assetName"`
Tag string // custom field we populate
}
// WithdrawalFeeData stores data for fees

View File

@@ -343,7 +343,7 @@ func (b *BTCMarkets) Subscribe(channelsToSubscribe []stream.ChannelSubscription)
if !common.StringDataCompare(payload.Channels, authChannels[i]) {
continue
}
signTime := strconv.FormatInt(time.Now().UTC().UnixMilli(), 10)
signTime := strconv.FormatInt(time.Now().UnixMilli(), 10)
strToSign := "/users/self/subscribe" + "\n" + signTime
tempSign, err := crypto.GetHMAC(crypto.HashSHA512,
[]byte(strToSign),

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"
@@ -648,12 +649,15 @@ func (b *BTCMarkets) GetOrderInfo(ctx context.Context, orderID string, pair curr
}
// GetDepositAddress returns a deposit address for a specified currency
func (b *BTCMarkets) GetDepositAddress(ctx context.Context, c currency.Code, accountID string) (string, error) {
temp, err := b.FetchDepositAddress(ctx, strings.ToUpper(c.String()), -1, -1, -1)
func (b *BTCMarkets) GetDepositAddress(ctx context.Context, cryptocurrency currency.Code, accountID, _ string) (*deposit.Address, error) {
depositAddr, err := b.FetchDepositAddress(ctx, cryptocurrency, -1, -1, -1)
if err != nil {
return "", err
return nil, err
}
return temp.Address, nil
return &deposit.Address{
Address: depositAddr.Address,
Tag: depositAddr.Tag,
}, nil
}
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted