Engine: Protocol Features, coverage, types, BTC markets websocket (#368)

* Attempts to update orderbook so it doesn't need to sort

* Reverts the ws ob stuff. Gets rid of sorting because it happens later. Adds some exchange features

* update existing feature lists. Expands list definition to match my emotions

* Adds bithumb bitmex and bitstamp. adds a couple more types

* Features for you, features for me, features for bittrex, btcmarkets, btse, coinbasepro, coinut, exmo, gateio and gemini

* Features for hitbtc, huobi, itbit, kraken, lakebtc, lbank, localbitcoins, okcoin, okex, poloniex, yobit, zb

* Who can forget good old alphapoint?

* Adds btcmarksets websocket :glitch_crab: fixes alphapoint features

* Adds extra data not in the documentation :/

* Replaces websocket features by using protocol features. However, it breaks it due to import cycles. I'm not sure what I'll do just yet

* Removes import cycle via duplicate structs.

* Increases coverage of config with `TestCheckCurrencyConfigValues`. Moves all currency pair package types into their own files or places it at the bottom of files if necessary

* Increase coverage in code.go

* One way of determining a test has failed, is when to it fails. Removed redundant explanation

* Increases code coverage of conversion

* Lint fixes

* Fixes orderbook tests

* Re-adds sorting because its important to still have the internal pre-processed orderbook to be representative of a real orderbook

* Secret lints that did not show up via Windows linting

* Adds protocol package to contain exchange features

* Fixes protocol implementation

* Fixes ws tests

* Addresses the following: Removes st-st-stutters in config types, changes GetAvailableForexProviders -> GetSupportedForexProviders, removes errors from tests where error is nil, removes orderbook setup when not necessary, removes import newlines, removes false bools from declaration, changes should of to should have

* imports and casing

* Fixes two more nil error checks
This commit is contained in:
Scott
2019-10-22 10:56:20 +11:00
committed by Adrian Gallagher
parent ec0ed1c1e5
commit ccfcdf26aa
156 changed files with 5228 additions and 4337 deletions

View File

@@ -26,11 +26,11 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bithumb load config error", err)
t.Fatal("Bithumb load config error", err)
}
bitConfig, err := cfg.GetExchangeConfig("Bithumb")
if err != nil {
t.Error("Test Failed - Bithumb Setup() init error")
t.Error("Bithumb Setup() init error")
}
bitConfig.API.AuthenticatedSupport = true
@@ -39,7 +39,7 @@ func TestSetup(t *testing.T) {
err = b.Setup(bitConfig)
if err != nil {
t.Fatal("Test Failed - Bithumb setup error", err)
t.Fatal("Bithumb setup error", err)
}
}
@@ -47,7 +47,7 @@ func TestGetTradablePairs(t *testing.T) {
t.Parallel()
_, err := b.GetTradablePairs()
if err != nil {
t.Error("test failed - Bithumb GetTradablePairs() error", err)
t.Error("Bithumb GetTradablePairs() error", err)
}
}
@@ -55,7 +55,7 @@ func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := b.GetTicker("btc")
if err != nil {
t.Error("test failed - Bithumb GetTicker() error", err)
t.Error("Bithumb GetTicker() error", err)
}
}
@@ -63,7 +63,7 @@ func TestGetAllTickers(t *testing.T) {
t.Parallel()
_, err := b.GetAllTickers()
if err != nil {
t.Error("test failed - Bithumb GetAllTickers() error", err)
t.Error("Bithumb GetAllTickers() error", err)
}
}
@@ -71,7 +71,7 @@ func TestGetOrderBook(t *testing.T) {
t.Parallel()
_, err := b.GetOrderBook("btc")
if err != nil {
t.Error("test failed - Bithumb GetOrderBook() error", err)
t.Error("Bithumb GetOrderBook() error", err)
}
}
@@ -79,7 +79,7 @@ func TestGetTransactionHistory(t *testing.T) {
t.Parallel()
_, err := b.GetTransactionHistory("btc")
if err != nil {
t.Error("test failed - Bithumb GetTransactionHistory() error", err)
t.Error("Bithumb GetTransactionHistory() error", err)
}
}
@@ -91,7 +91,7 @@ func TestGetAccountBalance(t *testing.T) {
_, err := b.GetAccountBalance("BTC")
if err == nil {
t.Error("test failed - Bithumb GetAccountBalance() error", err)
t.Error("Bithumb GetAccountBalance() Expected error")
}
}
@@ -103,7 +103,7 @@ func TestGetWalletAddress(t *testing.T) {
t.Parallel()
_, err := b.GetWalletAddress("")
if err == nil {
t.Error("test failed - Bithumb GetWalletAddress() error", err)
t.Error("Bithumb GetWalletAddress() Expected error")
}
}
@@ -111,7 +111,7 @@ func TestGetLastTransaction(t *testing.T) {
t.Parallel()
_, err := b.GetLastTransaction()
if err == nil {
t.Error("test failed - Bithumb GetLastTransaction() error", err)
t.Error("Bithumb GetLastTransaction() Expected error")
}
}
@@ -119,7 +119,7 @@ func TestGetOrders(t *testing.T) {
t.Parallel()
_, err := b.GetOrders("1337", "bid", "100", "", "BTC")
if err == nil {
t.Error("test failed - Bithumb GetOrders() error", err)
t.Error("Bithumb GetOrders() Expected error")
}
}
@@ -127,7 +127,7 @@ func TestGetUserTransactions(t *testing.T) {
t.Parallel()
_, err := b.GetUserTransactions()
if err == nil {
t.Error("test failed - Bithumb GetUserTransactions() error", err)
t.Error("Bithumb GetUserTransactions() Expected error")
}
}
@@ -135,7 +135,7 @@ func TestPlaceTrade(t *testing.T) {
t.Parallel()
_, err := b.PlaceTrade("btc", "bid", 0, 0)
if err == nil {
t.Error("test failed - Bithumb PlaceTrade() error", err)
t.Error("Bithumb PlaceTrade() Expected error")
}
}
@@ -143,7 +143,7 @@ func TestGetOrderDetails(t *testing.T) {
t.Parallel()
_, err := b.GetOrderDetails("1337", "bid", "btc")
if err == nil {
t.Error("test failed - Bithumb GetOrderDetails() error", err)
t.Error("Bithumb GetOrderDetails() Expected error")
}
}
@@ -151,7 +151,7 @@ func TestCancelTrade(t *testing.T) {
t.Parallel()
_, err := b.CancelTrade("", "", "")
if err == nil {
t.Error("test failed - Bithumb CancelTrade() error", err)
t.Error("Bithumb CancelTrade() Expected error")
}
}
@@ -159,7 +159,7 @@ func TestWithdrawCrypto(t *testing.T) {
t.Parallel()
_, err := b.WithdrawCrypto("LQxiDhKU7idKiWQhx4ALKYkBx8xKEQVxJR", "", "ltc", 0)
if err == nil {
t.Error("test failed - Bithumb WithdrawCrypto() error", err)
t.Error("Bithumb WithdrawCrypto() Expected error")
}
}
@@ -170,7 +170,7 @@ func TestRequestKRWDepositDetails(t *testing.T) {
}
_, err := b.RequestKRWDepositDetails()
if err == nil {
t.Error("test failed - Bithumb RequestKRWDepositDetails() error", err)
t.Error("Bithumb RequestKRWDepositDetails() Expected error")
}
}
@@ -178,7 +178,7 @@ func TestRequestKRWWithdraw(t *testing.T) {
t.Parallel()
_, err := b.RequestKRWWithdraw("102_bank", "1337", 1000)
if err == nil {
t.Error("test failed - Bithumb RequestKRWWithdraw() error", err)
t.Error("Bithumb RequestKRWWithdraw() Expected error")
}
}
@@ -186,7 +186,7 @@ func TestMarketBuyOrder(t *testing.T) {
t.Parallel()
_, err := b.MarketBuyOrder("btc", 0)
if err == nil {
t.Error("test failed - Bithumb MarketBuyOrder() error", err)
t.Error("Bithumb MarketBuyOrder() Expected error")
}
}
@@ -194,7 +194,7 @@ func TestMarketSellOrder(t *testing.T) {
t.Parallel()
_, err := b.MarketSellOrder("btc", 0)
if err == nil {
t.Error("test failed - Bithumb MarketSellOrder() error", err)
t.Error("Bithumb MarketSellOrder() Expected error")
}
}
@@ -230,7 +230,7 @@ func TestGetFee(t *testing.T) {
// CryptocurrencyTradeFee Basic
if resp, err := b.GetFee(feeBuilder); resp != float64(0.0025) || err != nil {
t.Error(err)
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
}
// CryptocurrencyTradeFee High quantity
@@ -238,7 +238,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if resp, err := b.GetFee(feeBuilder); resp != float64(2500) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(2500), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(2500), resp)
t.Error(err)
}
@@ -246,7 +246,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if resp, err := b.GetFee(feeBuilder); resp != float64(0.0025) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.0025), resp)
t.Error(err)
}
@@ -254,7 +254,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
}
@@ -262,7 +262,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := b.GetFee(feeBuilder); resp != float64(0.001) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
t.Error(err)
}
@@ -270,7 +270,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
}
@@ -279,7 +279,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
}
@@ -288,7 +288,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.HKD
if resp, err := b.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
}
}
@@ -432,12 +432,12 @@ func TestGetAccountInfo(t *testing.T) {
if apiKey != "" || apiSecret != "" {
_, err := b.GetAccountInfo()
if err != nil {
t.Error("test failed - Bithumb GetAccountInfo() error", err)
t.Error("Bithumb GetAccountInfo() error", err)
}
} else {
_, err := b.GetAccountInfo()
if err == nil {
t.Error("test failed - Bithumb GetAccountInfo() error")
t.Error("Bithumb GetAccountInfo() Expected error")
}
}
}
@@ -450,7 +450,7 @@ func TestModifyOrder(t *testing.T) {
OrderSide: exchange.SellOrderSide,
CurrencyPair: curr})
if err == nil {
t.Error("Test Failed - ModifyOrder() error")
t.Error("ModifyOrder() Expected error")
}
}
@@ -534,12 +534,12 @@ func TestGetDepositAddress(t *testing.T) {
if apiKey != "" && apiSecret != "" {
_, err := b.GetDepositAddress(currency.BTC, "")
if err != nil {
t.Error("Test Failed - GetDepositAddress() error", err)
t.Error("GetDepositAddress() error", err)
}
} else {
_, err := b.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
t.Error("GetDepositAddress() error cannot be nil")
}
}
}

View File

@@ -15,6 +15,7 @@ import (
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
@@ -70,9 +71,27 @@ func (b *Bithumb) SetDefaults() {
b.Features = exchange.Features{
Supports: exchange.FeaturesSupported{
REST: true,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: true,
RESTCapabilities: protocol.Features{
TickerBatching: true,
TickerFetching: true,
TradeFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
AccountInfo: true,
CryptoWithdrawal: true,
FiatDeposit: true,
FiatWithdraw: true,
GetOrder: true,
CancelOrder: true,
SubmitOrder: true,
ModifyOrder: true,
DepositHistory: true,
WithdrawalHistory: true,
UserTradeHistory: true,
TradeFee: true,
FiatWithdrawalFee: true,
CryptoDepositFee: true,
CryptoWithdrawalFee: true,
},
WithdrawPermissions: exchange.AutoWithdrawCrypto |
exchange.AutoWithdrawFiat,