mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-30 07:26:46 +00:00
* GHA, tests: Add additional checks for common issues These checks include: - Ensuring that all testify funcs use their formatted variants (e.g., `assert.Equalf(t, expected, actual)` instead of `assert.Equal(t, expected, actual)`). - Replacing `%s` with %q - Enforcing consistent usage of should/must wording for testify assert/require messages * Add support for checking backticked string format specifiers and fix issues * tests: Fix error comparisons * tests: Replace errors.Is(err, nil) usage with testify and automate check * refactor: Rename ExtractPort to ExtractPortOrDefault * tests: Replace assert with require for error handling in multiple test files * tests: Replace assert with require for error handling and improve assertions in data tests * tests: Fix typo in assertion message for StreamVol test * OKX: Fix GetOpenInterestAndVolumeStrike test with instrument selection and improved assertions * OKX: Revert intentional error check * Improve error message for expiry time check in GetOpenInterestAndVolumeStrike test
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package strategies
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/data"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/portfolio"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/dollarcostaverage"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/eventtypes/signal"
|
|
"github.com/thrasher-corp/gocryptotrader/backtester/funding"
|
|
)
|
|
|
|
func TestAddStrategies(t *testing.T) {
|
|
t.Parallel()
|
|
err := addStrategies(nil)
|
|
if !errors.Is(err, errNoStrategies) {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = addStrategies([]strategies.Handler{&dollarcostaverage.Strategy{}})
|
|
if !errors.Is(err, strategies.ErrStrategyAlreadyExists) {
|
|
t.Error(err)
|
|
}
|
|
|
|
err = addStrategies([]strategies.Handler{&CustomStrategy{}})
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
type CustomStrategy struct {
|
|
base.Strategy
|
|
}
|
|
|
|
func (s *CustomStrategy) Name() string {
|
|
return "custom-strategy"
|
|
}
|
|
|
|
func (s *CustomStrategy) Description() string {
|
|
return "this is a demonstration of loading strategies via custom plugins"
|
|
}
|
|
|
|
func (s *CustomStrategy) SupportsSimultaneousProcessing() bool {
|
|
return true
|
|
}
|
|
|
|
func (s *CustomStrategy) OnSignal(d data.Handler, _ funding.IFundingTransferer, _ portfolio.Handler) (signal.Event, error) {
|
|
return s.createSignal(d)
|
|
}
|
|
|
|
func (s *CustomStrategy) OnSimultaneousSignals(_ []data.Handler, _ funding.IFundingTransferer, _ portfolio.Handler) ([]signal.Event, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *CustomStrategy) createSignal(_ data.Handler) (*signal.Signal, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *CustomStrategy) SetCustomSettings(map[string]any) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *CustomStrategy) SetDefaults() {}
|