mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-18 15:10:03 +00:00
* 1) Update Dockerfile/docker-compose.yml 2) Remove inline strings for buy/sell/test pairs 3) Remove dangerous order submission values 4) Fix consistency with audit_events (all other spec files use CamelCase) 5) Update web websocket endpoint 6) Fix main param set (and induce dryrun mode on specific command line params) * Engine QA Link up exchange syncer to cmd params, disarm market selling bombs and fix OKEX endpoints * Fix linter issue after merge * Engine QA changes Template updates Wrapper code cleanup Disarmed order bombs Documentation updates * Daily engine QA Bitstamp improvements Spelling mistakes Add Coinbene exchange to support list Protect API authenticated calls for Coinbene/LBank * Engine QA changes Fix exchange_wrapper_coverage tool Add SupportsAsset to exchange interface Fix inline string usage and add BCH withdrawal support * Engine QA Fix Bitstamp types Inform user of errors when parsing time accross the codebase Change time parsing warnings to errors (as they are) Update markdown docs [with linter fixes] * Engine QA changes 1) Add test for dryrunParamInteraction 2) Disarm OKCoin/OKEX bombs if someone accidently sets canManipulateRealOrders to true and runs all package tests 3) Actually check exchange setup errors for BTSE and Coinbene, plus address this in the wrapper template 4) Hardcode missing/non-retrievable contributors and bump the contributors 5) Convert numbers/strings to meaningful types in Bitstamp and OKEX 6) If WS is supported for the exchange wrapper template, preset authWebsocketSupport var * Fix the shadow people * Link the SyncContinuously paramerino * Also show SyncContinuously in engine.PrintSettings * Address nitterinos and use correct filepath for logs * Bitstamp: Extract ALL THE APM * Fix additional nitterinos * Fix time parsing error for Bittrex
549 lines
14 KiB
Go
549 lines
14 KiB
Go
package bithumb
|
|
|
|
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"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
)
|
|
|
|
// Please supply your own keys here for due diligence testing
|
|
const (
|
|
apiKey = ""
|
|
apiSecret = ""
|
|
canManipulateRealOrders = false
|
|
testCurrency = "btc"
|
|
)
|
|
|
|
var b Bithumb
|
|
|
|
func TestSetDefaults(t *testing.T) {
|
|
b.SetDefaults()
|
|
}
|
|
|
|
func TestSetup(t *testing.T) {
|
|
cfg := config.GetConfig()
|
|
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
|
if err != nil {
|
|
t.Fatal("Bithumb load config error", err)
|
|
}
|
|
bitConfig, err := cfg.GetExchangeConfig("Bithumb")
|
|
if err != nil {
|
|
t.Error("Bithumb Setup() init error")
|
|
}
|
|
|
|
bitConfig.API.AuthenticatedSupport = true
|
|
bitConfig.API.Credentials.Key = apiKey
|
|
bitConfig.API.Credentials.Secret = apiSecret
|
|
|
|
err = b.Setup(bitConfig)
|
|
if err != nil {
|
|
t.Fatal("Bithumb setup error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTradablePairs(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetTradablePairs()
|
|
if err != nil {
|
|
t.Error("Bithumb GetTradablePairs() error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTicker(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetTicker(testCurrency)
|
|
if err != nil {
|
|
t.Error("Bithumb GetTicker() error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetAllTickers(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetAllTickers()
|
|
if err != nil {
|
|
t.Error("Bithumb GetAllTickers() error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetOrderBook(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetOrderBook(testCurrency)
|
|
if err != nil {
|
|
t.Error("Bithumb GetOrderBook() error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTransactionHistory(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetTransactionHistory(testCurrency)
|
|
if err != nil {
|
|
t.Error("Bithumb GetTransactionHistory() error", err)
|
|
}
|
|
}
|
|
|
|
func TestGetAccountBalance(t *testing.T) {
|
|
t.Parallel()
|
|
if apiKey == "" || apiSecret == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
_, err := b.GetAccountBalance(testCurrency)
|
|
if err == nil {
|
|
t.Error("Bithumb GetAccountBalance() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestGetWalletAddress(t *testing.T) {
|
|
if apiKey == "" || apiSecret == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
t.Parallel()
|
|
_, err := b.GetWalletAddress("")
|
|
if err == nil {
|
|
t.Error("Bithumb GetWalletAddress() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestGetLastTransaction(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetLastTransaction()
|
|
if err == nil {
|
|
t.Error("Bithumb GetLastTransaction() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestGetOrders(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetOrders("1337", order.Bid.Lower(), "100", "", testCurrency)
|
|
if err == nil {
|
|
t.Error("Bithumb GetOrders() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestGetUserTransactions(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetUserTransactions()
|
|
if err == nil {
|
|
t.Error("Bithumb GetUserTransactions() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestPlaceTrade(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.PlaceTrade(testCurrency, order.Bid.Lower(), 0, 0)
|
|
if err == nil {
|
|
t.Error("Bithumb PlaceTrade() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestGetOrderDetails(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.GetOrderDetails("1337", order.Bid.Lower(), testCurrency)
|
|
if err == nil {
|
|
t.Error("Bithumb GetOrderDetails() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestCancelTrade(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.CancelTrade("", "", "")
|
|
if err == nil {
|
|
t.Error("Bithumb CancelTrade() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestWithdrawCrypto(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.WithdrawCrypto("LQxiDhKU7idKiWQhx4ALKYkBx8xKEQVxJR", "", "ltc", 0)
|
|
if err == nil {
|
|
t.Error("Bithumb WithdrawCrypto() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestRequestKRWDepositDetails(t *testing.T) {
|
|
t.Parallel()
|
|
if apiKey == "" || apiSecret == "" {
|
|
t.Skip()
|
|
}
|
|
_, err := b.RequestKRWDepositDetails()
|
|
if err == nil {
|
|
t.Error("Bithumb RequestKRWDepositDetails() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestRequestKRWWithdraw(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.RequestKRWWithdraw("102_bank", "1337", 1000)
|
|
if err == nil {
|
|
t.Error("Bithumb RequestKRWWithdraw() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestMarketBuyOrder(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.MarketBuyOrder(testCurrency, 0)
|
|
if err == nil {
|
|
t.Error("Bithumb MarketBuyOrder() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestMarketSellOrder(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := b.MarketSellOrder(testCurrency, 0)
|
|
if err == nil {
|
|
t.Error("Bithumb MarketSellOrder() Expected error")
|
|
}
|
|
}
|
|
|
|
func setFeeBuilder() *exchange.FeeBuilder {
|
|
return &exchange.FeeBuilder{
|
|
Amount: 1,
|
|
FeeType: exchange.CryptocurrencyTradeFee,
|
|
Pair: currency.NewPair(currency.BTC, currency.LTC),
|
|
PurchasePrice: 1,
|
|
}
|
|
}
|
|
|
|
// TestGetFeeByTypeOfflineTradeFee logic test
|
|
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
|
var feeBuilder = setFeeBuilder()
|
|
b.GetFeeByType(feeBuilder)
|
|
if apiKey == "" || apiSecret == "" {
|
|
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
|
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
|
}
|
|
} else {
|
|
if feeBuilder.FeeType != exchange.CryptocurrencyTradeFee {
|
|
t.Errorf("Expected %v, received %v", exchange.CryptocurrencyTradeFee, feeBuilder.FeeType)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetFee(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
var feeBuilder = setFeeBuilder()
|
|
|
|
// CryptocurrencyTradeFee Basic
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0.0025) || err != nil {
|
|
t.Error(err)
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee High quantity
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.Amount = 1000
|
|
feeBuilder.PurchasePrice = 1000
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(2500) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(2500), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee IsMaker
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.IsMaker = true
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0.0025) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee Negative purchase price
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.PurchasePrice = -1000
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyWithdrawalFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0.001) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CyptocurrencyDepositFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// InternationalBankDepositFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.InternationalBankDepositFee
|
|
feeBuilder.FiatCurrency = currency.HKD
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// InternationalBankWithdrawalFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
|
|
feeBuilder.FiatCurrency = currency.HKD
|
|
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestFormatWithdrawPermissions(t *testing.T) {
|
|
b.SetDefaults()
|
|
expectedResult := exchange.AutoWithdrawCryptoText + " & " + exchange.AutoWithdrawFiatText
|
|
|
|
withdrawPermissions := b.FormatWithdrawPermissions()
|
|
|
|
if withdrawPermissions != expectedResult {
|
|
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
|
}
|
|
}
|
|
|
|
func TestGetActiveOrders(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
var getOrdersRequest = order.GetOrdersRequest{
|
|
OrderType: order.AnyType,
|
|
OrderSide: order.Sell,
|
|
}
|
|
|
|
_, 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")
|
|
}
|
|
}
|
|
|
|
func TestGetOrderHistory(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
var getOrdersRequest = order.GetOrdersRequest{
|
|
OrderType: order.AnyType,
|
|
}
|
|
|
|
_, 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")
|
|
}
|
|
}
|
|
|
|
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
|
// ----------------------------------------------------------------------------------------------------------------------------
|
|
func areTestAPIKeysSet() bool {
|
|
return b.ValidateAPICredentials()
|
|
}
|
|
|
|
func TestSubmitOrder(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
var orderSubmission = &order.Submit{
|
|
Pair: currency.Pair{
|
|
Base: currency.BTC,
|
|
Quote: currency.LTC,
|
|
},
|
|
OrderSide: order.Buy,
|
|
OrderType: order.Limit,
|
|
Price: 1,
|
|
Amount: 1,
|
|
ClientID: "meowOrder",
|
|
}
|
|
response, err := b.SubmitOrder(orderSubmission)
|
|
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")
|
|
}
|
|
}
|
|
|
|
func TestCancelExchangeOrder(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
|
|
|
var orderCancellation = &order.Cancel{
|
|
OrderID: "1",
|
|
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
AccountID: "1",
|
|
CurrencyPair: currencyPair,
|
|
}
|
|
|
|
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 order: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestCancelAllExchangeOrders(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
|
|
|
var orderCancellation = &order.Cancel{
|
|
OrderID: "1",
|
|
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
AccountID: "1",
|
|
CurrencyPair: currencyPair,
|
|
}
|
|
|
|
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.Status) > 0 {
|
|
t.Errorf("%v orders failed to cancel", len(resp.Status))
|
|
}
|
|
}
|
|
|
|
func TestGetAccountInfo(t *testing.T) {
|
|
t.Parallel()
|
|
if apiKey != "" || apiSecret != "" {
|
|
_, err := b.GetAccountInfo()
|
|
if err != nil {
|
|
t.Error("Bithumb GetAccountInfo() error", err)
|
|
}
|
|
} else {
|
|
_, err := b.GetAccountInfo()
|
|
if err == nil {
|
|
t.Error("Bithumb GetAccountInfo() Expected error")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestModifyOrder(t *testing.T) {
|
|
curr := currency.NewPairFromString("BTCUSD")
|
|
_, err := b.ModifyOrder(&order.Modify{
|
|
OrderID: "1337",
|
|
Price: 100,
|
|
Amount: 1000,
|
|
Side: order.Sell,
|
|
CurrencyPair: curr})
|
|
if err == nil {
|
|
t.Error("ModifyOrder() Expected error")
|
|
}
|
|
}
|
|
|
|
func TestWithdraw(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
withdrawCryptoRequest := exchange.CryptoWithdrawRequest{
|
|
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
|
|
Amount: -1,
|
|
Currency: currency.BTC,
|
|
Description: "WITHDRAW IT ALL",
|
|
},
|
|
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
}
|
|
|
|
_, 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)
|
|
}
|
|
}
|
|
|
|
func TestWithdrawFiat(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
var withdrawFiatRequest = exchange.FiatWithdrawRequest{
|
|
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
|
|
Amount: -1,
|
|
Currency: currency.USD,
|
|
Description: "WITHDRAW IT ALL",
|
|
},
|
|
BankAccountName: "Satoshi Nakamoto",
|
|
BankAccountNumber: 12345,
|
|
BankCode: 123,
|
|
BankAddress: "123 Fake St",
|
|
BankCity: "Tarry Town",
|
|
BankCountry: "Hyrule",
|
|
BankName: "Federal Reserve Bank",
|
|
WireCurrency: currency.KRW.String(),
|
|
SwiftCode: "Taylor",
|
|
RequiresIntermediaryBank: false,
|
|
IsExpressWire: false,
|
|
}
|
|
|
|
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestWithdrawInternationalBank(t *testing.T) {
|
|
b.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
var withdrawFiatRequest = exchange.FiatWithdrawRequest{}
|
|
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
|
if err != common.ErrFunctionNotSupported {
|
|
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
|
}
|
|
}
|
|
|
|
func TestGetDepositAddress(t *testing.T) {
|
|
if apiKey != "" && apiSecret != "" {
|
|
_, err := b.GetDepositAddress(currency.BTC, "")
|
|
if err != nil {
|
|
t.Error("GetDepositAddress() error", err)
|
|
}
|
|
} else {
|
|
_, err := b.GetDepositAddress(currency.BTC, "")
|
|
if err == nil {
|
|
t.Error("GetDepositAddress() error cannot be nil")
|
|
}
|
|
}
|
|
}
|