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

@@ -34,18 +34,18 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatalf("Test Failed - Lbank Setup() init error:, %v", err)
t.Fatalf("Lbank Setup() init error:, %v", err)
}
lbankConfig, err := cfg.GetExchangeConfig("Lbank")
if err != nil {
t.Fatalf("Test Failed - Lbank Setup() init error: %v", err)
t.Fatalf("Lbank Setup() init error: %v", err)
}
lbankConfig.API.AuthenticatedSupport = true
lbankConfig.API.Credentials.Secret = testAPISecret
lbankConfig.API.Credentials.Key = testAPIKey
err = l.Setup(lbankConfig)
if err != nil {
t.Fatal("Test Failed - LBank setup error", err)
t.Fatal("LBank setup error", err)
}
setupRan = true
}
@@ -58,7 +58,7 @@ func TestGetTicker(t *testing.T) {
TestSetup(t)
_, err := l.GetTicker("btc_usdt")
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -66,7 +66,7 @@ func TestGetTickers(t *testing.T) {
TestSetup(t)
tickers, err := l.GetTickers()
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
if len(tickers) <= 1 {
t.Errorf("Expected multiple tickers, received %v", len(tickers))
@@ -77,7 +77,7 @@ func TestGetCurrencyPairs(t *testing.T) {
TestSetup(t)
_, err := l.GetCurrencyPairs()
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -97,11 +97,11 @@ func TestGetTrades(t *testing.T) {
TestSetup(t)
_, err := l.GetTrades("btc_usdt", "600", fmt.Sprintf("%v", time.Now().Unix()))
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
a, err := l.GetTrades("btc_usdt", "600", "0")
if len(a) != 600 && err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -109,7 +109,7 @@ func TestGetKlines(t *testing.T) {
TestSetup(t)
_, err := l.GetKlines("btc_usdt", "600", "minute1", fmt.Sprintf("%v", time.Now().Unix()))
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -145,15 +145,15 @@ func TestCreateOrder(t *testing.T) {
cp := currency.NewPairWithDelimiter(currency.BTC.String(), currency.USDT.String(), "_")
_, err := l.CreateOrder(cp.Lower().String(), "what", 1231, 12314)
if err == nil {
t.Error("Test Failed - CreateOrder error cannot be nil")
t.Error("CreateOrder error cannot be nil")
}
_, err = l.CreateOrder(cp.Lower().String(), "buy", 0, 0)
if err == nil {
t.Error("Test Failed - CreateOrder error cannot be nil")
t.Error("CreateOrder error cannot be nil")
}
_, err = l.CreateOrder(cp.Lower().String(), "sell", 1231, 0)
if err == nil {
t.Error("Test Failed - CreateOrder error cannot be nil")
t.Error("CreateOrder error cannot be nil")
}
_, err = l.CreateOrder(cp.Lower().String(), "buy", 58, 681)
if err != nil {
@@ -193,7 +193,7 @@ func TestQueryOrderHistory(t *testing.T) {
cp := currency.NewPairWithDelimiter(currency.BTC.String(), currency.USDT.String(), "_")
_, err := l.QueryOrderHistory(cp.Lower().String(), "1", "100")
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -289,7 +289,7 @@ func TestLoadPrivKey(t *testing.T) {
l.API.Credentials.Secret = "errortest"
err = l.loadPrivKey()
if err == nil {
t.Errorf("expected error due to pemblock nil, got err: %v", err)
t.Errorf("Expected error due to pemblock nil")
}
}
@@ -302,7 +302,7 @@ func TestSign(t *testing.T) {
l.loadPrivKey()
_, err := l.sign("hello123")
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -343,7 +343,7 @@ func TestCancelOrder(t *testing.T) {
a.OrderID = "24f7ce27-af1d-4dca-a8c1-ef1cbeec1b23"
err := l.CancelOrder(&a)
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -354,7 +354,7 @@ func TestGetOrderInfo(t *testing.T) {
}
_, err := l.GetOrderInfo("9ead39f5-701a-400b-b635-d7349eb0f6b")
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -365,7 +365,7 @@ func TestGetAllOpenOrderID(t *testing.T) {
}
_, err := l.getAllOpenOrderID()
if err != nil {
t.Errorf("test failed: %v", err)
t.Errorf("%v", err)
}
}
@@ -378,7 +378,7 @@ func TestGetFeeByType(t *testing.T) {
input.Pair = cp
a, err := l.GetFeeByType(&input)
if err != nil {
t.Errorf("test failed. couldnt get fee: %v", err)
t.Errorf("couldnt get fee: %v", err)
}
if a != 0.0005 {
t.Errorf("testGetFeeByType failed. Expected: 0.0005, Received: %v", a)

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"
@@ -67,9 +68,23 @@ func (l *Lbank) SetDefaults() {
l.Features = exchange.Features{
Supports: exchange.FeaturesSupported{
REST: 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,
CancelOrder: true,
SubmitOrder: true,
WithdrawalHistory: true,
UserTradeHistory: true,
CryptoWithdrawal: true,
TradeFee: true,
CryptoWithdrawalFee: true,
},
WithdrawPermissions: exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.NoFiatWithdrawals,