mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-07 15:11:03 +00:00
Asset update to fix minor stutter (#316)
This commit is contained in:
committed by
Adrian Gallagher
parent
b901c4b670
commit
20c24601fb
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// Const values for the ticker package
|
||||
@@ -44,7 +44,7 @@ type Ticker struct {
|
||||
}
|
||||
|
||||
// PriceToString returns the string version of a stored price field
|
||||
func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType assets.AssetType) string {
|
||||
func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType asset.Item) string {
|
||||
priceType = strings.ToLower(priceType)
|
||||
|
||||
switch priceType {
|
||||
@@ -68,7 +68,7 @@ func (t *Ticker) PriceToString(p currency.Pair, priceType string, tickerType ass
|
||||
}
|
||||
|
||||
// GetTicker checks and returns a requested ticker if it exists
|
||||
func GetTicker(exchange string, p currency.Pair, tickerType assets.AssetType) (Price, error) {
|
||||
func GetTicker(exchange string, p currency.Pair, tickerType asset.Item) (Price, error) {
|
||||
ticker, err := GetTickerByExchange(exchange)
|
||||
if err != nil {
|
||||
return Price{}, err
|
||||
@@ -130,7 +130,7 @@ func SecondCurrencyExists(exchange string, p currency.Pair) bool {
|
||||
}
|
||||
|
||||
// CreateNewTicker creates a new Ticker
|
||||
func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType assets.AssetType) Ticker {
|
||||
func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType asset.Item) Ticker {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
ticker := Ticker{}
|
||||
@@ -147,7 +147,7 @@ func CreateNewTicker(exchangeName string, tickerNew *Price, tickerType assets.As
|
||||
|
||||
// ProcessTicker processes incoming tickers, creating or updating the Tickers
|
||||
// list
|
||||
func ProcessTicker(exchangeName string, tickerNew *Price, tickerType assets.AssetType) error {
|
||||
func ProcessTicker(exchangeName string, tickerNew *Price, tickerType asset.Item) error {
|
||||
if tickerNew.Pair.String() == "" {
|
||||
return errors.New("")
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
log "github.com/thrasher-/gocryptotrader/logger"
|
||||
)
|
||||
|
||||
@@ -26,30 +26,30 @@ func TestPriceToString(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
|
||||
if newTicker.PriceToString(newPair, "last", assets.AssetTypeSpot) != "1200" {
|
||||
if newTicker.PriceToString(newPair, "last", asset.Spot) != "1200" {
|
||||
t.Error("Test Failed - ticker PriceToString last value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "high", assets.AssetTypeSpot) != "1298" {
|
||||
if newTicker.PriceToString(newPair, "high", asset.Spot) != "1298" {
|
||||
t.Error("Test Failed - ticker PriceToString high value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "low", assets.AssetTypeSpot) != "1148" {
|
||||
if newTicker.PriceToString(newPair, "low", asset.Spot) != "1148" {
|
||||
t.Error("Test Failed - ticker PriceToString low value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "bid", assets.AssetTypeSpot) != "1195" {
|
||||
if newTicker.PriceToString(newPair, "bid", asset.Spot) != "1195" {
|
||||
t.Error("Test Failed - ticker PriceToString bid value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ask", assets.AssetTypeSpot) != "1220" {
|
||||
if newTicker.PriceToString(newPair, "ask", asset.Spot) != "1220" {
|
||||
t.Error("Test Failed - ticker PriceToString ask value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "volume", assets.AssetTypeSpot) != "5" {
|
||||
if newTicker.PriceToString(newPair, "volume", asset.Spot) != "5" {
|
||||
t.Error("Test Failed - ticker PriceToString volume value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "ath", assets.AssetTypeSpot) != "1337" {
|
||||
if newTicker.PriceToString(newPair, "ath", asset.Spot) != "1337" {
|
||||
t.Error("Test Failed - ticker PriceToString ath value is incorrect")
|
||||
}
|
||||
if newTicker.PriceToString(newPair, "obtuse", assets.AssetTypeSpot) != "" {
|
||||
if newTicker.PriceToString(newPair, "obtuse", asset.Spot) != "" {
|
||||
t.Error("Test Failed - ticker PriceToString obtuse value is incorrect")
|
||||
}
|
||||
}
|
||||
@@ -67,12 +67,12 @@ func TestGetTicker(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
err := ProcessTicker("bitfinex", &priceStruct, assets.AssetTypeSpot)
|
||||
err := ProcessTicker("bitfinex", &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
tickerPrice, err := GetTicker("bitfinex", newPair, assets.AssetTypeSpot)
|
||||
tickerPrice, err := GetTicker("bitfinex", newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
|
||||
}
|
||||
@@ -80,19 +80,19 @@ func TestGetTicker(t *testing.T) {
|
||||
t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect")
|
||||
}
|
||||
|
||||
_, err = GetTicker("blah", newPair, assets.AssetTypeSpot)
|
||||
_, err = GetTicker("blah", newPair, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("Test Failed. TestGetTicker returned nil error on invalid exchange")
|
||||
}
|
||||
|
||||
newPair.Base = currency.ETH
|
||||
_, err = GetTicker("bitfinex", newPair, assets.AssetTypeSpot)
|
||||
_, err = GetTicker("bitfinex", newPair, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("Test Failed. TestGetTicker returned ticker for invalid first currency")
|
||||
}
|
||||
|
||||
btcltcPair := currency.NewPairFromStrings("BTC", "LTC")
|
||||
_, err = GetTicker("bitfinex", btcltcPair, assets.AssetTypeSpot)
|
||||
_, err = GetTicker("bitfinex", btcltcPair, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("Test Failed. TestGetTicker returned ticker for invalid second currency")
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func TestGetTickerByExchange(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
anxTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
|
||||
anxTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, anxTicker)
|
||||
|
||||
tickerPtr, err := GetTickerByExchange("ANX")
|
||||
@@ -152,7 +152,7 @@ func TestFirstCurrencyExists(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, assets.AssetTypeSpot)
|
||||
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, alphaTicker)
|
||||
|
||||
if !FirstCurrencyExists("alphapoint", currency.BTC) {
|
||||
@@ -178,7 +178,7 @@ func TestSecondCurrencyExists(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, assets.AssetTypeSpot)
|
||||
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, bitstampTicker)
|
||||
|
||||
if !SecondCurrencyExists("bitstamp", newPair) {
|
||||
@@ -205,7 +205,7 @@ func TestCreateNewTicker(t *testing.T) {
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, assets.AssetTypeSpot)
|
||||
newTicker := CreateNewTicker("ANX", &priceStruct, asset.Spot)
|
||||
|
||||
if reflect.ValueOf(newTicker).NumField() != 2 {
|
||||
t.Error("Test Failed - ticker CreateNewTicker struct change/or updated")
|
||||
@@ -217,31 +217,31 @@ func TestCreateNewTicker(t *testing.T) {
|
||||
t.Error("Test Failed - ticker CreateNewTicker.ExchangeName value is not ANX")
|
||||
}
|
||||
|
||||
if newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][assets.AssetTypeSpot.String()].Pair.String() != "BTCUSD" {
|
||||
if newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][asset.Spot.String()].Pair.String() != "BTCUSD" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Ask).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Ask).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Ask value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Bid).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Bid).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Bid value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Pair).String() != "currency.Pair" {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Pair).String() != "currency.Pair" {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].CurrencyPair value is not a currency.Pair")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].High).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].High).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].High value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Last).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Last).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Last value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Low).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Low).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Low value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].PriceATH).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].PriceATH).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].PriceATH value is not a float64")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][assets.AssetTypeSpot.String()].Volume).String() != float64Type {
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Volume).String() != float64Type {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Volume value is not a float64")
|
||||
}
|
||||
}
|
||||
@@ -261,17 +261,17 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
err := ProcessTicker(exchName, &Price{}, assets.AssetTypeSpot)
|
||||
err := ProcessTicker(exchName, &Price{}, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("Test failed. ProcessTicker error cannot be nil")
|
||||
}
|
||||
|
||||
err = ProcessTicker(exchName, &priceStruct, assets.AssetTypeSpot)
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
result, err := GetTicker(exchName, newPair, assets.AssetTypeSpot)
|
||||
result, err := GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
|
||||
}
|
||||
@@ -282,17 +282,17 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
|
||||
secondPair := currency.NewPairFromStrings("BTC", "AUD")
|
||||
priceStruct.Pair = secondPair
|
||||
err = ProcessTicker(exchName, &priceStruct, assets.AssetTypeSpot)
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
result, err = GetTicker(exchName, secondPair, assets.AssetTypeSpot)
|
||||
result, err = GetTicker(exchName, secondPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
|
||||
}
|
||||
|
||||
result, err = GetTicker(exchName, newPair, assets.AssetTypeSpot)
|
||||
result, err = GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to return an existing ticker")
|
||||
}
|
||||
@@ -328,7 +328,7 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
}
|
||||
|
||||
sm.Lock()
|
||||
err = ProcessTicker(newName, &tp, assets.AssetTypeSpot)
|
||||
err = ProcessTicker(newName, &tp, asset.Spot)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
catastrophicFailure = true
|
||||
@@ -351,7 +351,7 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
wg.Add(1)
|
||||
fatalErr := false
|
||||
go func(test quick) {
|
||||
result, err := GetTicker(test.Name, test.P, assets.AssetTypeSpot)
|
||||
result, err := GetTicker(test.Name, test.P, asset.Spot)
|
||||
if err != nil {
|
||||
fatalErr = true
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user