Skip to content

Commit

Permalink
Moved withdraw structs into own package
Browse files Browse the repository at this point in the history
  • Loading branch information
xtda committed Dec 12, 2019
1 parent 473092a commit a91d147
Show file tree
Hide file tree
Showing 64 changed files with 323 additions and 260 deletions.
6 changes: 3 additions & 3 deletions cmd/exchange_template/wrapper_file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,19 @@ func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency currency

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
// submitted
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
// submitted
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/exchange_wrapper_coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

const (
Expand Down Expand Up @@ -173,16 +174,16 @@ func testWrappers(e exchange.IBotExchange) []string {
funcs = append(funcs, "GetDepositAddress")
}

_, err = e.WithdrawCryptocurrencyFunds(&exchange.CryptoWithdrawRequest{})
_, err = e.WithdrawCryptocurrencyFunds(&withdraw.CryptoWithdrawRequest{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "WithdrawCryptocurrencyFunds")
}

_, err = e.WithdrawFiatFunds(&exchange.FiatWithdrawRequest{})
_, err = e.WithdrawFiatFunds(&withdraw.FiatWithdrawRequest{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "WithdrawFiatFunds")
}
_, err = e.WithdrawFiatFundsToInternationalBank(&exchange.FiatWithdrawRequest{})
_, err = e.WithdrawFiatFundsToInternationalBank(&withdraw.FiatWithdrawRequest{})
if err == common.ErrNotYetImplemented {
funcs = append(funcs, "WithdrawFiatFundsToInternationalBank")
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

func main() {
Expand Down Expand Up @@ -619,11 +620,11 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r19}),
})

genericWithdrawRequest := exchange.GenericWithdrawRequestInfo{
genericWithdrawRequest := withdraw.GenericWithdrawRequestInfo{
Amount: config.OrderSubmission.Amount,
Currency: p.Quote,
}
withdrawRequest := exchange.CryptoWithdrawRequest{
withdrawRequest := withdraw.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: genericWithdrawRequest,
Address: withdrawAddressOverride,
}
Expand Down Expand Up @@ -663,7 +664,7 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
Response: jsonifyInterface([]interface{}{r21}),
})

fiatWithdrawRequest := exchange.FiatWithdrawRequest{
fiatWithdrawRequest := withdraw.FiatWithdrawRequest{
GenericWithdrawRequestInfo: genericWithdrawRequest,
BankAccountName: config.BankDetails.BankAccountName,
BankAccountNumber: config.BankDetails.BankAccountNumber,
Expand Down
3 changes: 2 additions & 1 deletion engine/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/stats"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
log "github.com/thrasher-corp/gocryptotrader/logger"
"github.com/thrasher-corp/gocryptotrader/portfolio"
"github.com/thrasher-corp/gocryptotrader/utils"
Expand Down Expand Up @@ -699,7 +700,7 @@ func GetExchangeCryptocurrencyDepositAddresses() map[string]map[string]string {
}

// WithdrawCryptocurrencyFundsByExchange withdraws the desired cryptocurrency and amount to a desired cryptocurrency address
func WithdrawCryptocurrencyFundsByExchange(exchName string, req *exchange.CryptoWithdrawRequest) (string, error) {
func WithdrawCryptocurrencyFundsByExchange(exchName string, req *withdraw.CryptoWithdrawRequest) (string, error) {
if req == nil {
return "", errors.New("crypto withdraw request param is nil")
}
Expand Down
7 changes: 4 additions & 3 deletions exchanges/alphapoint/alphapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

const (
Expand Down Expand Up @@ -560,7 +561,7 @@ func TestModifyOrder(t *testing.T) {

func TestWithdraw(t *testing.T) {
t.Parallel()
var withdrawCryptoRequest = exchange.CryptoWithdrawRequest{}
var withdrawCryptoRequest = withdraw.CryptoWithdrawRequest{}
_, err := a.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
if err != common.ErrNotYetImplemented {
t.Errorf("Expected 'Not implemented', received %v", err)
Expand All @@ -573,7 +574,7 @@ func TestWithdrawFiat(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{}
_, err := a.WithdrawFiatFunds(&withdrawFiatRequest)
if err != common.ErrNotYetImplemented {
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
Expand All @@ -586,7 +587,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{}
_, err := a.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
if err != common.ErrNotYetImplemented {
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
Expand Down
7 changes: 4 additions & 3 deletions exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

// GetDefaultConfig returns a default exchange config for Alphapoint
Expand Down Expand Up @@ -282,18 +283,18 @@ func (a *Alphapoint) GetDepositAddress(cryptocurrency currency.Code, _ string) (

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (a *Alphapoint) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
func (a *Alphapoint) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
func (a *Alphapoint) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (a *Alphapoint) WithdrawFiatFunds(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
// submitted
func (a *Alphapoint) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (a *Alphapoint) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}

Expand Down
9 changes: 5 additions & 4 deletions exchanges/anx/anx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

// Please supply your own keys here for due diligence testing
Expand Down Expand Up @@ -326,8 +327,8 @@ func TestWithdraw(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

withdrawCryptoRequest := exchange.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
withdrawCryptoRequest := withdraw.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: withdraw.GenericWithdrawRequestInfo{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Expand All @@ -346,7 +347,7 @@ func TestWithdraw(t *testing.T) {

func TestWithdrawFiat(t *testing.T) {
t.Parallel()
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{}
_, err := a.WithdrawFiatFunds(&withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'",
Expand All @@ -357,7 +358,7 @@ func TestWithdrawFiat(t *testing.T) {

func TestWithdrawInternationalBank(t *testing.T) {
t.Parallel()
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{}
_, err := a.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'",
Expand Down
7 changes: 4 additions & 3 deletions exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
log "github.com/thrasher-corp/gocryptotrader/logger"
)

Expand Down Expand Up @@ -417,20 +418,20 @@ func (a *ANX) GetDepositAddress(cryptocurrency currency.Code, _ string) (string,

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (a *ANX) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
func (a *ANX) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoWithdrawRequest) (string, error) {
return a.Send(withdrawRequest.Currency.String(), withdrawRequest.Address, "", strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64))
}

// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
// submitted
func (a *ANX) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (a *ANX) WithdrawFiatFunds(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
// Fiat withdrawals available via website
return "", common.ErrFunctionNotSupported
}

// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
// submitted
func (a *ANX) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (a *ANX) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
// Fiat withdrawals available via website
return "", common.ErrFunctionNotSupported
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/binance/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
allOrders = "/api/v3/allOrders"

// Withdraw API endpoints
withdraw = "/wapi/v3/withdraw.html"
withdrawEndpoint = "/wapi/v3/withdraw.html"
depositHistory = "/wapi/v3/depositHistory.html"
withdrawalHistory = "/wapi/v3/withdrawHistory.html"
depositAddress = "/wapi/v3/depositAddress.html"
Expand Down Expand Up @@ -643,7 +643,7 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
// WithdrawCrypto sends cryptocurrency to the address of your choosing
func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string) (string, error) {
var resp WithdrawResponse
path := b.API.Endpoints.URL + withdraw
path := b.API.Endpoints.URL + withdrawEndpoint

params := url.Values{}
params.Set("asset", asset)
Expand Down
9 changes: 5 additions & 4 deletions exchanges/binance/binance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

// Please supply your own keys here for due diligence testing
Expand Down Expand Up @@ -453,8 +454,8 @@ func TestWithdraw(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

withdrawCryptoRequest := exchange.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
withdrawCryptoRequest := withdraw.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: withdraw.GenericWithdrawRequestInfo{
Amount: 0,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Expand All @@ -476,7 +477,7 @@ func TestWithdraw(t *testing.T) {
func TestWithdrawFiat(t *testing.T) {
t.Parallel()

var withdrawFiatRequest exchange.FiatWithdrawRequest
var withdrawFiatRequest withdraw.FiatWithdrawRequest
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
Expand All @@ -486,7 +487,7 @@ func TestWithdrawFiat(t *testing.T) {
func TestWithdrawInternationalBank(t *testing.T) {
t.Parallel()

var withdrawFiatRequest exchange.FiatWithdrawRequest
var withdrawFiatRequest withdraw.FiatWithdrawRequest
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
if err != common.ErrFunctionNotSupported {
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
Expand Down
7 changes: 4 additions & 3 deletions exchanges/binance/binance_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
log "github.com/thrasher-corp/gocryptotrader/logger"
)

Expand Down Expand Up @@ -494,7 +495,7 @@ func (b *Binance) GetDepositAddress(cryptocurrency currency.Code, _ string) (str

// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWithdrawRequest) (string, error) {
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoWithdrawRequest) (string, error) {
amountStr := strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
return b.WithdrawCrypto(withdrawRequest.Currency.String(),
withdrawRequest.Address,
Expand All @@ -504,13 +505,13 @@ func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.CryptoWi

// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (b *Binance) WithdrawFiatFunds(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (b *Binance) WithdrawFiatFunds(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrFunctionNotSupported
}

// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
// withdrawal is submitted
func (b *Binance) WithdrawFiatFundsToInternationalBank(withdrawRequest *exchange.FiatWithdrawRequest) (string, error) {
func (b *Binance) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatWithdrawRequest) (string, error) {
return "", common.ErrFunctionNotSupported
}

Expand Down
3 changes: 2 additions & 1 deletion exchanges/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
log "github.com/thrasher-corp/gocryptotrader/logger"
)

Expand Down Expand Up @@ -541,7 +542,7 @@ func (b *Bitfinex) WithdrawCryptocurrency(withdrawType, wallet, address, payment
}

// WithdrawFIAT Sends an authenticated request to withdraw FIAT currency
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *exchange.FiatWithdrawRequest) ([]Withdrawal, error) {
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *withdraw.FiatWithdrawRequest) ([]Withdrawal, error) {
var response []Withdrawal
req := make(map[string]interface{})

Expand Down
13 changes: 7 additions & 6 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
)

// Please supply your own keys here to do better tests
Expand Down Expand Up @@ -884,8 +885,8 @@ func TestWithdraw(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

withdrawCryptoRequest := exchange.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
withdrawCryptoRequest := withdraw.CryptoWithdrawRequest{
GenericWithdrawRequestInfo: withdraw.GenericWithdrawRequestInfo{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Expand All @@ -908,8 +909,8 @@ func TestWithdrawFiat(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

var withdrawFiatRequest = exchange.FiatWithdrawRequest{
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{
GenericWithdrawRequestInfo: withdraw.GenericWithdrawRequestInfo{
Amount: -1,
Currency: currency.USD,
Description: "WITHDRAW IT ALL",
Expand Down Expand Up @@ -941,8 +942,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}

var withdrawFiatRequest = exchange.FiatWithdrawRequest{
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
var withdrawFiatRequest = withdraw.FiatWithdrawRequest{
GenericWithdrawRequestInfo: withdraw.GenericWithdrawRequestInfo{
Amount: -1,
Currency: currency.BTC,
Description: "WITHDRAW IT ALL",
Expand Down
Loading

0 comments on commit a91d147

Please sign in to comment.