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 - Gemini load config error", err)
log.Fatal("Gemini load config error", err)
}
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
if err != nil {
log.Fatal("Test Failed - Gemini Setup() init error", err)
log.Fatal("Gemini Setup() init error", err)
}
geminiConfig.API.AuthenticatedSupport = true
geminiConfig.API.Credentials.Key = apiKey
@@ -31,7 +31,7 @@ func TestMain(m *testing.M) {
g.SetDefaults()
err = g.Setup(geminiConfig)
if err != nil {
log.Fatal("Test Failed - Gemini setup error", err)
log.Fatal("Gemini setup error", err)
}
g.API.Endpoints.URL = geminiSandboxAPIURL
log.Printf(sharedtestvalues.LiveTesting, g.GetName(), g.API.Endpoints.URL)

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 - Gemini load config error", err)
log.Fatal("Gemini load config error", err)
}
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
if err != nil {
log.Fatal("Test Failed - Mock server error", err)
log.Fatal("Mock server error", err)
}
g.SkipAuthCheck = true
geminiConfig.API.AuthenticatedSupport = true
@@ -35,12 +35,12 @@ func TestMain(m *testing.M) {
g.SetDefaults()
err = g.Setup(geminiConfig)
if err != nil {
log.Fatal("Test Failed - Gemini setup error", err)
log.Fatal("Gemini 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)
}
g.HTTPClient = newClient

View File

@@ -30,7 +30,7 @@ func TestGetSymbols(t *testing.T) {
t.Parallel()
_, err := g.GetSymbols()
if err != nil {
t.Error("Test Failed - GetSymbols() error", err)
t.Error("GetSymbols() error", err)
}
}
@@ -38,11 +38,11 @@ func TestGetTicker(t *testing.T) {
t.Parallel()
_, err := g.GetTicker("BTCUSD")
if err != nil {
t.Error("Test Failed - GetTicker() error", err)
t.Error("GetTicker() error", err)
}
_, err = g.GetTicker("bla")
if err == nil {
t.Error("Test Failed - GetTicker() error", err)
t.Error("GetTicker() Expected error")
}
}
@@ -50,7 +50,7 @@ func TestGetOrderbook(t *testing.T) {
t.Parallel()
_, err := g.GetOrderbook(testCurrency, url.Values{})
if err != nil {
t.Error("Test Failed - GetOrderbook() error", err)
t.Error("GetOrderbook() error", err)
}
}
@@ -58,7 +58,7 @@ func TestGetTrades(t *testing.T) {
t.Parallel()
_, err := g.GetTrades(testCurrency, url.Values{})
if err != nil {
t.Error("Test Failed - GetTrades() error", err)
t.Error("GetTrades() error", err)
}
}
@@ -66,9 +66,9 @@ func TestGetNotionalVolume(t *testing.T) {
t.Parallel()
_, err := g.GetNotionalVolume()
if err != nil && mockTests {
t.Error("Test Failed - GetNotionalVolume() error", err)
t.Error("GetNotionalVolume() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetNotionalVolume() error cannot be nil")
t.Error("GetNotionalVolume() error cannot be nil")
}
}
@@ -76,7 +76,7 @@ func TestGetAuction(t *testing.T) {
t.Parallel()
_, err := g.GetAuction(testCurrency)
if err != nil {
t.Error("Test Failed - GetAuction() error", err)
t.Error("GetAuction() error", err)
}
}
@@ -84,7 +84,7 @@ func TestGetAuctionHistory(t *testing.T) {
t.Parallel()
_, err := g.GetAuctionHistory(testCurrency, url.Values{})
if err != nil {
t.Error("Test Failed - GetAuctionHistory() error", err)
t.Error("GetAuctionHistory() error", err)
}
}
@@ -92,9 +92,9 @@ func TestNewOrder(t *testing.T) {
t.Parallel()
_, err := g.NewOrder(testCurrency, 1, 9000, "buy", "exchange limit")
if err != nil && mockTests {
t.Error("Test Failed - NewOrder() error", err)
t.Error("NewOrder() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - NewOrder() error cannot be nil")
t.Error("NewOrder() error cannot be nil")
}
}
@@ -102,9 +102,9 @@ func TestCancelExistingOrder(t *testing.T) {
t.Parallel()
_, err := g.CancelExistingOrder(265555413)
if err != nil && mockTests {
t.Error("Test Failed - CancelExistingOrder() error", err)
t.Error("CancelExistingOrder() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - CancelExistingOrder() error cannot be nil")
t.Error("CancelExistingOrder() error cannot be nil")
}
}
@@ -112,9 +112,9 @@ func TestCancelExistingOrders(t *testing.T) {
t.Parallel()
_, err := g.CancelExistingOrders(false)
if err != nil && mockTests {
t.Error("Test Failed - CancelExistingOrders() error", err)
t.Error("CancelExistingOrders() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - CancelExistingOrders() error cannot be nil")
t.Error("CancelExistingOrders() error cannot be nil")
}
}
@@ -122,9 +122,9 @@ func TestGetOrderStatus(t *testing.T) {
t.Parallel()
_, err := g.GetOrderStatus(265563260)
if err != nil && mockTests {
t.Error("Test Failed - GetOrderStatus() error", err)
t.Error("GetOrderStatus() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetOrderStatus() error cannot be nil")
t.Error("GetOrderStatus() error cannot be nil")
}
}
@@ -132,9 +132,9 @@ func TestGetOrders(t *testing.T) {
t.Parallel()
_, err := g.GetOrders()
if err != nil && mockTests {
t.Error("Test Failed - GetOrders() error", err)
t.Error("GetOrders() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetOrders() error cannot be nil")
t.Error("GetOrders() error cannot be nil")
}
}
@@ -142,9 +142,9 @@ func TestGetTradeHistory(t *testing.T) {
t.Parallel()
_, err := g.GetTradeHistory(testCurrency, 0)
if err != nil && mockTests {
t.Error("Test Failed - GetTradeHistory() error", err)
t.Error("GetTradeHistory() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetTradeHistory() error cannot be nil")
t.Error("GetTradeHistory() error cannot be nil")
}
}
@@ -152,9 +152,9 @@ func TestGetTradeVolume(t *testing.T) {
t.Parallel()
_, err := g.GetTradeVolume()
if err != nil && mockTests {
t.Error("Test Failed - GetTradeVolume() error", err)
t.Error("GetTradeVolume() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetTradeVolume() error cannot be nil")
t.Error("GetTradeVolume() error cannot be nil")
}
}
@@ -162,9 +162,9 @@ func TestGetBalances(t *testing.T) {
t.Parallel()
_, err := g.GetBalances()
if err != nil && mockTests {
t.Error("Test Failed - GetBalances() error", err)
t.Error("GetBalances() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - GetBalances() error cannot be nil")
t.Error("GetBalances() error cannot be nil")
}
}
@@ -172,7 +172,7 @@ func TestGetCryptoDepositAddress(t *testing.T) {
t.Parallel()
_, err := g.GetCryptoDepositAddress("LOL123", "btc")
if err == nil {
t.Error("Test Failed - GetCryptoDepositAddress() error", err)
t.Error("GetCryptoDepositAddress() Expected error")
}
}
@@ -180,7 +180,7 @@ func TestWithdrawCrypto(t *testing.T) {
t.Parallel()
_, err := g.WithdrawCrypto("LOL123", "btc", 1)
if err == nil {
t.Error("Test Failed - WithdrawCrypto() error", err)
t.Error("WithdrawCrypto() Expected error")
}
}
@@ -188,9 +188,9 @@ func TestPostHeartbeat(t *testing.T) {
t.Parallel()
_, err := g.PostHeartbeat()
if err != nil && mockTests {
t.Error("Test Failed - PostHeartbeat() error", err)
t.Error("PostHeartbeat() error", err)
} else if err == nil && !mockTests {
t.Error("Test Failed - PostHeartbeat() error cannot be nil")
t.Error("PostHeartbeat() error cannot be nil")
}
}
@@ -234,7 +234,7 @@ func TestGetFee(t *testing.T) {
if areTestAPIKeysSet() || mockTests {
// CryptocurrencyTradeFee Basic
if resp, err := g.GetFee(feeBuilder); resp != float64(0.0035) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0.0035),
resp)
t.Error(err)
@@ -245,7 +245,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if resp, err := g.GetFee(feeBuilder); resp != float64(3500) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(3500),
resp)
t.Error(err)
@@ -255,7 +255,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if resp, err := g.GetFee(feeBuilder); resp != float64(0.001) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0.001),
resp)
t.Error(err)
@@ -265,7 +265,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -275,7 +275,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -286,7 +286,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Pair.Base = currency.NewCode("hello")
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -296,7 +296,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -306,7 +306,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -317,7 +317,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.USD
if resp, err := g.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f",
t.Errorf("GetFee() error. Expected: %f, Received: %f",
float64(0),
resp)
t.Error(err)
@@ -470,7 +470,7 @@ func TestModifyOrder(t *testing.T) {
t.Parallel()
_, err := g.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
t.Error("ModifyOrder() Expected error")
}
}
@@ -535,7 +535,7 @@ func TestGetDepositAddress(t *testing.T) {
t.Parallel()
_, err := g.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"
@@ -69,9 +70,28 @@ func (g *Gemini) SetDefaults() {
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: false,
RESTCapabilities: protocol.Features{
TickerFetching: true,
TradeFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
AccountInfo: true,
GetOrder: true,
CancelOrders: true,
CancelOrder: true,
SubmitOrder: true,
UserTradeHistory: true,
CryptoDeposit: true,
CryptoWithdrawal: true,
TradeFee: true,
FiatWithdrawalFee: true,
CryptoWithdrawalFee: true,
},
WebsocketCapabilities: protocol.Features{
OrderbookFetching: true,
TradeFetching: true,
AuthenticatedEndpoints: true,
MessageSequenceNumbers: true,
},
WithdrawPermissions: exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.AutoWithdrawCryptoWithSetup |
@@ -91,10 +111,6 @@ func (g *Gemini) SetDefaults() {
g.API.Endpoints.URL = g.API.Endpoints.URLDefault
g.API.Endpoints.WebsocketURL = geminiWebsocketEndpoint
g.Websocket = wshandler.New()
g.Websocket.Functionality = wshandler.WebsocketOrderbookSupported |
wshandler.WebsocketTradeDataSupported |
wshandler.WebsocketAuthenticatedEndpointsSupported |
wshandler.WebsocketSequenceNumberSupported
g.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
g.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
g.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -126,6 +142,7 @@ func (g *Gemini) Setup(exch *config.ExchangeConfig) error {
ExchangeName: exch.Name,
RunningURL: exch.API.Endpoints.WebsocketURL,
Connector: g.WsConnect,
Features: &g.Features.Supports.WebsocketCapabilities,
})
if err != nil {
return err