Withdraw Crypto wrapper mapping (#226)

* Initial commit

* Updates signature for all withdrawal methods to use new withdrawRequest struct type

* Implements crypto withdraw features & tests for Alphapoint, ANX, Binance, Bitfinex, Bitflyer, Bithumb, Bitmex, Bitstamp, Bittrex, BTCC, BTCmarkets, CoinbasePro, Coinut. Updates WithdrawRequest type with more members. Breaking change to update real order testing for increased code coverage

* Updates all realOrder tests to run when no API key is present. Updates exchange functions to handle errors better

* Implements crypto withdrawals for Exmo, GateIO, Gemini, HitBTC, Huobi, HuobiHadax, Kraken, LakeBTC, Liqui, Localbitcoins, OKCoin, OKEX, Poloniex, Wex, Yobit and ZB. Updates real order test formatting for all real order tests

* Update alphapoint. Fixes anx typos. Adds function WithdrawFiatFundsToInternationalBank to exchange wrapper interface. Adds WithdrawFiatFundsToInternationalBank to alphapoint, bitmex, coinbasepro. Updates Kraken to use TradePassword property

* Reverts alphapoint to use ErrNotYetImplemented

* Fixes line spacing and removes unnecessary line
This commit is contained in:
Scott
2019-01-03 13:15:07 +11:00
committed by Adrian Gallagher
parent 9ebcb1a462
commit b1e6534e7c
88 changed files with 2050 additions and 802 deletions

View File

@@ -317,11 +317,19 @@ func (l *LakeBTC) GetExternalAccounts() ([]ExternalAccounts, error) {
// CreateWithdraw allows your to withdraw to external account WARNING: Only for
// BTC!
func (l *LakeBTC) CreateWithdraw(amount float64, accountID int64) (Withdraw, error) {
func (l *LakeBTC) CreateWithdraw(amount float64, accountID string) (Withdraw, error) {
resp := Withdraw{}
params := strconv.FormatFloat(amount, 'f', -1, 64) + ",btc," + strconv.FormatInt(accountID, 10)
params := strconv.FormatFloat(amount, 'f', -1, 64) + ",btc," + accountID
return resp, l.SendAuthenticatedHTTPRequest(lakeBTCCreateWithdraw, params, &resp)
err := l.SendAuthenticatedHTTPRequest(lakeBTCCreateWithdraw, params, &resp)
if err != nil {
return Withdraw{}, err
}
if len(resp.Error) > 0 {
return resp, errors.New(resp.Error)
}
return resp, nil
}
// SendHTTPRequest sends an unauthenticated http request

View File

@@ -135,17 +135,6 @@ func TestGetExternalAccounts(t *testing.T) {
}
}
func TestCreateWithdraw(t *testing.T) {
t.Parallel()
if l.APIKey == "" || l.APISecret == "" {
t.Skip()
}
_, err := l.CreateWithdraw(0, 1337)
if err == nil {
t.Error("Test Failed - CreateWithdraw() error", err)
}
}
func setFeeBuilder() exchange.FeeBuilder {
return exchange.FeeBuilder{
Amount: 1,
@@ -250,21 +239,20 @@ func TestFormatWithdrawPermissions(t *testing.T) {
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
// ----------------------------------------------------------------------------------------------------------------------------
func isRealOrderTestEnabled() bool {
if l.APIKey == "" || l.APISecret == "" ||
l.APIKey == "Key" || l.APISecret == "Secret" ||
!canManipulateRealOrders {
return false
func areTestAPIKeysSet() bool {
if l.APIKey != "" && l.APIKey != "Key" &&
l.APISecret != "" && l.APISecret != "Secret" {
return true
}
return true
return false
}
func TestSubmitOrder(t *testing.T) {
l.SetDefaults()
TestSetup(t)
if !isRealOrderTestEnabled() {
t.Skip()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var p = pair.CurrencyPair{
@@ -273,8 +261,10 @@ func TestSubmitOrder(t *testing.T) {
SecondCurrency: symbol.EUR,
}
response, err := l.SubmitOrder(p, exchange.Buy, exchange.Market, 1, 10, "hi")
if err != nil || !response.IsOrderPlaced {
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
t.Errorf("Order failed to be placed: %v", err)
} else if !areTestAPIKeysSet() && err == nil {
t.Error("Expecting an error when no keys are set")
}
}
@@ -283,8 +273,8 @@ func TestCancelExchangeOrder(t *testing.T) {
l.SetDefaults()
TestSetup(t)
if !isRealOrderTestEnabled() {
t.Skip()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
@@ -300,8 +290,11 @@ func TestCancelExchangeOrder(t *testing.T) {
err := l.CancelOrder(orderCancellation)
// Assert
if err != nil {
t.Errorf("Could not cancel order: %s", err)
if !areTestAPIKeysSet() && err == nil {
t.Errorf("Expecting an error when no keys are set: %v", err)
}
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not cancel orders: %v", err)
}
}
@@ -310,8 +303,8 @@ func TestCancelAllExchangeOrders(t *testing.T) {
l.SetDefaults()
TestSetup(t)
if !isRealOrderTestEnabled() {
t.Skip()
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
@@ -327,8 +320,11 @@ func TestCancelAllExchangeOrders(t *testing.T) {
resp, err := l.CancelAllOrders(orderCancellation)
// Assert
if err != nil {
t.Errorf("Could not cancel order: %s", err)
if !areTestAPIKeysSet() && err == nil {
t.Errorf("Expecting an error when no keys are set: %v", err)
}
if areTestAPIKeysSet() && err != nil {
t.Errorf("Could not cancel orders: %v", err)
}
if len(resp.OrderStatus) > 0 {
@@ -342,3 +338,26 @@ func TestModifyOrder(t *testing.T) {
t.Error("Test failed - ModifyOrder() error")
}
}
func TestWithdraw(t *testing.T) {
l.SetDefaults()
TestSetup(t)
var withdrawCryptoRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.BTC,
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
Description: "7860767916",
}
if areTestAPIKeysSet() && !canManipulateRealOrders {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
_, err := l.WithdrawCryptocurrencyFunds(withdrawCryptoRequest)
if !areTestAPIKeysSet() && err == nil {
t.Errorf("Expecting an error when no keys are set: %v", err)
}
if areTestAPIKeysSet() && err != nil {
t.Errorf("Withdraw failed to be placed: %v", err)
}
}

View File

@@ -110,4 +110,5 @@ type Withdraw struct {
Source string `json:"source"`
ExternalAccountID int64 `json:"external_account_id,string"`
At int64 `json:"at"`
Error string `json:"error"`
}

View File

@@ -1,6 +1,7 @@
package lakebtc
import (
"errors"
"fmt"
"log"
"strconv"
@@ -8,6 +9,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -205,19 +207,28 @@ func (l *LakeBTC) GetDepositAddress(cryptocurrency pair.CurrencyItem) (string, e
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
// submitted
func (l *LakeBTC) WithdrawCryptocurrencyFunds(address string, cryptocurrency pair.CurrencyItem, amount float64) (string, error) {
return "", common.ErrNotYetImplemented
func (l *LakeBTC) WithdrawCryptocurrencyFunds(withdrawRequest exchange.WithdrawRequest) (string, error) {
if withdrawRequest.Currency.String() != symbol.BTC {
return "", errors.New("Only BTC supported for withdrawals")
}
resp, err := l.CreateWithdraw(withdrawRequest.Amount, withdrawRequest.Description)
if err != nil {
return "", err
}
return fmt.Sprintf("%v", resp.ID), nil
}
// WithdrawFiatFunds returns a withdrawal ID when a
// withdrawal is submitted
func (l *LakeBTC) WithdrawFiatFunds(currency pair.CurrencyItem, amount float64) (string, error) {
func (l *LakeBTC) WithdrawFiatFunds(withdrawRequest exchange.WithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
// withdrawal is submitted
func (l *LakeBTC) WithdrawFiatFundsToInternationalBank(currency pair.CurrencyItem, amount float64) (string, error) {
func (l *LakeBTC) WithdrawFiatFundsToInternationalBank(withdrawRequest exchange.WithdrawRequest) (string, error) {
return "", common.ErrNotYetImplemented
}