Skip to content

Commit

Permalink
exchanges/engine: Add multichain deposit/withdrawal support (thrasher…
Browse files Browse the repository at this point in the history
…-corp#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
  • Loading branch information
thrasher- authored Oct 15, 2021
1 parent b093a7d commit 0c00b7e
Show file tree
Hide file tree
Showing 145 changed files with 64,578 additions and 23,756 deletions.
5 changes: 3 additions & 2 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ ermalguni | https://github.com/ermalguni
MadCozBadd | https://github.com/MadCozBadd
ydm | https://github.com/ydm
vadimzhukck | https://github.com/vadimzhukck
lrascao | https://github.com/lrascao
140am | https://github.com/140am
marcofranssen | https://github.com/marcofranssen
lrascao | https://github.com/lrascao
dackroyd | https://github.com/dackroyd
cranktakular | https://github.com/cranktakular
woshidama323 | https://github.com/woshidama323
Expand All @@ -29,7 +29,7 @@ MarkDzulko | https://github.com/MarkDzulko
gam-phon | https://github.com/gam-phon
cornelk | https://github.com/cornelk
if1live | https://github.com/if1live
lozdog245 | https://github.com/lozdog245
khcchiu | https://github.com/khcchiu
herenow | https://github.com/herenow
mshogin | https://github.com/mshogin
soxipy | https://github.com/soxipy
Expand All @@ -52,3 +52,4 @@ Daanikus | https://github.com/Daanikus
CodeLingoBot | https://github.com/CodeLingoBot
blombard | https://github.com/blombard
soxipy | https://github.com/soxipy
lozdog245 | https://github.com/lozdog245
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ However, we welcome pull requests for any exchange which does not match this cri
+ Recent and historic trade processing. See [trades](/exchanges/trade/README.md).
+ Backtesting application. An event-driven backtesting tool to test and iterate trading strategies using historical or custom data. See [backtester](/backtester/README.md).
+ WebGUI (discontinued).
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).

## Planned Features

Expand Down Expand Up @@ -144,19 +146,19 @@ Binaries will be published once the codebase reaches a stable condition.
|--|--|
| [thrasher-](https://github.com/thrasher-) | 658 |
| [shazbert](https://github.com/shazbert) | 223 |
| [gloriousCode](https://github.com/gloriousCode) | 190 |
| [gloriousCode](https://github.com/gloriousCode) | 191 |
| [dependabot-preview[bot]](https://github.com/apps/dependabot-preview) | 88 |
| [xtda](https://github.com/xtda) | 47 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 23 |
| [dependabot[bot]](https://github.com/apps/dependabot) | 24 |
| [Rots](https://github.com/Rots) | 15 |
| [vazha](https://github.com/vazha) | 15 |
| [ermalguni](https://github.com/ermalguni) | 14 |
| [MadCozBadd](https://github.com/MadCozBadd) | 13 |
| [ydm](https://github.com/ydm) | 11 |
| [vadimzhukck](https://github.com/vadimzhukck) | 10 |
| [lrascao](https://github.com/lrascao) | 8 |
| [140am](https://github.com/140am) | 8 |
| [marcofranssen](https://github.com/marcofranssen) | 8 |
| [lrascao](https://github.com/lrascao) | 7 |
| [dackroyd](https://github.com/dackroyd) | 5 |
| [cranktakular](https://github.com/cranktakular) | 5 |
| [woshidama323](https://github.com/woshidama323) | 3 |
Expand All @@ -171,7 +173,7 @@ Binaries will be published once the codebase reaches a stable condition.
| [gam-phon](https://github.com/gam-phon) | 2 |
| [cornelk](https://github.com/cornelk) | 2 |
| [if1live](https://github.com/if1live) | 2 |
| [lozdog245](https://github.com/lozdog245) | 2 |
| [khcchiu](https://github.com/khcchiu) | 2 |
| [herenow](https://github.com/herenow) | 2 |
| [mshogin](https://github.com/mshogin) | 2 |
| [soxipy](https://github.com/soxipy) | 2 |
Expand All @@ -194,3 +196,4 @@ Binaries will be published once the codebase reaches a stable condition.
| [CodeLingoBot](https://github.com/CodeLingoBot) | 1 |
| [blombard](https://github.com/blombard) | 1 |
| [soxipy](https://github.com/soxipy) | 2 |
| [lozdog245](https://github.com/lozdog245) | 2 |
5 changes: 5 additions & 0 deletions cmd/documentation/documentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func main() {
URL: "https://github.com/soxipy",
Contributions: 2,
},
{
Login: "lozdog245",
URL: "https://github.com/lozdog245",
Contributions: 2,
},
}...)

if verbose {
Expand Down
2 changes: 2 additions & 0 deletions cmd/documentation/root_templates/root_readme.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ However, we welcome pull requests for any exchange which does not match this cri
+ Recent and historic trade processing. See [trades](/exchanges/trade/README.md).
+ Backtesting application. An event-driven backtesting tool to test and iterate trading strategies using historical or custom data. See [backtester](/backtester/README.md).
+ WebGUI (discontinued).
+ Exchange HTTP mock testing. See [mock](/exchanges/mock/README.md).
+ Exchange multichain deposits and withdrawals for specific exchanges. See [multichain transfer support](/docs/MULTICHAIN_TRANSFER_SUPPORT.md).

## Planned Features

Expand Down
2 changes: 1 addition & 1 deletion cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "GetActiveOrders")
}

_, err = e.GetDepositAddress(context.TODO(), currency.BTC, "")
_, err = e.GetDepositAddress(context.TODO(), currency.BTC, "", "")
if errors.Is(err, common.ErrNotYetImplemented) {
funcs = append(funcs, "GetDepositAddress")
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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"
Expand Down Expand Up @@ -694,8 +695,8 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{getActiveOrdersResponse}),
})

var getDepositAddressResponse string
getDepositAddressResponse, err = e.GetDepositAddress(context.TODO(), p.Base, "")
var getDepositAddressResponse *deposit.Address
getDepositAddressResponse, err = e.GetDepositAddress(context.TODO(), p.Base, "", "")
msg = ""
if err != nil {
msg = err.Error()
Expand Down
109 changes: 105 additions & 4 deletions cmd/gctcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ func getCryptocurrencyDepositAddresses(c *cli.Context) error {
var getCryptocurrencyDepositAddressCommand = &cli.Command{
Name: "getcryptocurrencydepositaddress",
Usage: "gets the cryptocurrency deposit address for an exchange and cryptocurrency",
ArgsUsage: "<exchange> <cryptocurrency>",
ArgsUsage: "<exchange> <cryptocurrency> <chain> <bypass>",
Action: getCryptocurrencyDepositAddress,
Flags: []cli.Flag{
&cli.StringFlag{
Expand All @@ -2603,12 +2603,20 @@ var getCryptocurrencyDepositAddressCommand = &cli.Command{
Name: "cryptocurrency",
Usage: "the cryptocurrency to get the deposit address for",
},
&cli.StringFlag{
Name: "chain",
Usage: "the chain to use for the deposit",
},
&cli.BoolFlag{
Name: "bypass",
Usage: "whether to bypass the deposit address manager cache if enabled",
},
},
}

func getCryptocurrencyDepositAddress(c *cli.Context) error {
if c.NArg() == 0 && c.NumFlags() == 0 {
return cli.ShowCommandHelp(c, "getcryptocurrencydepositaddresses")
return cli.ShowCommandHelp(c, "getcryptocurrencydepositaddress")
}

var exchangeName string
Expand All @@ -2630,6 +2638,24 @@ func getCryptocurrencyDepositAddress(c *cli.Context) error {
return errors.New("cryptocurrency must be set")
}

var chain string
if c.IsSet("chain") {
chain = c.String("chain")
} else if c.Args().Get(2) != "" {
chain = c.Args().Get(2)
}

var bypass bool
if c.IsSet("bypass") {
bypass = c.Bool("bypass")
} else if c.Args().Get(3) != "" {
b, err := strconv.ParseBool(c.Args().Get(3))
if err != nil {
return err
}
bypass = b
}

conn, cancel, err := setupClient(c)
if err != nil {
return err
Expand All @@ -2641,6 +2667,70 @@ func getCryptocurrencyDepositAddress(c *cli.Context) error {
&gctrpc.GetCryptocurrencyDepositAddressRequest{
Exchange: exchangeName,
Cryptocurrency: cryptocurrency,
Chain: chain,
Bypass: bypass,
},
)
if err != nil {
return err
}

jsonOutput(result)
return nil
}

var getAvailableTransferChainsCommand = &cli.Command{
Name: "getavailabletransferchains",
Usage: "gets the available transfer chains (deposits and withdrawals) for the desired exchange and cryptocurrency",
ArgsUsage: "<exchange> <cryptocurrency>",
Action: getAvailableTransferChains,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "exchange",
Usage: "the exchange to get the available transfer chains",
},
&cli.StringFlag{
Name: "cryptocurrency",
Usage: "the cryptocurrency to get the available transfer chains for",
},
},
}

func getAvailableTransferChains(c *cli.Context) error {
if c.NArg() == 0 && c.NumFlags() == 0 {
return cli.ShowCommandHelp(c, "getavailabletransferchains")
}

var exchangeName string
var cryptocurrency string

if c.IsSet("exchange") {
exchangeName = c.String("exchange")
} else {
exchangeName = c.Args().First()
}

if c.IsSet("cryptocurrency") {
cryptocurrency = c.String("cryptocurrency")
} else if c.Args().Get(1) != "" {
cryptocurrency = c.Args().Get(1)
}

if cryptocurrency == "" {
return errors.New("cryptocurrency must be set")
}

conn, cancel, err := setupClient(c)
if err != nil {
return err
}
defer closeConn(conn, cancel)

client := gctrpc.NewGoCryptoTraderClient(conn)
result, err := client.GetAvailableTransferChains(c.Context,
&gctrpc.GetAvailableTransferChainsRequest{
Exchange: exchangeName,
Cryptocurrency: cryptocurrency,
},
)
if err != nil {
Expand All @@ -2654,7 +2744,7 @@ func getCryptocurrencyDepositAddress(c *cli.Context) error {
var withdrawCryptocurrencyFundsCommand = &cli.Command{
Name: "withdrawcryptofunds",
Usage: "withdraws cryptocurrency funds from the desired exchange",
ArgsUsage: "<exchange> <currency> <amount> <address> <addresstag> <fee> <description>",
ArgsUsage: "<exchange> <currency> <amount> <address> <addresstag> <fee> <description> <chain>",
Action: withdrawCryptocurrencyFunds,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down Expand Up @@ -2685,6 +2775,10 @@ var withdrawCryptocurrencyFundsCommand = &cli.Command{
Name: "description",
Usage: "description to submit with request",
},
&cli.StringFlag{
Name: "chain",
Usage: "chain to use for the withdrawal",
},
},
}

Expand All @@ -2693,7 +2787,7 @@ func withdrawCryptocurrencyFunds(c *cli.Context) error {
return cli.ShowCommandHelp(c, "withdrawcryptofunds")
}

var exchange, cur, address, addressTag, description string
var exchange, cur, address, addressTag, chain, description string
var amount, fee float64

if c.IsSet("exchange") {
Expand Down Expand Up @@ -2744,6 +2838,12 @@ func withdrawCryptocurrencyFunds(c *cli.Context) error {
description = c.Args().Get(6)
}

if c.IsSet("chain") {
chain = c.String("chain")
} else if c.Args().Get(7) != "" {
chain = c.Args().Get(7)
}

conn, cancel, err := setupClient(c)
if err != nil {
return err
Expand All @@ -2761,6 +2861,7 @@ func withdrawCryptocurrencyFunds(c *cli.Context) error {
Amount: amount,
Fee: fee,
Description: description,
Chain: chain,
},
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/gctcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func main() {
removeEventCommand,
getCryptocurrencyDepositAddressesCommand,
getCryptocurrencyDepositAddressCommand,
getAvailableTransferChainsCommand,
withdrawCryptocurrencyFundsCommand,
withdrawFiatFundsCommand,
withdrawalRequestCommand,
Expand Down
14 changes: 8 additions & 6 deletions config/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,14 @@ type APIEndpointsConfig struct {

// APICredentialsConfig stores the API credentials
type APICredentialsConfig struct {
Key string `json:"key,omitempty"`
Secret string `json:"secret,omitempty"`
ClientID string `json:"clientID,omitempty"`
Subaccount string `json:"subaccount,omitempty"`
PEMKey string `json:"pemKey,omitempty"`
OTPSecret string `json:"otpSecret,omitempty"`
Key string `json:"key,omitempty"`
Secret string `json:"secret,omitempty"`
ClientID string `json:"clientID,omitempty"`
Subaccount string `json:"subaccount,omitempty"`
PEMKey string `json:"pemKey,omitempty"`
OTPSecret string `json:"otpSecret,omitempty"`
TradePassword string `json:"tradePassword,omitempty"`
PIN string `json:"pin,omitempty"`
}

// APICredentialsValidatorConfig stores the API credentials validator settings
Expand Down
1 change: 1 addition & 0 deletions currency/code_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1665,4 +1665,5 @@ var (
BUSD = NewCode("BUSD")
SRM = NewCode("SRM")
FTT = NewCode("FTT")
UST = NewCode("UST")
)
2 changes: 1 addition & 1 deletion currency/currency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestGetDefaultBaseCurrency(t *testing.T) {
}

func TestGetDefaulCryptoCurrencies(t *testing.T) {
expected := Currencies{BTC, LTC, ETH, DOGE, DASH, XRP, XMR}
expected := Currencies{BTC, LTC, ETH, DOGE, DASH, XRP, XMR, USDT, UST}
if !GetDefaultCryptocurrencies().Match(expected) {
t.Errorf("GetDefaultCryptocurrencies() expected %s but received %s",
expected, GetDefaultCryptocurrencies())
Expand Down
2 changes: 1 addition & 1 deletion currency/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Storage) SetDefaults() {
log.Errorf(log.Global, "Currency Storage: Setting default fiat currencies error: %s", err)
}

err = s.SetDefaultCryptocurrencies(BTC, LTC, ETH, DOGE, DASH, XRP, XMR)
err = s.SetDefaultCryptocurrencies(BTC, LTC, ETH, DOGE, DASH, XRP, XMR, USDT, UST)
if err != nil {
log.Errorf(log.Global, "Currency Storage: Setting default cryptocurrencies error: %s", err)
}
Expand Down
Loading

0 comments on commit 0c00b7e

Please sign in to comment.