mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 15:10:59 +00:00
Merge branch 'master' into engine
This commit is contained in:
@@ -76,7 +76,7 @@ func TestGetTicker(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("Test Failed - Ticker GetTicker init error: %s", err)
|
||||
}
|
||||
if tickerPrice.Pair.String() != "BTCUSD" {
|
||||
if !tickerPrice.Pair.Equal(newPair) {
|
||||
t.Error("Test Failed - ticker tickerPrice.CurrencyPair value is incorrect")
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func TestGetTickerByExchange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFirstCurrencyExists(t *testing.T) {
|
||||
func TestBaseCurrencyExists(t *testing.T) {
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
@@ -155,15 +155,15 @@ func TestFirstCurrencyExists(t *testing.T) {
|
||||
alphaTicker := CreateNewTicker("alphapoint", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, alphaTicker)
|
||||
|
||||
if !FirstCurrencyExists("alphapoint", currency.BTC) {
|
||||
t.Error("Test Failed - FirstCurrencyExists1 value return is incorrect")
|
||||
if !BaseCurrencyExists("alphapoint", currency.BTC) {
|
||||
t.Error("Test Failed - BaseCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
if FirstCurrencyExists("alphapoint", currency.NewCode("CATS")) {
|
||||
t.Error("Test Failed - FirstCurrencyExists2 value return is incorrect")
|
||||
if BaseCurrencyExists("alphapoint", currency.NewCode("CATS")) {
|
||||
t.Error("Test Failed - BaseCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSecondCurrencyExists(t *testing.T) {
|
||||
func TestQuoteCurrencyExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
@@ -181,13 +181,13 @@ func TestSecondCurrencyExists(t *testing.T) {
|
||||
bitstampTicker := CreateNewTicker("bitstamp", &priceStruct, asset.Spot)
|
||||
Tickers = append(Tickers, bitstampTicker)
|
||||
|
||||
if !SecondCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - SecondCurrencyExists1 value return is incorrect")
|
||||
if !QuoteCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - QuoteCurrencyExists1 value return is incorrect")
|
||||
}
|
||||
|
||||
newPair.Quote = currency.NewCode("DOGS")
|
||||
if SecondCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - SecondCurrencyExists2 value return is incorrect")
|
||||
if QuoteCurrencyExists("bitstamp", newPair) {
|
||||
t.Error("Test Failed - QuoteCurrencyExists2 value return is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ 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()][asset.Spot.String()].Pair.String() != "BTCUSD" {
|
||||
if !newTicker.Price[currency.BTC.Upper().String()][currency.USD.Upper().String()][asset.Spot.String()].Pair.Equal(newPair) {
|
||||
t.Error("Test Failed - ticker newTicker.Price[BTC][USD].Pair.Pair().String() value is not expected 'BTCUSD'")
|
||||
}
|
||||
if reflect.TypeOf(newTicker.Price["BTC"]["USD"][asset.Spot.String()].Ask).String() != float64Type {
|
||||
@@ -251,7 +251,6 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
exchName := "bitstamp"
|
||||
newPair := currency.NewPairFromStrings("BTC", "USD")
|
||||
priceStruct := Price{
|
||||
Pair: newPair,
|
||||
Last: 1200,
|
||||
High: 1298,
|
||||
Low: 1148,
|
||||
@@ -261,37 +260,59 @@ func TestProcessTicker(t *testing.T) { // non-appending function to tickers
|
||||
PriceATH: 1337,
|
||||
}
|
||||
|
||||
err := ProcessTicker(exchName, &Price{}, asset.Spot)
|
||||
// test for empty pair
|
||||
err := ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err == nil {
|
||||
t.Fatal("empty pair should throw an err")
|
||||
}
|
||||
|
||||
// test for empty asset type
|
||||
priceStruct.Pair = newPair
|
||||
err = ProcessTicker(exchName, &priceStruct, "")
|
||||
if err == nil {
|
||||
t.Fatal("Test failed. ProcessTicker error cannot be nil")
|
||||
}
|
||||
|
||||
// now process a valid ticker
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
result, err := GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
|
||||
}
|
||||
|
||||
if result.Pair.String() != newPair.String() {
|
||||
if !result.Pair.Equal(newPair) {
|
||||
t.Fatal("Test failed. TestProcessTicker pair mismatch")
|
||||
}
|
||||
|
||||
secondPair := currency.NewPairFromStrings("BTC", "AUD")
|
||||
priceStruct.Pair = secondPair
|
||||
// now test for processing a pair with a different quote currency
|
||||
newPair = currency.NewPairFromStrings("BTC", "AUD")
|
||||
priceStruct.Pair = newPair
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
|
||||
result, err = GetTicker(exchName, secondPair, asset.Spot)
|
||||
result, err = GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
|
||||
}
|
||||
result, err = GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to return an existing ticker")
|
||||
}
|
||||
|
||||
// now test for processing a pair which has a different base currency
|
||||
newPair = currency.NewPairFromStrings("LTC", "AUD")
|
||||
priceStruct.Pair = newPair
|
||||
err = ProcessTicker(exchName, &priceStruct, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. ProcessTicker error", err)
|
||||
}
|
||||
result, err = GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to create and return a new ticker")
|
||||
}
|
||||
result, err = GetTicker(exchName, newPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal("Test failed. TestProcessTicker failed to return an existing ticker")
|
||||
|
||||
Reference in New Issue
Block a user