mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* Speeds up tests * Reduces time.Sleeps, lowers CreateTestBot complexity. Breaks things * Removal of unecessary config reads. Parallel tests. Lower times * Speeds up recent trades results * mini update * zoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooom * Removes the dupes * Lint * post cherrypick * Fix rare kraken data race * Fixes banking global issues. Fixes postgres trades * rmline for appveyor test * Expands timeout in event that channel is closed before send * Fix data race * No rows, no bows and definitely no shows * Removes parallel from createsnapshot tests * Extends timedmutext test a smidge. Exchange fatality * Shorter end timeframe and bigger candle
84 lines
2.5 KiB
Go
84 lines
2.5 KiB
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
|
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/engine"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
)
|
|
|
|
const testExchange = "binance"
|
|
|
|
func TestLoadCandles(t *testing.T) {
|
|
t.Parallel()
|
|
em := engine.SetupExchangeManager()
|
|
exch, err := em.NewExchangeByName(testExchange)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
exch.SetDefaults()
|
|
cp := currency.NewPair(currency.BTC, currency.USDT)
|
|
b := exch.GetBase()
|
|
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
|
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
|
Available: currency.Pairs{cp},
|
|
Enabled: currency.Pairs{cp},
|
|
AssetEnabled: convert.BoolPtr(true),
|
|
ConfigFormat: ¤cy.PairFormat{Uppercase: true},
|
|
RequestFormat: ¤cy.PairFormat{Uppercase: true}}
|
|
tt1 := time.Now().Add(-time.Minute).Round(gctkline.OneMin.Duration())
|
|
tt2 := time.Now().Round(gctkline.OneMin.Duration())
|
|
interval := gctkline.OneMin
|
|
a := asset.Spot
|
|
var data *gctkline.Item
|
|
data, err = LoadData(common.DataCandle, tt1, tt2, interval.Duration(), exch, cp, a)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(data.Candles) == 0 {
|
|
t.Error("expected candles")
|
|
}
|
|
|
|
_, err = LoadData(-1, tt1, tt2, interval.Duration(), exch, cp, a)
|
|
if !errors.Is(err, common.ErrInvalidDataType) {
|
|
t.Errorf("expected '%v' received '%v'", err, common.ErrInvalidDataType)
|
|
}
|
|
}
|
|
|
|
func TestLoadTrades(t *testing.T) {
|
|
t.Parallel()
|
|
em := engine.SetupExchangeManager()
|
|
exch, err := em.NewExchangeByName(testExchange)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
exch.SetDefaults()
|
|
cp := currency.NewPair(currency.BTC, currency.USDT)
|
|
b := exch.GetBase()
|
|
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
|
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
|
Available: currency.Pairs{cp},
|
|
Enabled: currency.Pairs{cp},
|
|
AssetEnabled: convert.BoolPtr(true),
|
|
ConfigFormat: ¤cy.PairFormat{Uppercase: true},
|
|
RequestFormat: ¤cy.PairFormat{Uppercase: true}}
|
|
interval := gctkline.OneMin
|
|
tt1 := time.Now().Add(-time.Minute * 2).Round(interval.Duration())
|
|
tt2 := time.Now().Round(interval.Duration())
|
|
a := asset.Spot
|
|
var data *gctkline.Item
|
|
data, err = LoadData(common.DataTrade, tt1, tt2, interval.Duration(), exch, cp, a)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(data.Candles) == 0 {
|
|
t.Error("expected candles")
|
|
}
|
|
}
|