Skip to content

Commit

Permalink
CI: Fix golangci-lint linter issues, add prealloc linter and bump ver…
Browse files Browse the repository at this point in the history
…sion depends for Go 1.18 (thrasher-corp#915)

* Bump CI versions

* Specifically set go version as 1.17.x bumps it to 1.18

* Another

* Adjust AppVeyor

* Part 1 of linter issues

* Part 2

* Fix various linters and improvements

* Part 3

* Finishing touches

* Tests and EqualFold

* Fix nitterinos plus bonus requester jobs bump for exchanges with large number of tests

* Fix nitterinos and bump golangci-lint timeout for AppVeyor

* Address nits, ensure all books are returned on err due to syncer regression

* Fix the wiggins

* Fix duplication

* Fix nitterinos
  • Loading branch information
thrasher- authored Apr 20, 2022
1 parent c48e5ea commit 9a4eb9d
Show file tree
Hide file tree
Showing 216 changed files with 3,444 additions and 2,375 deletions.
8 changes: 5 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ environment:
PSQL_SSLMODE: disable
PSQL_SKIPSQLCMD: true
PSQL_TESTDBNAME: gct_dev_ci
stack: go 1.17.x

stack: go 1.17.8 # this is not actually used on Windows images

services:
- postgresql96

init:
- SET PATH=%POSTGRES_PATH%\bin;%PATH%
- set PATH=%POSTGRES_PATH%\bin;%PATH%
- set PATH=C:\go118\bin;%PATH%

install:
- set Path=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%Path%
Expand All @@ -53,7 +55,7 @@ before_test:

test_script:
# test back-end
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
- '%GOPATH%\bin\golangci-lint.exe run --verbose'
- ps: >-
if($env:APPVEYOR_SCHEDULED_BUILD -eq 'true') {
Expand Down
8 changes: 5 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
time: "19:30"
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: npm
directory: "/web"
schedule:
interval: "weekly"
# deprecated for now as it requires a more in-depth overhaul
open-pull-requests-limit: 0

9 changes: 6 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.18.x'
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.42.1
version: v1.45.2
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on: [push, pull_request]
name: CI
env:
GO_VERSION: 1.17.x
GO_VERSION: 1.18.x
jobs:
backend-psql:
name: GoCryptoTrader back-end with PSQL
Expand Down
13 changes: 11 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
run:
timeout: 6m
timeout: 8m
issues-exit-code: 1
tests: true
skip-dirs:
- vendor
- web/
- testdata
- database/models/

linters:
disable-all: true
Expand All @@ -24,12 +25,17 @@ linters:

# disabled by default linters
- asciicheck
- bidichk
- bodyclose
- containedctx
# - contextcheck
# - cyclop
- decorder
- depguard
- dogsled
# - dupl
- durationcheck
- errchkjson
- errname
# - errorlint
# - exhaustive
Expand Down Expand Up @@ -58,10 +64,13 @@ linters:
- gomodguard
- goprintffuncname
- gosec
- grouper
- ifshort
# - importas
# - interfacer // deprecated by its owner
# - ireturn
# - lll
# - maintidx
- makezero
# - maligned
- misspell
Expand All @@ -72,7 +81,7 @@ linters:
- noctx
- nolintlint
# - paralleltest
# - prealloc
- prealloc
- predeclared
# - promlinter
- revive
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17 as build
FROM golang:1.18 as build
WORKDIR /go/src/github.com/thrasher-corp/gocryptotrader
COPY . .
RUN GO111MODULE=on go mod vendor
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LDFLAGS = -ldflags "-w -s"
GCTPKG = github.com/thrasher-corp/gocryptotrader
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.42.1
LINTPKG = github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085
Expand Down
2 changes: 1 addition & 1 deletion backtester/backtest/backtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func (bt *BackTest) loadData(cfg *config.Config, exch gctexchange.IBotExchange,
if cfg.DataSettings.DatabaseData.Path == "" {
cfg.DataSettings.DatabaseData.Path = filepath.Join(gctcommon.GetDefaultDataDir(runtime.GOOS), "database")
}
gctdatabase.DB.DataPath = filepath.Join(cfg.DataSettings.DatabaseData.Path)
gctdatabase.DB.DataPath = cfg.DataSettings.DatabaseData.Path
err = gctdatabase.DB.SetConfig(&cfg.DataSettings.DatabaseData.Config)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions backtester/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/shopspring/decimal"
Expand All @@ -21,7 +21,7 @@ func ReadConfigFromFile(path string) (*Config, error) {
return nil, errors.New("file not found")
}

fileData, err := ioutil.ReadFile(path)
fileData, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down
23 changes: 12 additions & 11 deletions backtester/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/common"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/base"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies/top2bottom2"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/database"
"github.com/thrasher-corp/gocryptotrader/database/drivers"
Expand Down Expand Up @@ -210,7 +211,7 @@ func TestGenerateConfigForDCAAPICandles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-api-candles.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-api-candles.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -288,7 +289,7 @@ func TestGenerateConfigForDCAAPICandlesExchangeLevelFunding(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-api-candles-exchange-level-funding.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-api-candles-exchange-level-funding.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -356,7 +357,7 @@ func TestGenerateConfigForDCAAPITrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-api-trades.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-api-trades.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -429,7 +430,7 @@ func TestGenerateConfigForDCAAPICandlesMultipleCurrencies(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-api-candles-multiple-currencies.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-api-candles-multiple-currencies.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -503,7 +504,7 @@ func TestGenerateConfigForDCAAPICandlesSimultaneousProcessing(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-api-candles-simultaneous-processing.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-api-candles-simultaneous-processing.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -566,7 +567,7 @@ func TestGenerateConfigForDCALiveCandles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-candles-live.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-candles-live.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -645,7 +646,7 @@ func TestGenerateConfigForRSIAPICustomSettings(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "rsi-api-candles.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "rsi-api-candles.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -704,7 +705,7 @@ func TestGenerateConfigForDCACSVCandles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-csv-candles.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-csv-candles.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -759,7 +760,7 @@ func TestGenerateConfigForDCACSVTrades(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-csv-trades.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-csv-trades.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -827,7 +828,7 @@ func TestGenerateConfigForDCADatabaseCandles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "dca-database-candles.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "dca-database-candles.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -956,7 +957,7 @@ func TestGenerateConfigForTop2Bottom2(t *testing.T) {
if err != nil {
t.Fatal(err)
}
err = ioutil.WriteFile(filepath.Join(p, "examples", "t2b2-api-candles-exchange-funding.strat"), result, 0770)
err = os.WriteFile(filepath.Join(p, "examples", "t2b2-api-candles-exchange-funding.strat"), result, file.DefaultPermissionOctal)
if err != nil {
t.Error(err)
}
Expand Down
8 changes: 4 additions & 4 deletions backtester/config/configbuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/backtester/config"
"github.com/thrasher-corp/gocryptotrader/backtester/eventhandlers/strategies"
gctcommon "github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/file"
"github.com/thrasher-corp/gocryptotrader/database"
dbPSQL "github.com/thrasher-corp/gocryptotrader/database/drivers/postgres"
dbsqlite3 "github.com/thrasher-corp/gocryptotrader/database/drivers/sqlite3"
Expand Down Expand Up @@ -141,7 +141,7 @@ func main() {
if path == "" {
path = wd
}
err = ioutil.WriteFile(path, resp, 0770)
err = os.WriteFile(path, resp, file.DefaultPermissionOctal)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -235,10 +235,10 @@ func parseExchangeSettings(reader *bufio.Reader, cfg *config.Config) error {
func parseStrategySettings(cfg *config.Config, reader *bufio.Reader) error {
fmt.Println("Firstly, please select which strategy you wish to use")
strats := strategies.GetStrategies()
var strategiesToUse []string
strategiesToUse := make([]string, len(strats))
for i := range strats {
fmt.Printf("%v. %s\n", i+1, strats[i].Name())
strategiesToUse = append(strategiesToUse, strats[i].Name())
strategiesToUse[i] = strats[i].Name()
}
var err error
cfg.StrategySettings.Name, err = parseStratName(quickParse(reader), strategiesToUse)
Expand Down
11 changes: 6 additions & 5 deletions backtester/data/kline/kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ func (d *DataFromKline) AppendResults(ki *gctkline.Item) {
if d.addedTimes == nil {
d.addedTimes = make(map[time.Time]bool)
}
var klineData []common.DataEventHandler

var gctCandles []gctkline.Candle
for i := range ki.Candles {
if _, ok := d.addedTimes[ki.Candles[i].Time]; !ok {
gctCandles = append(gctCandles, ki.Candles[i])
d.addedTimes[ki.Candles[i].Time] = true
}
}
var candleTimes []time.Time

klineData := make([]common.DataEventHandler, len(gctCandles))
candleTimes := make([]time.Time, len(gctCandles))
for i := range gctCandles {
klineData = append(klineData, &kline.Kline{
klineData[i] = &kline.Kline{
Base: event.Base{
Offset: int64(i + 1),
Exchange: ki.Exchange,
Expand All @@ -84,8 +85,8 @@ func (d *DataFromKline) AppendResults(ki *gctkline.Item) {
Close: decimal.NewFromFloat(gctCandles[i].Close),
Volume: decimal.NewFromFloat(gctCandles[i].Volume),
ValidationIssues: gctCandles[i].ValidationIssues,
})
candleTimes = append(candleTimes, gctCandles[i].Time)
}
candleTimes[i] = gctCandles[i].Time
}
for i := range d.RangeHolder.Ranges {
for j := range d.RangeHolder.Ranges[i].Intervals {
Expand Down
Loading

0 comments on commit 9a4eb9d

Please sign in to comment.