mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
build/ci: Update Go to v1.24, golangci-lint to v1.64.6 and fix issues (#1804)
* build/ci: Update Go to v1.24, golangci-lint to v1.64.5 and fix issues * Address shazbert's nitters * linter/config: Fix new linter issue and use versionSize const * Address gk's nitters and fix additional linter issue after rebase * Address glorious nits * staticcheck: Fix additional linter issues after upgrading to Go 1.24.1 and golangci-lint v1.64.6 Also addresses nits * Improve testing, assertify usage and use common.ErrParsingWSField * TestCreateNewStrategy: Replace must > should wording
This commit is contained in:
@@ -178,7 +178,7 @@ func (m *DataHistoryManager) compareJobsToData(jobs ...*DataHistoryJob) error {
|
||||
}
|
||||
var err error
|
||||
for i := range jobs {
|
||||
jobs[i].rangeHolder, err = kline.CalculateCandleDateRanges(jobs[i].StartDate, jobs[i].EndDate, jobs[i].Interval, uint32(jobs[i].RequestSizeLimit))
|
||||
jobs[i].rangeHolder, err = kline.CalculateCandleDateRanges(jobs[i].StartDate, jobs[i].EndDate, jobs[i].Interval, jobs[i].RequestSizeLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (m *DataHistoryManager) runDataJob(job *DataHistoryJob, exch exchange.IBotE
|
||||
if !m.IsRunning() {
|
||||
return ErrSubSystemNotStarted
|
||||
}
|
||||
var intervalsProcessed int64
|
||||
var intervalsProcessed uint64
|
||||
var err error
|
||||
var result *DataHistoryJobResult
|
||||
ranges:
|
||||
@@ -404,7 +404,7 @@ ranges:
|
||||
job.DataType)
|
||||
}
|
||||
|
||||
var failures int64
|
||||
var failures uint64
|
||||
hasDataInRange := false
|
||||
resultLookup, ok := job.Results[job.rangeHolder.Ranges[i].Start.Time.Unix()]
|
||||
if ok {
|
||||
@@ -503,9 +503,9 @@ func (m *DataHistoryManager) runValidationJob(job *DataHistoryJob, exch exchange
|
||||
if !m.IsRunning() {
|
||||
return ErrSubSystemNotStarted
|
||||
}
|
||||
var intervalsProcessed int64
|
||||
var intervalsProcessed uint64
|
||||
var jobIntervals, intervalsToCheck []time.Time
|
||||
intervalLength := job.Interval.Duration() * time.Duration(job.RequestSizeLimit)
|
||||
intervalLength := job.Interval.Duration() * time.Duration(job.RequestSizeLimit) //nolint:gosec // TODO: Ensure size limit can't overflow
|
||||
for i := job.StartDate; i.Before(job.EndDate); i = i.Add(intervalLength) {
|
||||
jobIntervals = append(jobIntervals, i)
|
||||
}
|
||||
@@ -513,7 +513,7 @@ func (m *DataHistoryManager) runValidationJob(job *DataHistoryJob, exch exchange
|
||||
timesToFetch:
|
||||
for t, results := range job.Results {
|
||||
tt := time.Unix(t, 0)
|
||||
if len(results) < int(job.MaxRetryAttempts) {
|
||||
if uint64(len(results)) < job.MaxRetryAttempts {
|
||||
for x := range results {
|
||||
if results[x].Status == dataHistoryStatusComplete {
|
||||
continue timesToFetch
|
||||
@@ -1156,7 +1156,7 @@ func (m *DataHistoryManager) UpsertJob(job *DataHistoryJob, insertOnly bool) err
|
||||
if job.DataType == dataHistoryConvertCandlesDataType {
|
||||
interval = job.ConversionInterval
|
||||
}
|
||||
job.rangeHolder, err = kline.CalculateCandleDateRanges(job.StartDate, job.EndDate, interval, uint32(job.RequestSizeLimit))
|
||||
job.rangeHolder, err = kline.CalculateCandleDateRanges(job.StartDate, job.EndDate, interval, job.RequestSizeLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1256,7 +1256,7 @@ func (m *DataHistoryManager) validateJob(job *DataHistoryJob) error {
|
||||
}
|
||||
|
||||
if job.DataType == dataHistoryCandleValidationDataType {
|
||||
if job.DecimalPlaceComparison < 0 {
|
||||
if job.DecimalPlaceComparison == 0 {
|
||||
log.Warnf(log.DataHistory, "job %s decimal place comparison %v invalid. defaulting to %v decimal places when comparing data for validation", job.Nickname, job.DecimalPlaceComparison, defaultDecimalPlaceComparison)
|
||||
job.DecimalPlaceComparison = defaultDecimalPlaceComparison
|
||||
}
|
||||
|
||||
@@ -104,18 +104,20 @@ var (
|
||||
errNilResult = errors.New("received nil job result")
|
||||
errJobMustBeActiveOrPaused = errors.New("job must be active or paused to be set as a prerequisite")
|
||||
errNilCandles = errors.New("received nil candles")
|
||||
)
|
||||
|
||||
const (
|
||||
// defaultDataHistoryTradeInterval is the default interval size used to verify whether there is any database data
|
||||
// for a trade job
|
||||
defaultDataHistoryTradeInterval = kline.FifteenMin
|
||||
defaultDataHistoryMaxJobsPerCycle int64 = 5
|
||||
defaultMaxResultInsertions int64 = 10000
|
||||
defaultDataHistoryBatchLimit int64 = 3
|
||||
defaultDataHistoryRetryAttempts int64 = 3
|
||||
defaultDataHistoryRequestSizeLimit int64 = 500
|
||||
defaultDataHistoryTicker = time.Minute
|
||||
defaultDataHistoryTradeRequestSize int64 = 10
|
||||
defaultDecimalPlaceComparison int64 = 3
|
||||
defaultDataHistoryTradeInterval = kline.FifteenMin
|
||||
defaultDataHistoryMaxJobsPerCycle int64 = 5
|
||||
defaultMaxResultInsertions int64 = 10000
|
||||
defaultDataHistoryBatchLimit uint64 = 3
|
||||
defaultDataHistoryRetryAttempts uint64 = 3
|
||||
defaultDataHistoryRequestSizeLimit uint64 = 500
|
||||
defaultDataHistoryTicker = time.Minute
|
||||
defaultDataHistoryTradeRequestSize uint64 = 10
|
||||
defaultDecimalPlaceComparison uint64 = 3
|
||||
)
|
||||
|
||||
// DataHistoryManager is responsible for synchronising,
|
||||
@@ -149,17 +151,17 @@ type DataHistoryJob struct {
|
||||
StartDate time.Time
|
||||
EndDate time.Time
|
||||
Interval kline.Interval
|
||||
RunBatchLimit int64
|
||||
RequestSizeLimit int64
|
||||
RunBatchLimit uint64
|
||||
RequestSizeLimit uint64
|
||||
DataType dataHistoryDataType
|
||||
MaxRetryAttempts int64
|
||||
MaxRetryAttempts uint64
|
||||
Status dataHistoryStatus
|
||||
CreatedDate time.Time
|
||||
Results map[int64][]DataHistoryJobResult
|
||||
rangeHolder *kline.IntervalRangeHolder
|
||||
OverwriteExistingData bool
|
||||
ConversionInterval kline.Interval
|
||||
DecimalPlaceComparison int64
|
||||
DecimalPlaceComparison uint64
|
||||
SecondaryExchangeSource string
|
||||
IssueTolerancePercentage float64
|
||||
ReplaceOnIssue bool
|
||||
|
||||
@@ -202,7 +202,7 @@ func validateSettings(b *Engine, s *Settings, flagSet FlagSet) {
|
||||
flagSet.WithBool("deprecatedrpc", &b.Settings.EnableDeprecatedRPC, b.Config.RemoteControl.DeprecatedRPC.Enabled)
|
||||
|
||||
if flagSet["maxvirtualmachines"] {
|
||||
maxMachines := uint8(b.Settings.MaxVirtualMachines)
|
||||
maxMachines := b.Settings.MaxVirtualMachines
|
||||
b.gctScriptManager.MaxVirtualMachines = &maxMachines
|
||||
}
|
||||
|
||||
|
||||
@@ -369,9 +369,7 @@ func TestGetDefaultConfigurations(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
exch, err := em.NewExchangeByName(name)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "NewExchangeByName must not error")
|
||||
|
||||
if isCITest() && slices.Contains(blockedCIExchanges, name) {
|
||||
t.Skipf("skipping %s due to CI test restrictions", name)
|
||||
@@ -382,40 +380,18 @@ func TestGetDefaultConfigurations(t *testing.T) {
|
||||
}
|
||||
|
||||
defaultCfg, err := exchange.GetDefaultConfig(context.Background(), exch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if defaultCfg == nil {
|
||||
t.Fatal("expected config")
|
||||
}
|
||||
|
||||
if defaultCfg.Name == "" {
|
||||
t.Error("name unset SetDefaults() not called")
|
||||
}
|
||||
|
||||
if !defaultCfg.Enabled {
|
||||
t.Error("expected enabled", defaultCfg.Name)
|
||||
}
|
||||
require.NoError(t, err, "GetDefaultConfig must not error")
|
||||
require.NotNil(t, defaultCfg)
|
||||
assert.NotEmpty(t, defaultCfg.Name, "Name should not be empty")
|
||||
assert.True(t, defaultCfg.Enabled, "Enabled should have the correct value")
|
||||
|
||||
if exch.SupportsWebsocket() {
|
||||
if defaultCfg.WebsocketResponseCheckTimeout <= 0 {
|
||||
t.Error("expected websocketResponseCheckTimeout to be greater than 0", defaultCfg.Name)
|
||||
}
|
||||
|
||||
if defaultCfg.WebsocketResponseMaxLimit <= 0 {
|
||||
t.Error("expected WebsocketResponseMaxLimit to be greater than 0", defaultCfg.Name)
|
||||
}
|
||||
|
||||
if defaultCfg.WebsocketTrafficTimeout <= 0 {
|
||||
t.Error("expected WebsocketTrafficTimeout to be greater than 0", defaultCfg.Name)
|
||||
}
|
||||
assert.Positive(t, defaultCfg.WebsocketResponseCheckTimeout, "WebsocketResponseCheckTimeout should be positive")
|
||||
assert.Positive(t, defaultCfg.WebsocketResponseMaxLimit, "WebsocketResponseMaxLimit should be positive")
|
||||
assert.Positive(t, defaultCfg.WebsocketTrafficTimeout, "WebsocketTrafficTimeout should be positive")
|
||||
}
|
||||
|
||||
// Makes sure the config is valid and can be used to setup the exchange
|
||||
if err := exch.Setup(defaultCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, exch.Setup(defaultCfg), "Setup must not error")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ type ExchangeTuningSettings struct {
|
||||
|
||||
// GCTScriptSettings defines settings related to the GCTScript virtual machine
|
||||
type GCTScriptSettings struct {
|
||||
MaxVirtualMachines uint
|
||||
MaxVirtualMachines uint64
|
||||
}
|
||||
|
||||
// WithdrawSettings defines settings related to Withdrawing cryptocurrency
|
||||
|
||||
@@ -1796,7 +1796,7 @@ func (s *RPCServer) WithdrawalEventByID(_ context.Context, r *gctrpc.WithdrawalE
|
||||
Currency: v.RequestDetails.Currency.String(),
|
||||
Description: v.RequestDetails.Description,
|
||||
Amount: v.RequestDetails.Amount,
|
||||
Type: int32(v.RequestDetails.Type),
|
||||
Type: int64(v.RequestDetails.Type),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -3622,7 +3622,7 @@ func parseMultipleEvents(ret []*withdraw.Response) *gctrpc.WithdrawalEventsByExc
|
||||
Currency: ret[x].RequestDetails.Currency.String(),
|
||||
Description: ret[x].RequestDetails.Description,
|
||||
Amount: ret[x].RequestDetails.Amount,
|
||||
Type: int32(ret[x].RequestDetails.Type),
|
||||
Type: int64(ret[x].RequestDetails.Type),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3708,7 +3708,7 @@ func parseSingleEvents(ret *withdraw.Response) *gctrpc.WithdrawalEventsByExchang
|
||||
Currency: ret.RequestDetails.Currency.String(),
|
||||
Description: ret.RequestDetails.Description,
|
||||
Amount: ret.RequestDetails.Amount,
|
||||
Type: int32(ret.RequestDetails.Type),
|
||||
Type: int64(ret.RequestDetails.Type),
|
||||
},
|
||||
}
|
||||
tempEvent.CreatedAt = timestamppb.New(ret.CreatedAt)
|
||||
@@ -5058,7 +5058,7 @@ func (s *RPCServer) GetTechnicalAnalysis(ctx context.Context, r *gctrpc.GetTechn
|
||||
bollinger, err = klines.GetBollingerBands(r.Period,
|
||||
r.StandardDeviationUp,
|
||||
r.StandardDeviationDown,
|
||||
indicators.MaType(r.MovingAverageType))
|
||||
indicators.MaType(r.MovingAverageType)) //nolint:gosec // TODO: Make var types consistent
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1945,35 +1945,18 @@ func TestGetDataHistoryJobSummary(t *testing.T) {
|
||||
EndDate: time.Now().UTC(),
|
||||
Interval: kline.OneMin,
|
||||
}
|
||||
|
||||
err := m.UpsertJob(dhj, false)
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v, expected %v", err, nil)
|
||||
}
|
||||
|
||||
_, err = s.GetDataHistoryJobSummary(context.Background(), nil)
|
||||
if !errors.Is(err, errNilRequestData) {
|
||||
t.Errorf("received %v, expected %v", err, errNilRequestData)
|
||||
}
|
||||
assert.NoError(t, m.UpsertJob(dhj, false), "UpsertJob should not error")
|
||||
_, err := s.GetDataHistoryJobSummary(context.Background(), nil)
|
||||
assert.ErrorIs(t, err, errNilRequestData)
|
||||
|
||||
_, err = s.GetDataHistoryJobSummary(context.Background(), &gctrpc.GetDataHistoryJobDetailsRequest{})
|
||||
if !errors.Is(err, errNicknameUnset) {
|
||||
t.Errorf("received %v, expected %v", err, errNicknameUnset)
|
||||
}
|
||||
assert.ErrorIs(t, err, errNicknameUnset)
|
||||
|
||||
resp, err := s.GetDataHistoryJobSummary(context.Background(), &gctrpc.GetDataHistoryJobDetailsRequest{Nickname: "TestGetDataHistoryJobSummary"})
|
||||
if !errors.Is(err, nil) {
|
||||
t.Errorf("received %v, expected %v", err, nil)
|
||||
}
|
||||
if resp == nil { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
|
||||
t.Fatal("expected job")
|
||||
}
|
||||
if resp.Nickname == "" {
|
||||
t.Fatalf("received %v, expected %v", "", dhj.Nickname)
|
||||
}
|
||||
if resp.ResultSummaries == nil { //nolint:staticcheck,nolintlint // SA5011 Ignore the nil warnings
|
||||
t.Fatalf("received %v, expected %v", nil, "result summaries slice")
|
||||
}
|
||||
assert.NoError(t, err, "GetDataHistoryJobSummary should not error")
|
||||
require.NotNil(t, resp)
|
||||
assert.NotEmpty(t, resp.Nickname)
|
||||
assert.NotEmpty(t, resp.ResultSummaries)
|
||||
}
|
||||
|
||||
func TestGetManagedOrders(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user