mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
* Adds lovely initial concept for historical data doer
* Adds ability to save tasks. Adds config. Adds startStop to engine
* Has a database microservice without use of globals! Further infrastructure design. Adds readme
* Commentary to help design
* Adds migrations for database
* readme and adds database models
* Some modelling that doesn't work end of day
* Completes datahistoryjob sql.Begins datahistoryjobresult
* Adds datahistoryjob functions to retreive job results. Adapts subsystem
* Adds process for upserting jobs and job results to the database
* Broken end of day weird sqlboiler crap
* Fixes issue with SQL generation.
* RPC generation and addition of basic upsert command
* Renames types
* Adds rpc functions
* quick commit before context swithc. Exchanges aren't being populated
* Begin the tests!
* complete sql tests. stop failed jobs. CLI command creation
* Defines rpc commands
* Fleshes out RPC implementation
* Expands testing
* Expands testing, removes double remove
* Adds coverage of data history subsystem, expands errors and nil checks
* Minor logic improvement
* streamlines datahistory test setup
* End of day minor linting
* Lint, convert simplify, rpc expansion, type expansion, readme expansion
* Documentation update
* Renames for consistency
* Completes RPC server commands
* Fixes tests
* Speeds up testing by reducing unnecessary actions. Adds maxjobspercycle config
* Comments for everything
* Adds missing result string. checks interval supported. default start end cli
* Fixes ID problem. Improves binance trade fetch. job ranges are processed
* adds dbservice coverage. adds rpcserver coverage
* docs regen, uses dbcon interface, reverts binance, fixes races, toggle manager
* Speed up tests, remove bad global usage, fix uuid check
* Adds verbose. Updates docs. Fixes postgres
* Minor changes to logging and start stop
* Fixes postgres db tests, fixes postgres column typo
* Fixes old string typo,removes constraint,error parsing for nonreaders
* prevents dhm running when table doesn't exist. Adds prereq documentation
* Adds parallel, rmlines, err fix, comment fix, minor param fixes
* doc regen, common time range check and test updating
* Fixes job validation issues. Updates candle range checker.
* Ensures test cannot fail due to time.Now() shenanigans
* Fixes oopsie, adds documentation and a warn
* Fixes another time test, adjusts copy
* Drastically speeds up data history manager tests via function overrides
* Fixes summary bug and better logs
* Fixes local time test, fixes websocket tests
* removes defaults and comment,updates error messages,sets cli command args
* Fixes FTX trade processing
* Fixes issue where jobs got stuck if data wasn't returned but retrieval was successful
* Improves test speed. Simplifies trade verification SQL. Adds command help
* Fixes the oopsies
* Fixes use of query within transaction. Fixes trade err
* oopsie, not needed
* Adds missing data status. Properly ends job even when data is missing
* errors are more verbose and so have more words to describe them
* Doc regen for new status
* tiny test tinkering
* str := string("Removes .String()").String()
* Merge fixups
* Fixes a data race discovered during github actions
* Allows websocket test to pass consistently
* Fixes merge issue preventing datahistorymanager from starting via config
* Niterinos cmd defaults and explanations
* fixes default oopsie
* Fixes lack of nil protection
* Additional oopsie
* More detailed error for validating job exchange
722 lines
17 KiB
Go
722 lines
17 KiB
Go
package statistics
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/common"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/portfolio/compliance"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/portfolio/holdings"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/statistics/currencystatistics"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/event"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/fill"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/kline"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/order"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/signal"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
gctkline "github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
gctorder "github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
)
|
|
|
|
const testExchange = "binance"
|
|
|
|
func TestReset(t *testing.T) {
|
|
s := Statistic{
|
|
TotalOrders: 1,
|
|
}
|
|
s.Reset()
|
|
if s.TotalOrders != 0 {
|
|
t.Error("expected 0")
|
|
}
|
|
}
|
|
|
|
func TestAddDataEventForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
err := s.SetupEventForTime(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if s.ExchangeAssetPairStatistics == nil {
|
|
t.Error("expected not nil")
|
|
}
|
|
if len(s.ExchangeAssetPairStatistics[exch][a][p].Events) != 1 {
|
|
t.Error("expected 1 event")
|
|
}
|
|
}
|
|
|
|
func TestAddSignalEventForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
err := s.SetEventForOffset(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetEventForOffset(&signal.Signal{})
|
|
if !errors.Is(err, errExchangeAssetPairStatsUnset) {
|
|
t.Errorf("expected: %v, received %v", errExchangeAssetPairStatsUnset, err)
|
|
}
|
|
s.setupMap(exch, a)
|
|
s.ExchangeAssetPairStatistics = make(map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic)
|
|
err = s.SetEventForOffset(&signal.Signal{})
|
|
if !errors.Is(err, errCurrencyStatisticsUnset) {
|
|
t.Errorf("expected: %v, received %v", errCurrencyStatisticsUnset, err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
ClosePrice: 1337,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestAddExchangeEventForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
err := s.SetEventForOffset(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetEventForOffset(&order.Order{})
|
|
if !errors.Is(err, errExchangeAssetPairStatsUnset) {
|
|
t.Errorf("expected: %v, received %v", errExchangeAssetPairStatsUnset, err)
|
|
}
|
|
s.setupMap(exch, a)
|
|
s.ExchangeAssetPairStatistics = make(map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic)
|
|
err = s.SetEventForOffset(&order.Order{})
|
|
if !errors.Is(err, errCurrencyStatisticsUnset) {
|
|
t.Errorf("expected: %v, received %v", errCurrencyStatisticsUnset, err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&order.Order{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
ID: "1337",
|
|
Direction: gctorder.Buy,
|
|
Status: gctorder.New,
|
|
Price: 1337,
|
|
Amount: 1337,
|
|
OrderType: gctorder.Stop,
|
|
Leverage: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestAddFillEventForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
err := s.SetEventForOffset(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetEventForOffset(&fill.Fill{})
|
|
if err != nil && err.Error() != "exchangeAssetPairStatistics not setup" {
|
|
t.Error(err)
|
|
}
|
|
s.setupMap(exch, a)
|
|
s.ExchangeAssetPairStatistics = make(map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic)
|
|
err = s.SetEventForOffset(&fill.Fill{})
|
|
if !errors.Is(err, errCurrencyStatisticsUnset) {
|
|
t.Errorf("expected: %v, received %v", errCurrencyStatisticsUnset, err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&fill.Fill{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Direction: gctorder.Buy,
|
|
Amount: 1337,
|
|
ClosePrice: 1337,
|
|
VolumeAdjustedPrice: 1337,
|
|
PurchasePrice: 1337,
|
|
ExchangeFee: 1337,
|
|
Slippage: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestAddHoldingsForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
err := s.AddHoldingsForTime(&holdings.Holding{})
|
|
if !errors.Is(err, errExchangeAssetPairStatsUnset) {
|
|
t.Errorf("expected: %v, received %v", errExchangeAssetPairStatsUnset, err)
|
|
}
|
|
s.ExchangeAssetPairStatistics = make(map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic)
|
|
err = s.AddHoldingsForTime(&holdings.Holding{})
|
|
if !errors.Is(err, errCurrencyStatisticsUnset) {
|
|
t.Errorf("expected: %v, received %v", errCurrencyStatisticsUnset, err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.AddHoldingsForTime(&holdings.Holding{
|
|
Pair: p,
|
|
Asset: a,
|
|
Exchange: exch,
|
|
Timestamp: tt,
|
|
InitialFunds: 1337,
|
|
PositionsSize: 1337,
|
|
PositionsValue: 1337,
|
|
SoldAmount: 1337,
|
|
SoldValue: 1337,
|
|
BoughtAmount: 1337,
|
|
BoughtValue: 1337,
|
|
RemainingFunds: 1337,
|
|
TotalValueDifference: 1337,
|
|
ChangeInTotalValuePercent: 1337,
|
|
BoughtValueDifference: 1337,
|
|
SoldValueDifference: 1337,
|
|
PositionsValueDifference: 1337,
|
|
TotalValue: 1337,
|
|
TotalFees: 1337,
|
|
TotalValueLostToVolumeSizing: 1337,
|
|
TotalValueLostToSlippage: 1337,
|
|
TotalValueLost: 1337,
|
|
RiskFreeRate: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestAddComplianceSnapshotForTime(t *testing.T) {
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
s := Statistic{}
|
|
|
|
err := s.AddComplianceSnapshotForTime(compliance.Snapshot{}, nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.AddComplianceSnapshotForTime(compliance.Snapshot{}, &fill.Fill{})
|
|
if !errors.Is(err, errExchangeAssetPairStatsUnset) {
|
|
t.Errorf("expected: %v, received %v", errExchangeAssetPairStatsUnset, err)
|
|
}
|
|
s.setupMap(exch, a)
|
|
s.ExchangeAssetPairStatistics = make(map[string]map[asset.Item]map[currency.Pair]*currencystatistics.CurrencyStatistic)
|
|
err = s.AddComplianceSnapshotForTime(compliance.Snapshot{}, &fill.Fill{})
|
|
if !errors.Is(err, errCurrencyStatisticsUnset) {
|
|
t.Errorf("expected: %v, received %v", errCurrencyStatisticsUnset, err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.AddComplianceSnapshotForTime(compliance.Snapshot{
|
|
Timestamp: tt,
|
|
}, &fill.Fill{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestSerialise(t *testing.T) {
|
|
s := Statistic{}
|
|
_, err := s.Serialise()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestSetStrategyName(t *testing.T) {
|
|
s := Statistic{}
|
|
s.SetStrategyName("test")
|
|
if s.StrategyName != "test" {
|
|
t.Error("expected test")
|
|
}
|
|
}
|
|
|
|
func TestPrintTotalResults(t *testing.T) {
|
|
s := Statistic{}
|
|
s.BiggestDrawdown = s.GetTheBiggestDrawdownAcrossCurrencies([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
MaxDrawdown: currencystatistics.Swing{
|
|
DrawdownPercent: 1337,
|
|
},
|
|
},
|
|
})
|
|
s.BestStrategyResults = s.GetBestStrategyPerformer([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
Asset: asset.Spot,
|
|
Pair: currency.NewPair(currency.BTC, currency.DOGE),
|
|
MaxDrawdown: currencystatistics.Swing{},
|
|
MarketMovement: 1337,
|
|
StrategyMovement: 1337,
|
|
},
|
|
})
|
|
s.BestMarketMovement = s.GetBestMarketPerformer([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
MarketMovement: 1337,
|
|
},
|
|
})
|
|
s.PrintTotalResults()
|
|
}
|
|
|
|
func TestGetBestStrategyPerformer(t *testing.T) {
|
|
s := Statistic{}
|
|
resp := s.GetBestStrategyPerformer(nil)
|
|
if resp.Exchange != "" {
|
|
t.Error("expected unset details")
|
|
}
|
|
|
|
resp = s.GetBestStrategyPerformer([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
Asset: asset.Spot,
|
|
Pair: currency.NewPair(currency.BTC, currency.DOGE),
|
|
MaxDrawdown: currencystatistics.Swing{},
|
|
MarketMovement: 1337,
|
|
StrategyMovement: 1337,
|
|
},
|
|
{
|
|
Exchange: "test2",
|
|
Asset: asset.Spot,
|
|
Pair: currency.NewPair(currency.BTC, currency.DOGE),
|
|
MaxDrawdown: currencystatistics.Swing{},
|
|
MarketMovement: 1338,
|
|
StrategyMovement: 1338,
|
|
},
|
|
})
|
|
|
|
if resp.Exchange != "test2" {
|
|
t.Error("expected test2")
|
|
}
|
|
}
|
|
|
|
func TestGetTheBiggestDrawdownAcrossCurrencies(t *testing.T) {
|
|
s := Statistic{}
|
|
result := s.GetTheBiggestDrawdownAcrossCurrencies(nil)
|
|
if result.Exchange != "" {
|
|
t.Error("expected empty")
|
|
}
|
|
|
|
result = s.GetTheBiggestDrawdownAcrossCurrencies([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
MaxDrawdown: currencystatistics.Swing{
|
|
DrawdownPercent: 1337,
|
|
},
|
|
},
|
|
{
|
|
Exchange: "test2",
|
|
MaxDrawdown: currencystatistics.Swing{
|
|
DrawdownPercent: 1338,
|
|
},
|
|
},
|
|
})
|
|
if result.Exchange != "test2" {
|
|
t.Error("expected test2")
|
|
}
|
|
}
|
|
|
|
func TestGetBestMarketPerformer(t *testing.T) {
|
|
s := Statistic{}
|
|
result := s.GetBestMarketPerformer(nil)
|
|
if result.Exchange != "" {
|
|
t.Error("expected empty")
|
|
}
|
|
|
|
result = s.GetBestMarketPerformer([]FinalResultsHolder{
|
|
{
|
|
Exchange: "test",
|
|
MarketMovement: 1337,
|
|
},
|
|
{
|
|
Exchange: "test2",
|
|
MarketMovement: 1336,
|
|
},
|
|
})
|
|
if result.Exchange != "test" {
|
|
t.Error("expected test")
|
|
}
|
|
}
|
|
|
|
func TestPrintAllEvents(t *testing.T) {
|
|
s := Statistic{}
|
|
s.PrintAllEvents()
|
|
tt := time.Now()
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
err := s.SetupEventForTime(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = s.SetEventForOffset(&fill.Fill{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Direction: gctorder.Buy,
|
|
Amount: 1337,
|
|
ClosePrice: 1337,
|
|
VolumeAdjustedPrice: 1337,
|
|
PurchasePrice: 1337,
|
|
ExchangeFee: 1337,
|
|
Slippage: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
ClosePrice: 1337,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
s.PrintAllEvents()
|
|
}
|
|
|
|
func TestCalculateTheResults(t *testing.T) {
|
|
s := Statistic{}
|
|
err := s.CalculateAllResults()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
tt := time.Now().Add(-gctkline.OneDay.Duration() * 7)
|
|
tt2 := time.Now().Add(-gctkline.OneDay.Duration() * 6)
|
|
exch := testExchange
|
|
a := asset.Spot
|
|
p := currency.NewPair(currency.BTC, currency.USDT)
|
|
p2 := currency.NewPair(currency.DOGE, currency.DOGE)
|
|
err = s.SetupEventForTime(nil)
|
|
if !errors.Is(err, common.ErrNilEvent) {
|
|
t.Errorf("expected: %v, received %v", common.ErrNilEvent, err)
|
|
}
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1337,
|
|
Close: 1337,
|
|
Low: 1337,
|
|
High: 1337,
|
|
Volume: 1337,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
OpenPrice: 1337,
|
|
HighPrice: 1337,
|
|
LowPrice: 1337,
|
|
ClosePrice: 1337,
|
|
Volume: 1337,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p2,
|
|
AssetType: a,
|
|
},
|
|
Open: 1338,
|
|
Close: 1338,
|
|
Low: 1338,
|
|
High: 1338,
|
|
Volume: 1338,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p2,
|
|
AssetType: a,
|
|
},
|
|
OpenPrice: 1337,
|
|
HighPrice: 1337,
|
|
LowPrice: 1337,
|
|
ClosePrice: 1337,
|
|
Volume: 1337,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt2,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
Open: 1338,
|
|
Close: 1338,
|
|
Low: 1338,
|
|
High: 1338,
|
|
Volume: 1338,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt2,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p,
|
|
AssetType: a,
|
|
},
|
|
OpenPrice: 1338,
|
|
HighPrice: 1338,
|
|
LowPrice: 1338,
|
|
ClosePrice: 1338,
|
|
Volume: 1338,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = s.SetupEventForTime(&kline.Kline{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt2,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p2,
|
|
AssetType: a,
|
|
},
|
|
Open: 1338,
|
|
Close: 1338,
|
|
Low: 1338,
|
|
High: 1338,
|
|
Volume: 1338,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
err = s.SetEventForOffset(&signal.Signal{
|
|
Base: event.Base{
|
|
Exchange: exch,
|
|
Time: tt2,
|
|
Interval: gctkline.OneDay,
|
|
CurrencyPair: p2,
|
|
AssetType: a,
|
|
},
|
|
OpenPrice: 1338,
|
|
HighPrice: 1338,
|
|
LowPrice: 1338,
|
|
ClosePrice: 1338,
|
|
Volume: 1338,
|
|
Direction: gctorder.Buy,
|
|
})
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
s.ExchangeAssetPairStatistics[exch][a][p].Events[1].Holdings.InitialFunds = 1337
|
|
s.ExchangeAssetPairStatistics[exch][a][p].Events[1].Holdings.TotalValue = 13337
|
|
s.ExchangeAssetPairStatistics[exch][a][p2].Events[1].Holdings.InitialFunds = 1337
|
|
s.ExchangeAssetPairStatistics[exch][a][p2].Events[1].Holdings.TotalValue = 13337
|
|
|
|
err = s.CalculateAllResults()
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|