mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
Initial implementation of HTTP mock testing framework (#310)
* Initial implementation of HTTP mock testing framework Convert to VCR testing server. Segregate live testing via build tags. Converted Binance to VCR server Convert Bitstamp to VCR mocking tests Added VCR mock testing for localbitcoins * Add server generation for concurrent testing * Fix linter issues * Fix linter issue * fix race - potentially * revert auto assigning of host vals * Fix requested changes * Adds mock testing for ANX Switch to using TestMain functionality Added cron job usage for travis-ci to live testing Added appveyor scheduled build check for live testing * WOOPS * silly correction * Fixes fantastic linter issues * fixed another whoopsie * WOOO! * Adds gemini mock testing with additional fixes * Add docs and sharedvalue * Added tls using httptest package * Fixed issues * added explicit mock recording reference to error * Fix requested changes * strip port from mock files as they are not needed on tls server * Change incorrect names * fix requested changes * lbank update * Fix another issue * Updated readme
This commit is contained in:
committed by
Adrian Gallagher
parent
a81ddead9e
commit
6d8ba0a96a
@@ -279,20 +279,10 @@ func (b *Binance) GetRecentTrades(rtr RecentTradeRequestParams) ([]RecentTrade,
|
||||
// limit: Optional. Default 500; max 1000.
|
||||
// fromID:
|
||||
func (b *Binance) GetHistoricalTrades(symbol string, limit int, fromID int64) ([]HistoricalTrade, error) {
|
||||
var resp []HistoricalTrade
|
||||
|
||||
if err := b.CheckLimit(limit); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("symbol", common.StringToUpper(symbol))
|
||||
params.Set("limit", strconv.Itoa(limit))
|
||||
params.Set("fromid", strconv.FormatInt(fromID, 10))
|
||||
|
||||
path := fmt.Sprintf("%s%s?%s", b.APIUrl, historicalTrades, params.Encode())
|
||||
|
||||
return resp, b.SendHTTPRequest(path, &resp)
|
||||
// Dropping support due to response for market data is always
|
||||
// {"code":-2014,"msg":"API-key format invalid."}
|
||||
// TODO: replace with newer API vs REST endpoint
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetAggregatedTrades returns aggregated trade activity
|
||||
@@ -617,7 +607,16 @@ func (b *Binance) GetAccount() (*Account, error) {
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated request
|
||||
func (b *Binance) SendHTTPRequest(path string, result interface{}) error {
|
||||
return b.SendPayload(http.MethodGet, path, nil, nil, result, false, false, b.Verbose, b.HTTPDebugging)
|
||||
return b.SendPayload(http.MethodGet,
|
||||
path,
|
||||
nil,
|
||||
nil,
|
||||
result,
|
||||
false,
|
||||
false,
|
||||
b.Verbose,
|
||||
b.HTTPDebugging,
|
||||
b.HTTPRecording)
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated HTTP request
|
||||
@@ -653,7 +652,16 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
|
||||
Message string `json:"msg"`
|
||||
}{}
|
||||
|
||||
err := b.SendPayload(method, path, headers, bytes.NewBuffer(nil), &interim, true, false, b.Verbose, b.HTTPDebugging)
|
||||
err := b.SendPayload(method,
|
||||
path,
|
||||
headers,
|
||||
bytes.NewBuffer(nil),
|
||||
&interim,
|
||||
true,
|
||||
false,
|
||||
b.Verbose,
|
||||
b.HTTPDebugging,
|
||||
b.HTTPRecording)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -773,7 +781,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) (int64, error) {
|
||||
func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string) (string, error) {
|
||||
var resp WithdrawResponse
|
||||
path := fmt.Sprintf("%s%s", b.APIUrl, withdraw)
|
||||
|
||||
@@ -789,7 +797,7 @@ func (b *Binance) WithdrawCrypto(asset, address, addressTag, name, amount string
|
||||
}
|
||||
|
||||
if err := b.SendAuthHTTPRequest(http.MethodPost, path, params, &resp); err != nil {
|
||||
return -1, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !resp.Success {
|
||||
|
||||
32
exchanges/binance/binance_live_test.go
Normal file
32
exchanges/binance/binance_live_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
//+build mock_test_off
|
||||
|
||||
// This will build if build tag mock_test_off is parsed and will do live testing
|
||||
// using all tests in (exchange)_test.go
|
||||
package binance
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
)
|
||||
|
||||
var mockTests = false
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
cfg := config.GetConfig()
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
binanceConfig, err := cfg.GetExchangeConfig("Binance")
|
||||
if err != nil {
|
||||
log.Fatal("Test Failed - Binance Setup() init error", err)
|
||||
}
|
||||
binanceConfig.AuthenticatedAPISupport = true
|
||||
binanceConfig.APIKey = apiKey
|
||||
binanceConfig.APISecret = apiSecret
|
||||
b.SetDefaults()
|
||||
b.Setup(&binanceConfig)
|
||||
log.Printf(sharedtestvalues.LiveTesting, b.GetName(), b.APIUrl)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
44
exchanges/binance/binance_mock_test.go
Normal file
44
exchanges/binance/binance_mock_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
//+build !mock_test_off
|
||||
|
||||
// This will build if build tag mock_test_off is not parsed and will try to mock
|
||||
// all tests in _test.go
|
||||
package binance
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/mock"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
)
|
||||
|
||||
const mockfile = "../../testdata/http_mock/binance/binance.json"
|
||||
|
||||
var mockTests = true
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
cfg := config.GetConfig()
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
binanceConfig, err := cfg.GetExchangeConfig("Binance")
|
||||
if err != nil {
|
||||
log.Fatal("Test Failed - Binance Setup() init error", err)
|
||||
}
|
||||
binanceConfig.AuthenticatedAPISupport = true
|
||||
binanceConfig.APIKey = apiKey
|
||||
binanceConfig.APISecret = apiSecret
|
||||
b.SetDefaults()
|
||||
b.Setup(&binanceConfig)
|
||||
|
||||
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
|
||||
if err != nil {
|
||||
log.Fatalf("Test Failed - Mock server error %s", err)
|
||||
}
|
||||
|
||||
b.HTTPClient = newClient
|
||||
b.APIUrl = serverDetails
|
||||
|
||||
log.Printf(sharedtestvalues.MockTesting, b.GetName(), b.APIUrl)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
)
|
||||
@@ -18,26 +17,26 @@ const (
|
||||
|
||||
var b Binance
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
func areTestAPIKeysSet() bool {
|
||||
if b.APIKey != "" && b.APIKey != "Key" &&
|
||||
b.APISecret != "" && b.APISecret != "Secret" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
cfg.LoadConfig("../../testdata/configtest.json")
|
||||
binanceConfig, err := cfg.GetExchangeConfig("Binance")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance Setup() init error")
|
||||
func setFeeBuilder() *exchange.FeeBuilder {
|
||||
return &exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPair(currency.BTC, currency.LTC),
|
||||
PurchasePrice: 1,
|
||||
}
|
||||
|
||||
binanceConfig.AuthenticatedAPISupport = true
|
||||
binanceConfig.APIKey = apiKey
|
||||
binanceConfig.APISecret = apiSecret
|
||||
b.Setup(&binanceConfig)
|
||||
}
|
||||
|
||||
func TestGetExchangeValidCurrencyPairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetExchangeValidCurrencyPairs()
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetExchangeValidCurrencyPairs() error", err)
|
||||
@@ -46,6 +45,7 @@ func TestGetExchangeValidCurrencyPairs(t *testing.T) {
|
||||
|
||||
func TestGetOrderBook(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetOrderBook(OrderBookDataRequestParams{
|
||||
Symbol: "BTCUSDT",
|
||||
Limit: 10,
|
||||
@@ -71,14 +71,19 @@ func TestGetRecentTrades(t *testing.T) {
|
||||
|
||||
func TestGetHistoricalTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetHistoricalTrades("BTCUSDT", 5, 1337)
|
||||
if err == nil {
|
||||
|
||||
_, err := b.GetHistoricalTrades("BTCUSDT", 5, 0)
|
||||
if !mockTests && err == nil {
|
||||
t.Error("Test Failed - Binance GetHistoricalTrades() expecting error")
|
||||
}
|
||||
if mockTests && err == nil {
|
||||
t.Error("Test Failed - Binance GetHistoricalTrades() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAggregatedTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetAggregatedTrades("BTCUSDT", 5)
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetAggregatedTrades() error", err)
|
||||
@@ -87,6 +92,7 @@ func TestGetAggregatedTrades(t *testing.T) {
|
||||
|
||||
func TestGetSpotKline(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetSpotKline(KlinesRequestParams{
|
||||
Symbol: "BTCUSDT",
|
||||
Interval: TimeIntervalFiveMinutes,
|
||||
@@ -99,6 +105,7 @@ func TestGetSpotKline(t *testing.T) {
|
||||
|
||||
func TestGetAveragePrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetAveragePrice("BTCUSDT")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetAveragePrice() error", err)
|
||||
@@ -107,6 +114,7 @@ func TestGetAveragePrice(t *testing.T) {
|
||||
|
||||
func TestGetPriceChangeStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetPriceChangeStats("BTCUSDT")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetPriceChangeStats() error", err)
|
||||
@@ -115,6 +123,7 @@ func TestGetPriceChangeStats(t *testing.T) {
|
||||
|
||||
func TestGetTickers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetTickers()
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance TestGetTickers error", err)
|
||||
@@ -123,6 +132,7 @@ func TestGetTickers(t *testing.T) {
|
||||
|
||||
func TestGetLatestSpotPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetLatestSpotPrice("BTCUSDT")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetLatestSpotPrice() error", err)
|
||||
@@ -131,120 +141,62 @@ func TestGetLatestSpotPrice(t *testing.T) {
|
||||
|
||||
func TestGetBestPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetBestPrice("BTCUSDT")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance GetBestPrice() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
_, err := b.NewOrder(&NewOrderRequest{
|
||||
Symbol: "BTCUSDT",
|
||||
Side: BinanceRequestParamsSideSell,
|
||||
TradeType: BinanceRequestParamsOrderLimit,
|
||||
TimeInForce: BinanceRequestParamsTimeGTC,
|
||||
Quantity: 0.01,
|
||||
Price: 1536.1,
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
t.Error("Test Failed - Binance NewOrder() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExistingOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.CancelExistingOrder("BTCUSDT", 82584683, "")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance CancelExistingOrder() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.QueryOrder("BTCUSDT", "", 1337)
|
||||
if err == nil {
|
||||
t.Error("Test Failed - Binance QueryOrder() error", err)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - QueryOrder() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - QueryOrder() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock QueryOrder() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.OpenOrders("BTCUSDT")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance OpenOrders() error", err)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - OpenOrders() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - OpenOrders() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock OpenOrders() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
_, err := b.AllOrders("BTCUSDT", "", "")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - Binance AllOrders() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccount(t *testing.T) {
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
account, err := b.GetAccount()
|
||||
if err != nil {
|
||||
t.Fatal("Test Failed - Binance GetAccount() error", err)
|
||||
}
|
||||
if account.MakerCommission <= 0 {
|
||||
t.Fatalf("Test Failed. Expected > 0, Received %d", account.MakerCommission)
|
||||
}
|
||||
if account.TakerCommission <= 0 {
|
||||
t.Fatalf("Test Failed. Expected > 0, Received %d", account.TakerCommission)
|
||||
}
|
||||
|
||||
t.Logf("Current makerFee: %d", account.MakerCommission)
|
||||
t.Logf("Current takerFee: %d", account.TakerCommission)
|
||||
}
|
||||
|
||||
func setFeeBuilder() *exchange.FeeBuilder {
|
||||
return &exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPair(currency.BTC, currency.LTC),
|
||||
PurchasePrice: 1,
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - AllOrders() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - AllOrders() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock AllOrders() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetFeeByTypeOfflineTradeFee logic test
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var feeBuilder = setFeeBuilder()
|
||||
b.GetFeeByType(feeBuilder)
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
if !areTestAPIKeysSet() {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
@@ -256,12 +208,11 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
var feeBuilder = setFeeBuilder()
|
||||
|
||||
if apiKey != "" || apiSecret != "" {
|
||||
if areTestAPIKeysSet() || mockTests {
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if resp, err := b.GetFee(feeBuilder); resp != float64(0.1) || err != nil {
|
||||
t.Error(err)
|
||||
@@ -331,19 +282,18 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
t.Parallel()
|
||||
|
||||
expectedResult := exchange.AutoWithdrawCryptoText + " & " + exchange.NoFiatWithdrawalsText
|
||||
|
||||
withdrawPermissions := b.FormatWithdrawPermissions()
|
||||
|
||||
if withdrawPermissions != expectedResult {
|
||||
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
@@ -358,16 +308,18 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = b.GetActiveOrders(&getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - GetActiveOrders() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - GetActiveOrders() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock GetActiveOrders() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = exchange.GetOrdersRequest{
|
||||
OrderType: exchange.AnyOrderType,
|
||||
@@ -383,144 +335,144 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
currency.BTC)}
|
||||
|
||||
_, err = b.GetOrderHistory(&getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - GetOrderHistory() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - GetOrderHistory() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock GetOrderHistory() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
func areTestAPIKeysSet() bool {
|
||||
if b.APIKey != "" && b.APIKey != "Key" &&
|
||||
b.APISecret != "" && b.APISecret != "Secret" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
var p = currency.Pair{
|
||||
Delimiter: "",
|
||||
Base: currency.LTC,
|
||||
Quote: currency.BTC,
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
response, err := b.SubmitOrder(p, exchange.BuyOrderSide, exchange.MarketOrderType, 1, 1, "clientId")
|
||||
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")
|
||||
|
||||
_, err := b.SubmitOrder(currency.NewPair(currency.LTC, currency.BTC),
|
||||
exchange.BuyOrderSide,
|
||||
exchange.MarketOrderType,
|
||||
1,
|
||||
1,
|
||||
"clientId")
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - SubmitOrder() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - SubmitOrder() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock SubmitOrder() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
CurrencyPair: currencyPair,
|
||||
CurrencyPair: currency.NewPair(currency.LTC, currency.BTC),
|
||||
}
|
||||
|
||||
err := b.CancelOrder(orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - CancelExchangeOrder() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - CancelExchangeOrder() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock CancelExchangeOrder() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var orderCancellation = &exchange.OrderCancellation{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
AccountID: "1",
|
||||
CurrencyPair: currencyPair,
|
||||
CurrencyPair: currency.NewPair(currency.LTC, currency.BTC),
|
||||
}
|
||||
|
||||
resp, err := b.CancelAllOrders(orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Could not cancel order: %v", err)
|
||||
}
|
||||
|
||||
if len(resp.OrderStatus) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
|
||||
_, err := b.CancelAllOrders(orderCancellation)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - CancelAllExchangeOrders() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - CancelAllExchangeOrders() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock CancelAllExchangeOrders() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
t.Skip()
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetAccountInfo()
|
||||
if err != nil {
|
||||
t.Error("test failed - GetAccountInfo() error", err)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - GetAccountInfo() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - GetAccountInfo() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock GetAccountInfo() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
|
||||
if err == nil {
|
||||
t.Error("Test failed - ModifyOrder() error")
|
||||
t.Error("Test failed - ModifyOrder() error cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
t.Parallel()
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawCryptoRequest = exchange.WithdrawRequest{
|
||||
Amount: 100,
|
||||
Amount: 0,
|
||||
Currency: currency.BTC,
|
||||
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - Withdraw() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - Withdraw() expecting an error when no keys are set")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock Withdraw() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = exchange.WithdrawRequest{}
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest exchange.WithdrawRequest
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -528,15 +480,9 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
b.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = exchange.WithdrawRequest{}
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest exchange.WithdrawRequest
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -544,15 +490,15 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
if err == nil {
|
||||
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
switch {
|
||||
case areTestAPIKeysSet() && err != nil:
|
||||
t.Error("Test Failed - GetDepositAddress() error", err)
|
||||
case !areTestAPIKeysSet() && err == nil && !mockTests:
|
||||
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
|
||||
case mockTests && err != nil:
|
||||
t.Error("Test Failed - Mock GetDepositAddress() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ type NewOrderResponse struct {
|
||||
Price float64 `json:"price,string"`
|
||||
Qty float64 `json:"qty,string"`
|
||||
Commission float64 `json:"commission,string"`
|
||||
CommissionAsset float64 `json:"commissionAsset,string"`
|
||||
CommissionAsset string `json:"commissionAsset"`
|
||||
} `json:"fills"`
|
||||
}
|
||||
|
||||
@@ -621,5 +621,5 @@ var WithdrawalFees = map[currency.Code]float64{
|
||||
type WithdrawResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Msg string `json:"msg"`
|
||||
ID int64 `json:"id"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
@@ -301,9 +301,10 @@ func (b *Binance) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
// submitted
|
||||
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *exchange.WithdrawRequest) (string, error) {
|
||||
amountStr := strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
|
||||
id, err := b.WithdrawCrypto(withdrawRequest.Currency.String(), withdrawRequest.Address, withdrawRequest.AddressTag, withdrawRequest.Description, amountStr)
|
||||
|
||||
return strconv.FormatInt(id, 10), err
|
||||
return b.WithdrawCrypto(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.AddressTag,
|
||||
withdrawRequest.Description, amountStr)
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
|
||||
Reference in New Issue
Block a user