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

@@ -19,11 +19,11 @@ func TestMain(m *testing.M) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Binance load config error", err)
log.Fatal("Binance load config error", err)
}
binanceConfig, err := cfg.GetExchangeConfig("Binance")
if err != nil {
log.Fatal("Test Failed - Binance Setup() init error", err)
log.Fatal("Binance Setup() init error", err)
}
binanceConfig.API.AuthenticatedSupport = true
binanceConfig.API.Credentials.Key = apiKey
@@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
b.SetDefaults()
err = b.Setup(binanceConfig)
if err != nil {
log.Fatal("Test Failed - Binance setup error", err)
log.Fatal("Binance setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, b.GetName(), b.API.Endpoints.URL)
os.Exit(m.Run())

View File

@@ -22,11 +22,11 @@ func TestMain(m *testing.M) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
log.Fatal("Test Failed - Binance load config error", err)
log.Fatal("Binance load config error", err)
}
binanceConfig, err := cfg.GetExchangeConfig("Binance")
if err != nil {
log.Fatal("Test Failed - Binance Setup() init error", err)
log.Fatal("Binance Setup() init error", err)
}
b.SkipAuthCheck = true
binanceConfig.API.AuthenticatedSupport = true
@@ -35,12 +35,12 @@ func TestMain(m *testing.M) {
b.SetDefaults()
err = b.Setup(binanceConfig)
if err != nil {
log.Fatal("Test Failed - Binance setup error", err)
log.Fatal("Binance setup error", err)
}
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
if err != nil {
log.Fatalf("Test Failed - Mock server error %s", err)
log.Fatalf("Mock server error %s", err)
}
b.HTTPClient = newClient

View File

@@ -36,7 +36,7 @@ func TestFetchTradablePairs(t *testing.T) {
_, err := b.FetchTradablePairs(asset.Spot)
if err != nil {
t.Error("Test Failed - Binance FetchTradablePairs(asset asets.AssetType) error", err)
t.Error("Binance FetchTradablePairs(asset asets.AssetType) error", err)
}
}
@@ -49,7 +49,7 @@ func TestGetOrderBook(t *testing.T) {
})
if err != nil {
t.Error("Test Failed - Binance GetOrderBook() error", err)
t.Error("Binance GetOrderBook() error", err)
}
}
@@ -62,7 +62,7 @@ func TestGetRecentTrades(t *testing.T) {
})
if err != nil {
t.Error("Test Failed - Binance GetRecentTrades() error", err)
t.Error("Binance GetRecentTrades() error", err)
}
}
@@ -71,10 +71,10 @@ func TestGetHistoricalTrades(t *testing.T) {
_, err := b.GetHistoricalTrades("BTCUSDT", 5, 0)
if !mockTests && err == nil {
t.Error("Test Failed - Binance GetHistoricalTrades() expecting error")
t.Error("Binance GetHistoricalTrades() expecting error")
}
if mockTests && err == nil {
t.Error("Test Failed - Binance GetHistoricalTrades() error", err)
t.Error("Binance GetHistoricalTrades() error", err)
}
}
@@ -83,7 +83,7 @@ func TestGetAggregatedTrades(t *testing.T) {
_, err := b.GetAggregatedTrades("BTCUSDT", 5)
if err != nil {
t.Error("Test Failed - Binance GetAggregatedTrades() error", err)
t.Error("Binance GetAggregatedTrades() error", err)
}
}
@@ -96,7 +96,7 @@ func TestGetSpotKline(t *testing.T) {
Limit: 24,
})
if err != nil {
t.Error("Test Failed - Binance GetSpotKline() error", err)
t.Error("Binance GetSpotKline() error", err)
}
}
@@ -105,7 +105,7 @@ func TestGetAveragePrice(t *testing.T) {
_, err := b.GetAveragePrice("BTCUSDT")
if err != nil {
t.Error("Test Failed - Binance GetAveragePrice() error", err)
t.Error("Binance GetAveragePrice() error", err)
}
}
@@ -114,7 +114,7 @@ func TestGetPriceChangeStats(t *testing.T) {
_, err := b.GetPriceChangeStats("BTCUSDT")
if err != nil {
t.Error("Test Failed - Binance GetPriceChangeStats() error", err)
t.Error("Binance GetPriceChangeStats() error", err)
}
}
@@ -123,7 +123,7 @@ func TestGetTickers(t *testing.T) {
_, err := b.GetTickers()
if err != nil {
t.Error("Test Failed - Binance TestGetTickers error", err)
t.Error("Binance TestGetTickers error", err)
}
}
@@ -132,7 +132,7 @@ func TestGetLatestSpotPrice(t *testing.T) {
_, err := b.GetLatestSpotPrice("BTCUSDT")
if err != nil {
t.Error("Test Failed - Binance GetLatestSpotPrice() error", err)
t.Error("Binance GetLatestSpotPrice() error", err)
}
}
@@ -141,7 +141,7 @@ func TestGetBestPrice(t *testing.T) {
_, err := b.GetBestPrice("BTCUSDT")
if err != nil {
t.Error("Test Failed - Binance GetBestPrice() error", err)
t.Error("Binance GetBestPrice() error", err)
}
}
@@ -151,11 +151,11 @@ func TestQueryOrder(t *testing.T) {
_, err := b.QueryOrder("BTCUSDT", "", 1337)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - QueryOrder() error", err)
t.Error("QueryOrder() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - QueryOrder() expecting an error when no keys are set")
t.Error("QueryOrder() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock QueryOrder() error", err)
t.Error("Mock QueryOrder() error", err)
}
}
@@ -165,11 +165,11 @@ func TestOpenOrders(t *testing.T) {
_, err := b.OpenOrders("BTCUSDT")
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - OpenOrders() error", err)
t.Error("OpenOrders() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - OpenOrders() expecting an error when no keys are set")
t.Error("OpenOrders() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock OpenOrders() error", err)
t.Error("Mock OpenOrders() error", err)
}
}
@@ -179,11 +179,11 @@ func TestAllOrders(t *testing.T) {
_, err := b.AllOrders("BTCUSDT", "", "")
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - AllOrders() error", err)
t.Error("AllOrders() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - AllOrders() expecting an error when no keys are set")
t.Error("AllOrders() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock AllOrders() error", err)
t.Error("Mock AllOrders() error", err)
}
}
@@ -213,7 +213,7 @@ func TestGetFee(t *testing.T) {
// CryptocurrencyTradeFee Basic
if resp, err := b.GetFee(feeBuilder); resp != float64(0.1) || err != nil {
t.Error(err)
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
// CryptocurrencyTradeFee High quantity
@@ -221,7 +221,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if resp, err := b.GetFee(feeBuilder); resp != float64(100000) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(100000), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(100000), resp)
t.Error(err)
}
@@ -229,7 +229,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if resp, err := b.GetFee(feeBuilder); resp != float64(0.1) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.1), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.1), resp)
t.Error(err)
}
@@ -237,7 +237,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)
}
@@ -247,7 +247,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)
}
@@ -255,7 +255,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)
}
@@ -264,7 +264,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)
}
@@ -273,7 +273,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)
}
}
@@ -307,11 +307,11 @@ func TestGetActiveOrders(t *testing.T) {
_, err = b.GetActiveOrders(&getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - GetActiveOrders() error", err)
t.Error("GetActiveOrders() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - GetActiveOrders() expecting an error when no keys are set")
t.Error("GetActiveOrders() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock GetActiveOrders() error", err)
t.Error("Mock GetActiveOrders() error", err)
}
}
@@ -334,11 +334,11 @@ func TestGetOrderHistory(t *testing.T) {
_, err = b.GetOrderHistory(&getOrdersRequest)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - GetOrderHistory() error", err)
t.Error("GetOrderHistory() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - GetOrderHistory() expecting an error when no keys are set")
t.Error("GetOrderHistory() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock GetOrderHistory() error", err)
t.Error("Mock GetOrderHistory() error", err)
}
}
@@ -368,11 +368,11 @@ func TestSubmitOrder(t *testing.T) {
_, err := b.SubmitOrder(orderSubmission)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - SubmitOrder() error", err)
t.Error("SubmitOrder() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - SubmitOrder() expecting an error when no keys are set")
t.Error("SubmitOrder() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock SubmitOrder() error", err)
t.Error("Mock SubmitOrder() error", err)
}
}
@@ -393,11 +393,11 @@ func TestCancelExchangeOrder(t *testing.T) {
err := b.CancelOrder(orderCancellation)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - CancelExchangeOrder() error", err)
t.Error("CancelExchangeOrder() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - CancelExchangeOrder() expecting an error when no keys are set")
t.Error("CancelExchangeOrder() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock CancelExchangeOrder() error", err)
t.Error("Mock CancelExchangeOrder() error", err)
}
}
@@ -418,11 +418,11 @@ func TestCancelAllExchangeOrders(t *testing.T) {
_, err := b.CancelAllOrders(orderCancellation)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - CancelAllExchangeOrders() error", err)
t.Error("CancelAllExchangeOrders() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - CancelAllExchangeOrders() expecting an error when no keys are set")
t.Error("CancelAllExchangeOrders() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock CancelAllExchangeOrders() error", err)
t.Error("Mock CancelAllExchangeOrders() error", err)
}
}
@@ -432,11 +432,11 @@ func TestGetAccountInfo(t *testing.T) {
_, err := b.GetAccountInfo()
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - GetAccountInfo() error", err)
t.Error("GetAccountInfo() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - GetAccountInfo() expecting an error when no keys are set")
t.Error("GetAccountInfo() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock GetAccountInfo() error", err)
t.Error("Mock GetAccountInfo() error", err)
}
}
@@ -445,7 +445,7 @@ func TestModifyOrder(t *testing.T) {
_, err := b.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error cannot be nil")
t.Error("ModifyOrder() error cannot be nil")
}
}
@@ -468,11 +468,11 @@ func TestWithdraw(t *testing.T) {
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - Withdraw() error", err)
t.Error("Withdraw() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - Withdraw() expecting an error when no keys are set")
t.Error("Withdraw() expecting an error when no keys are set")
case mockTests && err != nil:
t.Error("Test Failed - Mock Withdraw() error", err)
t.Error("Mock Withdraw() error", err)
}
}
@@ -502,10 +502,10 @@ func TestGetDepositAddress(t *testing.T) {
_, err := b.GetDepositAddress(currency.BTC, "")
switch {
case areTestAPIKeysSet() && err != nil:
t.Error("Test Failed - GetDepositAddress() error", err)
t.Error("GetDepositAddress() error", err)
case !areTestAPIKeysSet() && err == nil && !mockTests:
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
t.Error("GetDepositAddress() error cannot be nil")
case mockTests && err != nil:
t.Error("Test Failed - Mock GetDepositAddress() error", err)
t.Error("Mock GetDepositAddress() error", err)
}
}

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"
@@ -71,9 +72,32 @@ func (b *Binance) SetDefaults() {
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: true,
RESTCapabilities: protocol.Features{
TickerBatching: true,
TickerFetching: true,
KlineFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
AccountInfo: true,
CryptoDeposit: true,
CryptoWithdrawal: true,
GetOrder: true,
GetOrders: true,
CancelOrders: true,
CancelOrder: true,
SubmitOrder: true,
DepositHistory: true,
WithdrawalHistory: true,
TradeFetching: true,
UserTradeHistory: true,
TradeFee: true,
CryptoWithdrawalFee: true,
},
WebsocketCapabilities: protocol.Features{
TradeFetching: true,
TickerFetching: true,
KlineFetching: true,
OrderbookFetching: true,
},
WithdrawPermissions: exchange.AutoWithdrawCrypto |
exchange.NoFiatWithdrawals,
@@ -92,10 +116,6 @@ func (b *Binance) SetDefaults() {
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
b.Websocket = wshandler.New()
b.API.Endpoints.WebsocketURL = binanceDefaultWebsocketURL
b.Websocket.Functionality = wshandler.WebsocketTradeDataSupported |
wshandler.WebsocketTickerSupported |
wshandler.WebsocketKlineSupported |
wshandler.WebsocketOrderbookSupported
b.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
b.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
b.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -123,6 +143,7 @@ func (b *Binance) Setup(exch *config.ExchangeConfig) error {
ExchangeName: exch.Name,
RunningURL: exch.API.Endpoints.WebsocketURL,
Connector: b.WsConnect,
Features: &b.Features.Supports.WebsocketCapabilities,
})
if err != nil {