Fix ticker empty err and improve test/consistency for orderbook/ticke… (#317)

* Fix ticker empty err and improve test/consistency for orderbook/ticker pkgs
This commit is contained in:
Adrian Gallagher
2019-06-17 13:43:13 +10:00
committed by GitHub
parent 92d798ef2a
commit 67a58a10bd
4 changed files with 118 additions and 62 deletions

View File

@@ -8,11 +8,13 @@ import (
"github.com/thrasher-/gocryptotrader/currency"
)
// Const values for orderbook package
// const values for orderbook package
const (
ErrOrderbookForExchangeNotFound = "ticker for exchange does not exist"
ErrPrimaryCurrencyNotFound = "primary currency for orderbook not found"
ErrSecondaryCurrencyNotFound = "secondary currency for orderbook not found"
errExchangeOrderbookNotFound = "orderbook for exchange does not exist"
errPairNotSet = "orderbook currency pair not set"
errAssetTypeNotSet = "orderbook asset type not set"
errBaseCurrencyNotFound = "orderbook base currency not found"
errQuoteCurrencyNotFound = "orderbook quote currency not found"
Spot = "SPOT"
)
@@ -82,11 +84,11 @@ func Get(exchange string, p currency.Pair, orderbookType string) (Base, error) {
}
if !BaseCurrencyExists(exchange, p.Base) {
return Base{}, errors.New(ErrPrimaryCurrencyNotFound)
return Base{}, errors.New(errBaseCurrencyNotFound)
}
if !QuoteCurrencyExists(exchange, p) {
return Base{}, errors.New(ErrSecondaryCurrencyNotFound)
return Base{}, errors.New(errQuoteCurrencyNotFound)
}
return orderbook.Orderbook[p.Base.Item][p.Quote.Item][orderbookType], nil
@@ -101,7 +103,7 @@ func GetByExchange(exchange string) (*Orderbook, error) {
return &Orderbooks[x], nil
}
}
return nil, errors.New(ErrOrderbookForExchangeNotFound)
return nil, errors.New(errExchangeOrderbookNotFound)
}
// BaseCurrencyExists checks to see if the base currency of the orderbook map
@@ -156,11 +158,11 @@ func CreateNewOrderbook(exchangeName string, orderbookNew *Base, orderbookType s
// list
func (o *Base) Process() error {
if o.Pair.IsEmpty() {
return errors.New("orderbook currency pair not populated")
return errors.New(errPairNotSet)
}
if o.AssetType == "" {
return errors.New("orderbook asset type not set")
return errors.New(errAssetTypeNotSet)
}
if o.LastUpdated.IsZero() {