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

@@ -21,7 +21,7 @@ var b Bittrex
func TestSetDefaults(t *testing.T) {
b.SetDefaults()
if b.GetName() != "Bittrex" {
t.Error("Test Failed - Bittrex - SetDefaults() error")
t.Error("Bittrex - SetDefaults() error")
}
}
@@ -29,11 +29,11 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - Bittrex load config error", err)
t.Fatal("Bittrex load config error", err)
}
bConfig, err := cfg.GetExchangeConfig("Bittrex")
if err != nil {
t.Error("Test Failed - Bittrex Setup() init error")
t.Error("Bittrex Setup() init error")
}
bConfig.API.Credentials.Key = apiKey
bConfig.API.Credentials.Secret = apiSecret
@@ -41,12 +41,12 @@ func TestSetup(t *testing.T) {
err = b.Setup(bConfig)
if err != nil {
t.Fatal("Test Failed - Bittrex setup error", err)
t.Fatal("Bittrex setup error", err)
}
if !b.IsEnabled() || !b.API.AuthenticatedSupport ||
b.Verbose || len(b.BaseCurrencies) < 1 {
t.Error("Test Failed - Bittrex Setup values not set correctly")
t.Error("Bittrex Setup values not set correctly")
}
}
@@ -54,7 +54,7 @@ func TestGetMarkets(t *testing.T) {
t.Parallel()
_, err := b.GetMarkets()
if err != nil {
t.Errorf("Test Failed - Bittrex - GetMarkets() error: %s", err)
t.Errorf("Bittrex - GetMarkets() error: %s", err)
}
}
@@ -62,7 +62,7 @@ func TestGetCurrencies(t *testing.T) {
t.Parallel()
_, err := b.GetCurrencies()
if err != nil {
t.Errorf("Test Failed - Bittrex - GetCurrencies() error: %s", err)
t.Errorf("Bittrex - GetCurrencies() error: %s", err)
}
}
@@ -72,7 +72,7 @@ func TestGetTicker(t *testing.T) {
_, err := b.GetTicker(btc)
if err != nil {
t.Errorf("Test Failed - Bittrex - GetTicker() error: %s", err)
t.Errorf("Bittrex - GetTicker() error: %s", err)
}
}
@@ -80,7 +80,7 @@ func TestGetMarketSummaries(t *testing.T) {
t.Parallel()
_, err := b.GetMarketSummaries()
if err != nil {
t.Errorf("Test Failed - Bittrex - GetMarketSummaries() error: %s", err)
t.Errorf("Bittrex - GetMarketSummaries() error: %s", err)
}
}
@@ -90,7 +90,7 @@ func TestGetMarketSummary(t *testing.T) {
_, err := b.GetMarketSummary(pairOne)
if err != nil {
t.Errorf("Test Failed - Bittrex - GetMarketSummary() error: %s", err)
t.Errorf("Bittrex - GetMarketSummary() error: %s", err)
}
}
@@ -99,7 +99,7 @@ func TestGetOrderbook(t *testing.T) {
_, err := b.GetOrderbook("btc-ltc")
if err != nil {
t.Errorf("Test Failed - Bittrex - GetOrderbook() error: %s", err)
t.Errorf("Bittrex - GetOrderbook() error: %s", err)
}
}
@@ -108,7 +108,7 @@ func TestGetMarketHistory(t *testing.T) {
_, err := b.GetMarketHistory("btc-ltc")
if err != nil {
t.Errorf("Test Failed - Bittrex - GetMarketHistory() error: %s", err)
t.Errorf("Bittrex - GetMarketHistory() error: %s", err)
}
}
@@ -117,7 +117,7 @@ func TestPlaceBuyLimit(t *testing.T) {
_, err := b.PlaceBuyLimit("btc-ltc", 1, 1)
if err == nil {
t.Error("Test Failed - Bittrex - PlaceBuyLimit() error")
t.Error("Bittrex - PlaceBuyLimit() Expected error")
}
}
@@ -126,7 +126,7 @@ func TestPlaceSellLimit(t *testing.T) {
_, err := b.PlaceSellLimit("btc-ltc", 1, 1)
if err == nil {
t.Error("Test Failed - Bittrex - PlaceSellLimit() error")
t.Error("Bittrex - PlaceSellLimit() Expected error")
}
}
@@ -135,11 +135,11 @@ func TestGetOpenOrders(t *testing.T) {
_, err := b.GetOpenOrders("")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrder() error")
t.Error("Bittrex - GetOrder() Expected error")
}
_, err = b.GetOpenOrders("btc-ltc")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrder() error")
t.Error("Bittrex - GetOrder() Expected error")
}
}
@@ -148,7 +148,7 @@ func TestCancelExistingOrder(t *testing.T) {
_, err := b.CancelExistingOrder("blaaaaaaa")
if err == nil {
t.Error("Test Failed - Bittrex - CancelExistingOrder() error")
t.Error("Bittrex - CancelExistingOrder() Expected error")
}
}
@@ -157,7 +157,7 @@ func TestGetAccountBalances(t *testing.T) {
_, err := b.GetAccountBalances()
if err == nil {
t.Error("Test Failed - Bittrex - GetAccountBalances() error")
t.Error("Bittrex - GetAccountBalances() Expected error")
}
}
@@ -166,7 +166,7 @@ func TestGetAccountBalanceByCurrency(t *testing.T) {
_, err := b.GetAccountBalanceByCurrency("btc")
if err == nil {
t.Error("Test Failed - Bittrex - GetAccountBalanceByCurrency() error")
t.Error("Bittrex - GetAccountBalanceByCurrency() Expected error")
}
}
@@ -175,11 +175,11 @@ func TestGetOrder(t *testing.T) {
_, err := b.GetOrder("0cb4c4e4-bdc7-4e13-8c13-430e587d2cc1")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrder() error")
t.Error("Bittrex - GetOrder() Expected error")
}
_, err = b.GetOrder("")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrder() error")
t.Error("Bittrex - GetOrder() Expected error")
}
}
@@ -188,11 +188,11 @@ func TestGetOrderHistoryForCurrency(t *testing.T) {
_, err := b.GetOrderHistoryForCurrency("")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrderHistory() error")
t.Error("Bittrex - GetOrderHistory() Expected error")
}
_, err = b.GetOrderHistoryForCurrency("btc-ltc")
if err == nil {
t.Error("Test Failed - Bittrex - GetOrderHistory() error")
t.Error("Bittrex - GetOrderHistory() Expected error")
}
}
@@ -201,11 +201,11 @@ func TestGetwithdrawalHistory(t *testing.T) {
_, err := b.GetWithdrawalHistory("")
if err == nil {
t.Error("Test Failed - Bittrex - GetWithdrawalHistory() error")
t.Error("Bittrex - GetWithdrawalHistory() Expected error")
}
_, err = b.GetWithdrawalHistory("btc-ltc")
if err == nil {
t.Error("Test Failed - Bittrex - GetWithdrawalHistory() error")
t.Error("Bittrex - GetWithdrawalHistory() Expected error")
}
}
@@ -214,11 +214,11 @@ func TestGetDepositHistory(t *testing.T) {
_, err := b.GetDepositHistory("")
if err == nil {
t.Error("Test Failed - Bittrex - GetDepositHistory() error")
t.Error("Bittrex - GetDepositHistory() Expected error")
}
_, err = b.GetDepositHistory("btc-ltc")
if err == nil {
t.Error("Test Failed - Bittrex - GetDepositHistory() error")
t.Error("Bittrex - GetDepositHistory() Expected error")
}
}
@@ -255,7 +255,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
@@ -263,7 +263,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)
}
@@ -271,7 +271,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)
}
@@ -279,7 +279,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)
}
@@ -287,7 +287,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := b.GetFee(feeBuilder); resp != float64(0.0005) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.0005), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.0005), resp)
t.Error(err)
}
@@ -295,7 +295,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)
}
@@ -304,7 +304,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)
}
@@ -313,7 +313,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)
}
}
@@ -459,7 +459,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestModifyOrder(t *testing.T) {
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
t.Error("ModifyOrder() Expected error")
}
}
@@ -524,12 +524,12 @@ func TestGetDepositAddress(t *testing.T) {
if areTestAPIKeysSet() {
_, 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

@@ -13,6 +13,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"
@@ -69,9 +70,23 @@ func (b *Bittrex) SetDefaults() {
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: false,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: true,
RESTCapabilities: protocol.Features{
TickerBatching: true,
TickerFetching: true,
KlineFetching: true,
TradeFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
GetOrders: true,
CancelOrder: true,
SubmitOrder: true,
DepositHistory: true,
WithdrawalHistory: true,
UserTradeHistory: true,
CryptoDeposit: true,
CryptoWithdrawal: true,
TradeFee: true,
CryptoWithdrawalFee: true,
},
WithdrawPermissions: exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.NoFiatWithdrawals,