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

@@ -40,11 +40,11 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Huobi load config error", err)
log.Fatal("Huobi load config error", err)
}
hConfig, err := cfg.GetExchangeConfig("Huobi")
if err != nil {
t.Error("Test Failed - Huobi Setup() init error")
t.Error("Huobi Setup() init error")
}
hConfig.API.AuthenticatedSupport = true
hConfig.API.AuthenticatedWebsocketSupport = true
@@ -53,7 +53,7 @@ func TestSetup(t *testing.T) {
err = h.Setup(hConfig)
if err != nil {
t.Fatal("Test Failed - Huobi setup error", err)
t.Fatal("Huobi setup error", err)
}
}
@@ -105,7 +105,7 @@ func TestGetSpotKline(t *testing.T) {
Size: 0,
})
if err != nil {
t.Errorf("Test failed - Huobi TestGetSpotKline: %s", err)
t.Errorf("Huobi TestGetSpotKline: %s", err)
}
}
@@ -113,7 +113,7 @@ func TestGetMarketDetailMerged(t *testing.T) {
t.Parallel()
_, err := h.GetMarketDetailMerged(testSymbol)
if err != nil {
t.Errorf("Test failed - Huobi TestGetMarketDetailMerged: %s", err)
t.Errorf("Huobi TestGetMarketDetailMerged: %s", err)
}
}
@@ -125,7 +125,7 @@ func TestGetDepth(t *testing.T) {
})
if err != nil {
t.Errorf("Test failed - Huobi TestGetDepth: %s", err)
t.Errorf("Huobi TestGetDepth: %s", err)
}
}
@@ -133,7 +133,7 @@ func TestGetTrades(t *testing.T) {
t.Parallel()
_, err := h.GetTrades(testSymbol)
if err != nil {
t.Errorf("Test failed - Huobi TestGetTrades: %s", err)
t.Errorf("Huobi TestGetTrades: %s", err)
}
}
@@ -141,7 +141,7 @@ func TestGetLatestSpotPrice(t *testing.T) {
t.Parallel()
_, err := h.GetLatestSpotPrice(testSymbol)
if err != nil {
t.Errorf("Test failed - Huobi GetLatestSpotPrice: %s", err)
t.Errorf("Huobi GetLatestSpotPrice: %s", err)
}
}
@@ -149,7 +149,7 @@ func TestGetTradeHistory(t *testing.T) {
t.Parallel()
_, err := h.GetTradeHistory(testSymbol, "50")
if err != nil {
t.Errorf("Test failed - Huobi TestGetTradeHistory: %s", err)
t.Errorf("Huobi TestGetTradeHistory: %s", err)
}
}
@@ -157,7 +157,7 @@ func TestGetMarketDetail(t *testing.T) {
t.Parallel()
_, err := h.GetMarketDetail(testSymbol)
if err != nil {
t.Errorf("Test failed - Huobi TestGetTradeHistory: %s", err)
t.Errorf("Huobi TestGetTradeHistory: %s", err)
}
}
@@ -165,7 +165,7 @@ func TestGetSymbols(t *testing.T) {
t.Parallel()
_, err := h.GetSymbols()
if err != nil {
t.Errorf("Test failed - Huobi TestGetSymbols: %s", err)
t.Errorf("Huobi TestGetSymbols: %s", err)
}
}
@@ -173,7 +173,7 @@ func TestGetCurrencies(t *testing.T) {
t.Parallel()
_, err := h.GetCurrencies()
if err != nil {
t.Errorf("Test failed - Huobi TestGetCurrencies: %s", err)
t.Errorf("Huobi TestGetCurrencies: %s", err)
}
}
@@ -188,7 +188,7 @@ func TestGetTimestamp(t *testing.T) {
t.Parallel()
_, err := h.GetTimestamp()
if err != nil {
t.Errorf("Test failed - Huobi TestGetTimestamp: %s", err)
t.Errorf("Huobi TestGetTimestamp: %s", err)
}
}
@@ -201,7 +201,7 @@ func TestGetAccounts(t *testing.T) {
_, err := h.GetAccounts()
if err != nil {
t.Errorf("Test failed - Huobi GetAccounts: %s", err)
t.Errorf("Huobi GetAccounts: %s", err)
}
}
@@ -214,13 +214,13 @@ func TestGetAccountBalance(t *testing.T) {
result, err := h.GetAccounts()
if err != nil {
t.Errorf("Test failed - Huobi GetAccounts: %s", err)
t.Errorf("Huobi GetAccounts: %s", err)
}
userID := strconv.FormatInt(result[0].ID, 10)
_, err = h.GetAccountBalance(userID)
if err != nil {
t.Errorf("Test failed - Huobi GetAccountBalance: %s", err)
t.Errorf("Huobi GetAccountBalance: %s", err)
}
}
@@ -233,7 +233,7 @@ func TestGetAggregatedBalance(t *testing.T) {
_, err := h.GetAggregatedBalance()
if err != nil {
t.Errorf("Test failed - Huobi GetAggregatedBalance: %s", err)
t.Errorf("Huobi GetAggregatedBalance: %s", err)
}
}
@@ -254,7 +254,7 @@ func TestSpotNewOrder(t *testing.T) {
_, err := h.SpotNewOrder(arg)
if err != nil {
t.Errorf("Test failed - Huobi SpotNewOrder: %s", err)
t.Errorf("Huobi SpotNewOrder: %s", err)
}
}
@@ -263,7 +263,7 @@ func TestCancelExistingOrder(t *testing.T) {
_, err := h.CancelExistingOrder(1337)
if err == nil {
t.Error("Test failed - Huobi TestCancelExistingOrder: Invalid orderID returned true")
t.Error("Huobi TestCancelExistingOrder Expected error")
}
}
@@ -272,7 +272,7 @@ func TestGetOrder(t *testing.T) {
_, err := h.GetOrder(1337)
if err == nil {
t.Error("Test failed - Huobi TestCancelOrder: Invalid orderID returned true")
t.Error("Huobi TestCancelOrder Expected error")
}
}
@@ -285,7 +285,7 @@ func TestGetMarginLoanOrders(t *testing.T) {
_, err := h.GetMarginLoanOrders(testSymbol, "", "", "", "", "", "", "")
if err != nil {
t.Errorf("Test failed - Huobi TestGetMarginLoanOrders: %s", err)
t.Errorf("Huobi TestGetMarginLoanOrders: %s", err)
}
}
@@ -298,7 +298,7 @@ func TestGetMarginAccountBalance(t *testing.T) {
_, err := h.GetMarginAccountBalance(testSymbol)
if err != nil {
t.Errorf("Test failed - Huobi TestGetMarginAccountBalance: %s", err)
t.Errorf("Huobi TestGetMarginAccountBalance: %s", err)
}
}
@@ -307,7 +307,7 @@ func TestCancelWithdraw(t *testing.T) {
_, err := h.CancelWithdraw(1337)
if err == nil {
t.Error("Test failed - Huobi TestCancelWithdraw: Invalid withdraw-ID was valid")
t.Error("Huobi TestCancelWithdraw Expected error")
}
}
@@ -317,23 +317,23 @@ func TestPEMLoadAndSign(t *testing.T) {
pemKey := strings.NewReader(h.API.Credentials.PEMKey)
pemBytes, err := ioutil.ReadAll(pemKey)
if err != nil {
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to ioutil.ReadAll PEM key: %s", err)
t.Fatalf("TestPEMLoadAndSign Unable to ioutil.ReadAll PEM key: %s", err)
}
block, _ := pem.Decode(pemBytes)
if block == nil {
t.Fatalf("Test Failed. TestPEMLoadAndSign Block is nil")
t.Fatalf("TestPEMLoadAndSign Block is nil")
}
x509Encoded := block.Bytes
privKey, err := x509.ParseECPrivateKey(x509Encoded)
if err != nil {
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to ParseECPrivKey: %s", err)
t.Fatalf("TestPEMLoadAndSign Unable to ParseECPrivKey: %s", err)
}
_, _, err = ecdsa.Sign(rand.Reader, privKey, crypto.GetSHA256([]byte("test")))
if err != nil {
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to sign: %s", err)
t.Fatalf("TestPEMLoadAndSign Unable to sign: %s", err)
}
}
@@ -371,7 +371,7 @@ func TestGetFee(t *testing.T) {
// CryptocurrencyTradeFee Basic
if resp, err := h.GetFee(feeBuilder); resp != float64(0.002) || err != nil {
t.Error(err)
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
}
// CryptocurrencyTradeFee High quantity
@@ -379,7 +379,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if resp, err := h.GetFee(feeBuilder); resp != float64(2000) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(2000), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(2000), resp)
t.Error(err)
}
@@ -387,7 +387,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if resp, err := h.GetFee(feeBuilder); resp != float64(0.002) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
t.Error(err)
}
@@ -395,14 +395,14 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if resp, err := h.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)
}
// CryptocurrencyWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := h.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)
}
@@ -411,7 +411,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Pair.Base = currency.NewCode("hello")
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := h.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)
}
@@ -419,7 +419,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
if resp, err := h.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)
}
@@ -427,7 +427,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
if resp, err := h.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)
}
@@ -436,7 +436,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.USD
if resp, err := h.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)
}
}
@@ -586,12 +586,12 @@ func TestGetAccountInfo(t *testing.T) {
if apiKey == "" || apiSecret == "" {
_, err := h.GetAccountInfo()
if err == nil {
t.Error("Test Failed - GetAccountInfo() error")
t.Error("GetAccountInfo() Expected error")
}
} else {
_, err := h.GetAccountInfo()
if err != nil {
t.Error("Test Failed - GetAccountInfo() error", err)
t.Error("GetAccountInfo() error", err)
}
}
}
@@ -599,7 +599,7 @@ func TestGetAccountInfo(t *testing.T) {
func TestModifyOrder(t *testing.T) {
_, err := h.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
t.Error("ModifyOrder() Expected error")
}
}
@@ -661,7 +661,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
_, err := h.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
t.Error("GetDepositAddress() error cannot be nil")
}
}

View File

@@ -14,6 +14,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,31 @@ func (h *HUOBI) SetDefaults() {
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: true,
RESTCapabilities: protocol.Features{
TickerBatching: true,
TickerFetching: true,
KlineFetching: true,
TradeFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
AccountInfo: true,
GetOrder: true,
GetOrders: true,
CancelOrders: true,
CancelOrder: true,
SubmitOrder: true,
CryptoWithdrawal: true,
TradeFee: true,
},
WebsocketCapabilities: protocol.Features{
KlineFetching: true,
OrderbookFetching: true,
TradeFetching: true,
Subscribe: true,
Unsubscribe: true,
AuthenticatedEndpoints: true,
AccountInfo: true,
MessageCorrelation: true,
},
WithdrawPermissions: exchange.AutoWithdrawCryptoWithSetup |
exchange.NoFiatWithdrawals,
@@ -91,14 +114,6 @@ func (h *HUOBI) SetDefaults() {
h.API.Endpoints.URL = h.API.Endpoints.URLDefault
h.API.Endpoints.WebsocketURL = wsMarketURL
h.Websocket = wshandler.New()
h.Websocket.Functionality = wshandler.WebsocketKlineSupported |
wshandler.WebsocketOrderbookSupported |
wshandler.WebsocketTradeDataSupported |
wshandler.WebsocketSubscribeSupported |
wshandler.WebsocketUnsubscribeSupported |
wshandler.WebsocketAuthenticatedEndpointsSupported |
wshandler.WebsocketAccountDataSupported |
wshandler.WebsocketMessageCorrelationSupported
h.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
h.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
h.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -131,6 +146,7 @@ func (h *HUOBI) Setup(exch *config.ExchangeConfig) error {
Connector: h.WsConnect,
Subscriber: h.Subscribe,
UnSubscriber: h.Unsubscribe,
Features: &h.Features.Supports.WebsocketCapabilities,
})
if err != nil {
return err