mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
modernise: Run new gopls modernise tool against the codebase and fix minor issues (#1826)
* modernise: Run new gopls modernise tool against codebase
* Address shazbert's nits
* apichecker, gctcli: Simplify HTML scraping functions and improve depth limit handling
* refactor: Create minSyncInterval const and update order book limit handling for binance and binanceUS
* refactor: Various slice usage improvements and rename TODO
* tranches: Revert deleteByID changes due to performance decrease
Shazbert was a F1 driver in a past lifetime 🏎️
* tranches: Simply retrieve copy
Thanks to shazbert
* documentation: Sort contributors list by contributions
* tranches: Remove deadcode in deleteByID
This commit is contained in:
@@ -36,7 +36,7 @@ var (
|
||||
|
||||
const defaultTimeout = time.Second * 30
|
||||
|
||||
func jsonOutput(in interface{}) {
|
||||
func jsonOutput(in any) {
|
||||
j, err := json.MarshalIndent(in, "", " ")
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -52,7 +52,7 @@ type Event interface {
|
||||
GetReasons() []string
|
||||
GetClosePrice() decimal.Decimal
|
||||
AppendReason(string)
|
||||
AppendReasonf(string, ...interface{})
|
||||
AppendReasonf(string, ...any)
|
||||
}
|
||||
|
||||
// custom subloggers for backtester use
|
||||
|
||||
@@ -362,7 +362,7 @@ func TestPrintSettings(t *testing.T) {
|
||||
Goal: "To demonstrate rendering of settings",
|
||||
StrategySettings: StrategySettings{
|
||||
Name: dca,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"dca-dummy1": 30.0,
|
||||
"dca-dummy2": 30.0,
|
||||
"dca-dummy3": 30.0,
|
||||
@@ -963,7 +963,7 @@ func TestGenerateConfigForRSIAPICustomSettings(t *testing.T) {
|
||||
Goal: "To demonstrate the RSI strategy using API candle data and custom settings",
|
||||
StrategySettings: StrategySettings{
|
||||
Name: "rsi",
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"rsi-low": 30.0,
|
||||
"rsi-high": 70.0,
|
||||
"rsi-period": 14,
|
||||
@@ -1206,7 +1206,7 @@ func TestGenerateConfigForTop2Bottom2(t *testing.T) {
|
||||
Name: top2bottom2.Name,
|
||||
SimultaneousSignalProcessing: true,
|
||||
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"mfi-low": 32,
|
||||
"mfi-high": 68,
|
||||
"mfi-period": 14,
|
||||
|
||||
@@ -67,8 +67,8 @@ type StrategySettings struct {
|
||||
|
||||
// If true, won't track USD values against currency pair
|
||||
// bool language is opposite to encourage use by default
|
||||
DisableUSDTracking bool `json:"disable-usd-tracking"`
|
||||
CustomSettings map[string]interface{} `json:"custom-settings,omitempty"`
|
||||
DisableUSDTracking bool `json:"disable-usd-tracking"`
|
||||
CustomSettings map[string]any `json:"custom-settings,omitempty"`
|
||||
}
|
||||
|
||||
// ExchangeLevelFunding allows the portfolio manager to access
|
||||
|
||||
@@ -554,8 +554,8 @@ func parseStratName(name string, strategiesToUse []string) (string, error) {
|
||||
return "", errors.New("unrecognised strategy")
|
||||
}
|
||||
|
||||
func customSettingsLoop(reader *bufio.Reader) map[string]interface{} {
|
||||
resp := make(map[string]interface{})
|
||||
func customSettingsLoop(reader *bufio.Reader) map[string]any {
|
||||
resp := make(map[string]any)
|
||||
customSettingField := "loopTime!"
|
||||
for customSettingField != "" {
|
||||
fmt.Println("Enter a custom setting name. Enter nothing to stop")
|
||||
|
||||
@@ -808,7 +808,7 @@ func (f fakeEvent) GetUnderlyingPair() currency.Pair {
|
||||
return f.Pair()
|
||||
}
|
||||
|
||||
func (f fakeEvent) AppendReasonf(string, ...interface{}) {}
|
||||
func (f fakeEvent) AppendReasonf(string, ...any) {}
|
||||
|
||||
func (f fakeEvent) GetBase() *event.Base {
|
||||
return &event.Base{}
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestSetupFromConfig(t *testing.T) {
|
||||
|
||||
cfg.StrategySettings = config.StrategySettings{
|
||||
Name: dollarcostaverage.Name,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"hello": "moto",
|
||||
},
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func TestLoadDataAPI(t *testing.T) {
|
||||
},
|
||||
StrategySettings: config.StrategySettings{
|
||||
Name: dollarcostaverage.Name,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"hello": "moto",
|
||||
},
|
||||
},
|
||||
@@ -222,7 +222,7 @@ func TestLoadDataCSV(t *testing.T) {
|
||||
},
|
||||
StrategySettings: config.StrategySettings{
|
||||
Name: dollarcostaverage.Name,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"hello": "moto",
|
||||
},
|
||||
},
|
||||
@@ -289,7 +289,7 @@ func TestLoadDataDatabase(t *testing.T) {
|
||||
},
|
||||
StrategySettings: config.StrategySettings{
|
||||
Name: dollarcostaverage.Name,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"hello": "moto",
|
||||
},
|
||||
},
|
||||
@@ -367,7 +367,7 @@ func TestLoadDataLive(t *testing.T) {
|
||||
},
|
||||
StrategySettings: config.StrategySettings{
|
||||
Name: dollarcostaverage.Name,
|
||||
CustomSettings: map[string]interface{}{
|
||||
CustomSettings: map[string]any{
|
||||
"hello": "moto",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -307,7 +307,7 @@ func (f fakeStrat) SupportsSimultaneousProcessing() bool {
|
||||
|
||||
func (f fakeStrat) SetSimultaneousProcessing(bool) {}
|
||||
|
||||
func (f fakeStrat) SetCustomSettings(map[string]interface{}) error {
|
||||
func (f fakeStrat) SetCustomSettings(map[string]any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ func (s *GRPCServer) ExecuteStrategyFromConfig(_ context.Context, request *btrpc
|
||||
}
|
||||
}
|
||||
|
||||
customSettings := make(map[string]interface{}, len(request.Config.StrategySettings.CustomSettings))
|
||||
customSettings := make(map[string]any, len(request.Config.StrategySettings.CustomSettings))
|
||||
for i := range request.Config.StrategySettings.CustomSettings {
|
||||
customSettings[request.Config.StrategySettings.CustomSettings[i].KeyField] = request.Config.StrategySettings.CustomSettings[i].KeyValue
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package engine
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
|
||||
@@ -185,7 +186,7 @@ func (r *TaskManager) ClearTask(id uuid.UUID) error {
|
||||
if r.tasks[i].IsRunning() {
|
||||
return fmt.Errorf("%w %v, currently running. Stop it first", errCannotClear, r.tasks[i].MetaData.ID)
|
||||
}
|
||||
r.tasks = append(r.tasks[:i], r.tasks[i+1:]...)
|
||||
r.tasks = slices.Delete(r.tasks, i, i+1)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%s %w", id, errTaskNotFound)
|
||||
@@ -208,7 +209,7 @@ func (r *TaskManager) ClearAllTasks() (clearedRuns, remainingRuns []*TaskSummary
|
||||
remainingRuns = append(remainingRuns, run)
|
||||
} else {
|
||||
clearedRuns = append(clearedRuns, run)
|
||||
r.tasks = append(r.tasks[:i], r.tasks[i+1:]...)
|
||||
r.tasks = slices.Delete(r.tasks, i, i+1)
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ type CurrencyPairStatistic struct {
|
||||
|
||||
Events []DataAtOffset `json:"-"`
|
||||
|
||||
MaxDrawdown Swing `json:"max-drawdown,omitempty"`
|
||||
MaxDrawdown Swing `json:"max-drawdown"`
|
||||
HighestCommittedFunds ValueAtTime `json:"highest-committed-funds"`
|
||||
GeometricRatios *Ratios `json:"geometric-ratios"`
|
||||
ArithmeticRatios *Ratios `json:"arithmetic-ratios"`
|
||||
|
||||
@@ -278,7 +278,7 @@ func sortSignals(d []data.Handler) ([]cashCarrySignals, error) {
|
||||
}
|
||||
|
||||
// SetCustomSettings can override default settings
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]interface{}) error {
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]any) error {
|
||||
for k, v := range customSettings {
|
||||
switch k {
|
||||
case openShortDistancePercentageString:
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestSetCustomSettings(t *testing.T) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
float14 := float64(14)
|
||||
mappalopalous := make(map[string]interface{})
|
||||
mappalopalous := make(map[string]any)
|
||||
mappalopalous[openShortDistancePercentageString] = float14
|
||||
mappalopalous[closeShortDistancePercentageString] = float14
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func (s *Strategy) OnSimultaneousSignals(d []data.Handler, _ funding.IFundingTra
|
||||
}
|
||||
|
||||
// SetCustomSettings not required for DCA
|
||||
func (s *Strategy) SetCustomSettings(_ map[string]interface{}) error {
|
||||
func (s *Strategy) SetCustomSettings(_ map[string]any) error {
|
||||
return base.ErrCustomSettingsUnsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ func (s *Strategy) OnSimultaneousSignals(d []data.Handler, _ funding.IFundingTra
|
||||
}
|
||||
|
||||
// SetCustomSettings allows a user to modify the RSI limits in their config
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]interface{}) error {
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]any) error {
|
||||
for k, v := range customSettings {
|
||||
switch k {
|
||||
case rsiHighKey:
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestSetCustomSettings(t *testing.T) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
float14 := float64(14)
|
||||
mappalopalous := make(map[string]interface{})
|
||||
mappalopalous := make(map[string]any)
|
||||
mappalopalous[rsiPeriodKey] = float14
|
||||
mappalopalous[rsiLowKey] = float14
|
||||
mappalopalous[rsiHighKey] = float14
|
||||
|
||||
@@ -137,7 +137,7 @@ func (s *customStrategy) createSignal(_ data.Handler) (*signal.Signal, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *customStrategy) SetCustomSettings(map[string]interface{}) error {
|
||||
func (s *customStrategy) SetCustomSettings(map[string]any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ type Handler interface {
|
||||
UsingSimultaneousProcessing() bool
|
||||
SupportsSimultaneousProcessing() bool
|
||||
SetSimultaneousProcessing(bool)
|
||||
SetCustomSettings(map[string]interface{}) error
|
||||
SetCustomSettings(map[string]any) error
|
||||
SetDefaults()
|
||||
CloseAllPositions([]holdings.Holding, []data.Event) ([]signal.Event, error)
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ func (s *Strategy) selectTopAndBottomPerformers(mfiFundEvents []mfiFundEvent, re
|
||||
}
|
||||
|
||||
// SetCustomSettings allows a user to modify the MFI limits in their config
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]interface{}) error {
|
||||
func (s *Strategy) SetCustomSettings(customSettings map[string]any) error {
|
||||
for k, v := range customSettings {
|
||||
switch k {
|
||||
case mfiHighKey:
|
||||
|
||||
@@ -51,7 +51,7 @@ func TestSetCustomSettings(t *testing.T) {
|
||||
t.Errorf("received: %v, expected: %v", err, nil)
|
||||
}
|
||||
float14 := float64(14)
|
||||
mappalopalous := make(map[string]interface{})
|
||||
mappalopalous := make(map[string]any)
|
||||
mappalopalous[mfiPeriodKey] = float14
|
||||
mappalopalous[mfiLowKey] = float14
|
||||
mappalopalous[mfiHighKey] = float14
|
||||
|
||||
@@ -62,7 +62,7 @@ func (b *Base) AppendReason(y string) {
|
||||
|
||||
// AppendReasonf adds reasoning for a decision being made
|
||||
// but with formatting
|
||||
func (b *Base) AppendReasonf(y string, addons ...interface{}) {
|
||||
func (b *Base) AppendReasonf(y string, addons ...any) {
|
||||
y = fmt.Sprintf(y, addons...)
|
||||
b.Reasons = append(b.Reasons, y)
|
||||
}
|
||||
|
||||
@@ -1016,22 +1016,22 @@ var leet = decimal.NewFromInt(1337)
|
||||
// caring about the response, or dealing with import cycles
|
||||
type fakeEvent struct{}
|
||||
|
||||
func (f *fakeEvent) GetHighPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetLowPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetOpenPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetVolume() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetOffset() int64 { return 0 }
|
||||
func (f *fakeEvent) SetOffset(int64) {}
|
||||
func (f *fakeEvent) IsEvent() bool { return true }
|
||||
func (f *fakeEvent) GetTime() time.Time { return time.Now() }
|
||||
func (f *fakeEvent) Pair() currency.Pair { return pair }
|
||||
func (f *fakeEvent) GetExchange() string { return exchName }
|
||||
func (f *fakeEvent) GetInterval() gctkline.Interval { return gctkline.OneMin }
|
||||
func (f *fakeEvent) GetAssetType() asset.Item { return asset.Spot }
|
||||
func (f *fakeEvent) AppendReason(string) {}
|
||||
func (f *fakeEvent) GetClosePrice() decimal.Decimal { return elite }
|
||||
func (f *fakeEvent) AppendReasonf(_ string, _ ...interface{}) {}
|
||||
func (f *fakeEvent) GetBase() *event.Base { return &event.Base{} }
|
||||
func (f *fakeEvent) GetUnderlyingPair() currency.Pair { return pair }
|
||||
func (f *fakeEvent) GetConcatReasons() string { return "" }
|
||||
func (f *fakeEvent) GetReasons() []string { return nil }
|
||||
func (f *fakeEvent) GetHighPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetLowPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetOpenPrice() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetVolume() decimal.Decimal { return leet }
|
||||
func (f *fakeEvent) GetOffset() int64 { return 0 }
|
||||
func (f *fakeEvent) SetOffset(int64) {}
|
||||
func (f *fakeEvent) IsEvent() bool { return true }
|
||||
func (f *fakeEvent) GetTime() time.Time { return time.Now() }
|
||||
func (f *fakeEvent) Pair() currency.Pair { return pair }
|
||||
func (f *fakeEvent) GetExchange() string { return exchName }
|
||||
func (f *fakeEvent) GetInterval() gctkline.Interval { return gctkline.OneMin }
|
||||
func (f *fakeEvent) GetAssetType() asset.Item { return asset.Spot }
|
||||
func (f *fakeEvent) AppendReason(string) {}
|
||||
func (f *fakeEvent) GetClosePrice() decimal.Decimal { return elite }
|
||||
func (f *fakeEvent) AppendReasonf(_ string, _ ...any) {}
|
||||
func (f *fakeEvent) GetBase() *event.Base { return &event.Base{} }
|
||||
func (f *fakeEvent) GetUnderlyingPair() currency.Pair { return pair }
|
||||
func (f *fakeEvent) GetConcatReasons() string { return "" }
|
||||
func (f *fakeEvent) GetReasons() []string { return nil }
|
||||
|
||||
@@ -3,6 +3,7 @@ package trackingcurrencies
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/engine"
|
||||
@@ -101,12 +102,9 @@ func CreateUSDTrackingPairs(tp []TrackingPair, em *engine.ExchangeManager) ([]Tr
|
||||
// CurrencyIsUSDTracked checks if the currency passed in
|
||||
// tracks against USD value, ie is in rankedUSDs
|
||||
func CurrencyIsUSDTracked(code currency.Code) bool {
|
||||
for i := range rankedUSDs {
|
||||
if code.Equal(rankedUSDs[i]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(rankedUSDs, func(c currency.Code) bool {
|
||||
return c.Equal(code)
|
||||
})
|
||||
}
|
||||
|
||||
// pairContainsUSD is a simple check to ensure that the currency pair
|
||||
|
||||
@@ -81,7 +81,7 @@ func (s *CustomStrategy) createSignal(d data.Handler) (*signal.Signal, error) {
|
||||
}
|
||||
|
||||
// SetCustomSettings can override default settings
|
||||
func (s *CustomStrategy) SetCustomSettings(map[string]interface{}) error {
|
||||
func (s *CustomStrategy) SetCustomSettings(map[string]any) error {
|
||||
return base.ErrCustomSettingsUnsupported
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ func (s *CustomStrategy) createSignal(_ data.Handler) (*signal.Signal, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *CustomStrategy) SetCustomSettings(map[string]interface{}) error {
|
||||
func (s *CustomStrategy) SetCustomSettings(map[string]any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user