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

@@ -32,11 +32,11 @@ func TestSetup(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig("../../testdata/configtest.json", true)
if err != nil {
t.Fatal("Test Failed - coinbasepro load config error", err)
t.Fatal("coinbasepro load config error", err)
}
gdxConfig, err := cfg.GetExchangeConfig("CoinbasePro")
if err != nil {
t.Error("Test Failed - coinbasepro Setup() init error")
t.Error("coinbasepro Setup() init error")
}
gdxConfig.API.Credentials.Key = apiKey
gdxConfig.API.Credentials.Secret = apiSecret
@@ -45,56 +45,56 @@ func TestSetup(t *testing.T) {
gdxConfig.API.AuthenticatedWebsocketSupport = true
err = c.Setup(gdxConfig)
if err != nil {
t.Fatal("Test Failed - CoinbasePro setup error", err)
t.Fatal("CoinbasePro setup error", err)
}
}
func TestGetProducts(t *testing.T) {
_, err := c.GetProducts()
if err != nil {
t.Errorf("Test failed - Coinbase, GetProducts() Error: %s", err)
t.Errorf("Coinbase, GetProducts() Error: %s", err)
}
}
func TestGetTicker(t *testing.T) {
_, err := c.GetTicker("BTC-USD")
if err != nil {
t.Error("Test failed - GetTicker() error", err)
t.Error("GetTicker() error", err)
}
}
func TestGetTrades(t *testing.T) {
_, err := c.GetTrades("BTC-USD")
if err != nil {
t.Error("Test failed - GetTrades() error", err)
t.Error("GetTrades() error", err)
}
}
func TestGetHistoricRates(t *testing.T) {
_, err := c.GetHistoricRates("BTC-USD", 0, 0, 0)
if err != nil {
t.Error("Test failed - GetHistoricRates() error", err)
t.Error("GetHistoricRates() error", err)
}
}
func TestGetStats(t *testing.T) {
_, err := c.GetStats("BTC-USD")
if err != nil {
t.Error("Test failed - GetStats() error", err)
t.Error("GetStats() error", err)
}
}
func TestGetCurrencies(t *testing.T) {
_, err := c.GetCurrencies()
if err != nil {
t.Error("Test failed - GetCurrencies() error", err)
t.Error("GetCurrencies() error", err)
}
}
func TestGetServerTime(t *testing.T) {
_, err := c.GetServerTime()
if err != nil {
t.Error("Test failed - GetServerTime() error", err)
t.Error("GetServerTime() error", err)
}
}
@@ -104,7 +104,7 @@ func TestAuthRequests(t *testing.T) {
}
_, err := c.GetAccounts()
if err != nil {
t.Error("Test failed - GetAccounts() error", err)
t.Error("GetAccounts() error", err)
}
accountResponse, err := c.GetAccount("13371337-1337-1337-1337-133713371337")
if accountResponse.ID != "" {
@@ -173,11 +173,11 @@ func TestAuthRequests(t *testing.T) {
}
_, err = c.GetPayMethods()
if err != nil {
t.Error("Test failed - GetPayMethods() error", err)
t.Error("GetPayMethods() error", err)
}
_, err = c.GetCoinbaseAccounts()
if err != nil {
t.Error("Test failed - GetCoinbaseAccounts() error", err)
t.Error("GetCoinbaseAccounts() error", err)
}
}
@@ -215,7 +215,7 @@ func TestGetFee(t *testing.T) {
// CryptocurrencyTradeFee Basic
if resp, err := c.GetFee(feeBuilder); resp != float64(0.003) || err != nil {
t.Error(err)
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
// CryptocurrencyTradeFee High quantity
@@ -223,7 +223,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.Amount = 1000
feeBuilder.PurchasePrice = 1000
if resp, err := c.GetFee(feeBuilder); resp != float64(3000) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(3000), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(3000), resp)
t.Error(err)
}
@@ -231,7 +231,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.IsMaker = true
if resp, err := c.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.01), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.01), resp)
t.Error(err)
}
@@ -239,7 +239,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.PurchasePrice = -1000
if resp, err := c.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)
}
}
@@ -248,7 +248,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
if resp, err := c.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)
}
@@ -256,7 +256,7 @@ func TestGetFee(t *testing.T) {
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
if resp, err := c.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)
}
@@ -265,7 +265,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.FiatCurrency = currency.EUR
if resp, err := c.GetFee(feeBuilder); resp != float64(0.15) || 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)
}
@@ -274,7 +274,7 @@ func TestGetFee(t *testing.T) {
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.FiatCurrency = currency.USD
if resp, err := c.GetFee(feeBuilder); resp != float64(25) || 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)
}
}
@@ -290,7 +290,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
// lowercase
@@ -302,7 +302,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
// mixedCase
@@ -314,7 +314,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.003) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.003), resp)
}
// medium volume
@@ -326,7 +326,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.002) {
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)
}
// high volume
@@ -338,7 +338,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0.001) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0.001), resp)
}
// no match
@@ -350,7 +350,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, false); resp != float64(0) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
// taker
@@ -362,7 +362,7 @@ func TestCalculateTradingFee(t *testing.T) {
}
if resp := c.calculateTradingFee(volume, currency.BTC, currency.USD, "_", 1, 1, true); resp != float64(0) {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Errorf("GetFee() error. Expected: %f, Received: %f", float64(0), resp)
}
}
@@ -510,7 +510,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
func TestModifyOrder(t *testing.T) {
_, err := c.ModifyOrder(&exchange.ModifyOrder{})
if err == nil {
t.Error("Test failed - ModifyOrder() error")
t.Error("ModifyOrder() Expected error")
}
}
@@ -592,7 +592,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
func TestGetDepositAddress(t *testing.T) {
_, err := c.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() error", err)
t.Error("GetDepositAddress() error", err)
}
}

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"
@@ -71,9 +72,36 @@ func (c *CoinbasePro) SetDefaults() {
Supports: exchange.FeaturesSupported{
REST: true,
Websocket: true,
RESTCapabilities: exchange.ProtocolFeatures{
AutoPairUpdates: true,
TickerBatching: false,
RESTCapabilities: protocol.Features{
TickerFetching: true,
KlineFetching: true,
TradeFetching: true,
OrderbookFetching: true,
AutoPairUpdates: true,
AccountInfo: true,
GetOrder: true,
GetOrders: true,
CancelOrders: true,
CancelOrder: true,
SubmitOrder: true,
DepositHistory: true,
WithdrawalHistory: true,
UserTradeHistory: true,
CryptoDeposit: true,
CryptoWithdrawal: true,
FiatDeposit: true,
FiatWithdraw: true,
TradeFee: true,
FiatDepositFee: true,
FiatWithdrawalFee: true,
},
WebsocketCapabilities: protocol.Features{
TickerFetching: true,
OrderbookFetching: true,
Subscribe: true,
Unsubscribe: true,
AuthenticatedEndpoints: true,
MessageSequenceNumbers: true,
},
WithdrawPermissions: exchange.AutoWithdrawCryptoWithAPIPermission |
exchange.AutoWithdrawFiatWithAPIPermission,
@@ -92,12 +120,6 @@ func (c *CoinbasePro) SetDefaults() {
c.API.Endpoints.URL = c.API.Endpoints.URLDefault
c.API.Endpoints.WebsocketURL = coinbaseproWebsocketURL
c.Websocket = wshandler.New()
c.Websocket.Functionality = wshandler.WebsocketTickerSupported |
wshandler.WebsocketOrderbookSupported |
wshandler.WebsocketSubscribeSupported |
wshandler.WebsocketUnsubscribeSupported |
wshandler.WebsocketAuthenticatedEndpointsSupported |
wshandler.WebsocketSequenceNumberSupported
c.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
c.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
c.WebsocketOrderbookBufferLimit = exchange.DefaultWebsocketOrderbookBufferLimit
@@ -127,6 +149,7 @@ func (c *CoinbasePro) Setup(exch *config.ExchangeConfig) error {
Connector: c.WsConnect,
Subscriber: c.Subscribe,
UnSubscriber: c.Unsubscribe,
Features: &c.Features.Supports.WebsocketCapabilities,
})
if err != nil {
return err