Skip to content

Commit

Permalink
Merge pull request #1763 from lanphan/obsoleted
Browse files Browse the repository at this point in the history
CHORE: solved all deprecated, comment all unused variables and functions
  • Loading branch information
c9s authored Oct 22, 2024
2 parents dcf2f52 + 8b17d78 commit b23c7a7
Show file tree
Hide file tree
Showing 29 changed files with 53 additions and 91 deletions.
4 changes: 2 additions & 2 deletions pkg/accounting/cost_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package accounting

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,7 +16,7 @@ func TestStockManager(t *testing.T) {
t.Run("testdata", func(t *testing.T) {
var trades []types.Trade

out, err := ioutil.ReadFile("testdata/btcusdt-trades.json")
out, err := os.ReadFile("testdata/btcusdt-trades.json")
assert.NoError(t, err)

err = json.Unmarshal(out, &trades)
Expand Down
6 changes: 0 additions & 6 deletions pkg/backtest/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ func (e *Exchange) resetMatchingBooks() {
e.matchingBooksMutex.Unlock()
}

func (e *Exchange) addMatchingBook(symbol string, market types.Market) {
e.matchingBooksMutex.Lock()
e._addMatchingBook(symbol, market)
e.matchingBooksMutex.Unlock()
}

func (e *Exchange) _addMatchingBook(symbol string, market types.Market) {
matching := &SimplePriceMatching{
currentTime: e.currentTime,
Expand Down
1 change: 1 addition & 0 deletions pkg/backtest/matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func init() {
}

// SimplePriceMatching implements a simple kline data driven matching engine for backtest
//
//go:generate callbackgen -type SimplePriceMatching
type SimplePriceMatching struct {
Symbol string
Expand Down
5 changes: 2 additions & 3 deletions pkg/backtest/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package backtest
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -55,7 +54,7 @@ type SummaryReport struct {
}

func ReadSummaryReport(filename string) (*SummaryReport, error) {
o, err := ioutil.ReadFile(filename)
o, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -247,7 +246,7 @@ func loadReportIndexLocked(indexFilePath string) (*ReportIndex, error) {
if fileInfo, err := os.Stat(indexFilePath); err != nil {
return nil, err
} else if fileInfo.Size() != 0 {
o, err := ioutil.ReadFile(indexFilePath)
o, err := os.ReadFile(indexFilePath)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/bbgo/activeorderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (b *ActiveOrderBook) BindStream(stream types.Stream) {
stream.OnOrderUpdate(b.orderUpdateHandler)
}

func (b *ActiveOrderBook) waitClear(
func (b *ActiveOrderBook) waitOrderClear(
ctx context.Context, order types.Order, waitTime, timeout time.Duration,
) (bool, error) {
if !b.orders.Exists(order.OrderID) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/bbgo/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -51,7 +50,7 @@ func generateRunFile(filepath string, config *Config, imports []string) error {
return err
}

return ioutil.WriteFile(filepath, buf.Bytes(), 0644)
return os.WriteFile(filepath, buf.Bytes(), 0644)
}

// compilePackage generates the main.go file of the wrapper package
Expand Down Expand Up @@ -80,7 +79,7 @@ func Build(ctx context.Context, userConfig *Config, targetConfig BuildTargetConf
buildDir = "build"
}

packageDir, err := ioutil.TempDir(buildDir, "bbgow-") // with prefix bbgow
packageDir, err := os.MkdirTemp(buildDir, "bbgow-") // with prefix bbgow
if err != nil {
return "", err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/bbgo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -496,7 +496,7 @@ func loadStash(config []byte) (Stash, error) {
func LoadBuildConfig(configFile string) (*Config, error) {
var config Config

content, err := ioutil.ReadFile(configFile)
content, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -526,7 +526,7 @@ func LoadBuildConfig(configFile string) (*Config, error) {
func Load(configFile string, loadStrategies bool) (*Config, error) {
var config Config

content, err := ioutil.ReadFile(configFile)
content, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/bbgo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bbgo

import (
"context"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestLoadConfig(t *testing.T) {
yamlText, err := config.YAML()
assert.NoError(t, err)

yamlTextSource, err := ioutil.ReadFile("testdata/strategy.yaml")
yamlTextSource, err := os.ReadFile("testdata/strategy.yaml")
assert.NoError(t, err)

var sourceMap map[string]interface{}
Expand Down
7 changes: 2 additions & 5 deletions pkg/bbgo/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"image/png"
"io/ioutil"
stdlog "log"
"math/rand"
"os"
Expand Down Expand Up @@ -34,7 +33,7 @@ import (

func init() {
// randomize pulling
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
}

var defaultSyncBufferPeriod = 30 * time.Minute
Expand Down Expand Up @@ -69,8 +68,6 @@ func RegisterStrategy(key string, s interface{}) {
}
}

var emptyTime time.Time

type SyncStatus int

const (
Expand Down Expand Up @@ -971,7 +968,7 @@ func writeOTPKeyAsQRCodePNG(key *otp.Key, imagePath string) error {
return err
}

if err := ioutil.WriteFile(imagePath, buf.Bytes(), 0644); err != nil {
if err := os.WriteFile(imagePath, buf.Bytes(), 0644); err != nil {
return err
}

Expand Down
15 changes: 0 additions & 15 deletions pkg/bbgo/interact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"path"
"reflect"
"strconv"
"strings"

"github.com/c9s/bbgo/pkg/dynamic"
"github.com/c9s/bbgo/pkg/fixedpoint"
Expand Down Expand Up @@ -556,19 +554,6 @@ func getStrategySignature(strategy SingleExchangeStrategy) (string, error) {
return signature, nil
}

func parseFloatPercent(s string, bitSize int) (f float64, err error) {
i := strings.Index(s, "%")
if i < 0 {
return strconv.ParseFloat(s, bitSize)
}

f, err = strconv.ParseFloat(s[:i], bitSize)
if err != nil {
return 0, err
}
return f / 100.0, nil
}

func getStrategySignatures(exchangeStrategies map[string]SingleExchangeStrategy) []string {
var strategies []string
for signature := range exchangeStrategies {
Expand Down
3 changes: 0 additions & 3 deletions pkg/bbgo/order_executor_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bbgo
import (
"context"

log "github.com/sirupsen/logrus"
"go.uber.org/multierr"

"github.com/c9s/bbgo/pkg/core"
Expand All @@ -14,8 +13,6 @@ import (
// This order executor does not handle position and profit stats update
type SimpleOrderExecutor struct {
BaseOrderExecutor

logger log.FieldLogger
}

func NewSimpleOrderExecutor(session *ExchangeSession) *SimpleOrderExecutor {
Expand Down
5 changes: 2 additions & 3 deletions pkg/bbgo/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ type PnLReporter interface {
}

type baseReporter struct {
notifier Notifier
cron *cron.Cron
environment *Environment
notifier Notifier
cron *cron.Cron
}

type PnLReporterManager struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
var err error
if util.SetEnvVarBool("DISABLE_MARKETS_CACHE", &disableMarketsCache); disableMarketsCache {
markets, err = session.Exchange.QueryMarkets(ctx)
if err != nil {
return err
}
} else {
markets, err = cache.LoadExchangeMarketsWithCache(ctx, session.Exchange)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -99,7 +98,7 @@ func WithCache(key string, obj interface{}, fetcher DataFetcher) error {
return err
}

if err := ioutil.WriteFile(cacheFile, out, 0666); err != nil {
if err := os.WriteFile(cacheFile, out, 0666); err != nil {
return err
}

Expand All @@ -113,7 +112,7 @@ func WithCache(key string, obj interface{}, fetcher DataFetcher) error {
} else {
log.Debugf("cache %s found", cacheFile)

data, err := ioutil.ReadFile(cacheFile)
data, err := os.ReadFile(cacheFile)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cmd/hoptimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/c9s/bbgo/pkg/optimizer"
"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"os/signal"
"syscall"
"time"
)

func init() {
Expand Down Expand Up @@ -69,7 +69,7 @@ var hoptimizeCmd = &cobra.Command{
return err
}

yamlBody, err := ioutil.ReadFile(configFile)
yamlBody, err := os.ReadFile(configFile)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/margin.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var marginCmd = &cobra.Command{
Short: "margin related history",
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := cobraLoadDotenv(cmd, args); err != nil {
if err := cobraLoadDotenv(cmd); err != nil {
return err
}

if err := cobraLoadConfig(cmd, args); err != nil {
if err := cobraLoadConfig(cmd); err != nil {
return err
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -60,7 +59,7 @@ var optimizeCmd = &cobra.Command{
return err
}

yamlBody, err := ioutil.ReadFile(configFile)
yamlBody, err := os.ReadFile(configFile)
if err != nil {
return err
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/c9s/bbgo/pkg/util"

_ "time/tzdata"

_ "github.com/go-sql-driver/mysql"
)

var cpuProfileFile *os.File
Expand All @@ -38,7 +36,7 @@ var RootCmd = &cobra.Command{
SilenceUsage: true,

PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := cobraLoadDotenv(cmd, args); err != nil {
if err := cobraLoadDotenv(cmd); err != nil {
return err
}

Expand Down Expand Up @@ -101,7 +99,7 @@ var RootCmd = &cobra.Command{
}
}

return cobraLoadConfig(cmd, args)
return cobraLoadConfig(cmd)
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
pprof.StopCPUProfile()
Expand All @@ -116,7 +114,7 @@ var RootCmd = &cobra.Command{
},
}

func cobraLoadDotenv(cmd *cobra.Command, args []string) error {
func cobraLoadDotenv(cmd *cobra.Command) error {
disableDotEnv, err := cmd.Flags().GetBool("no-dotenv")
if err != nil {
return err
Expand All @@ -137,7 +135,7 @@ func cobraLoadDotenv(cmd *cobra.Command, args []string) error {
return nil
}

func cobraLoadConfig(cmd *cobra.Command, args []string) error {
func cobraLoadConfig(cmd *cobra.Command) error {
configFile, err := cmd.Flags().GetString("config")
if err != nil {
return errors.Wrapf(err, "failed to get the config flag")
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -308,7 +307,7 @@ func runWrapperBinary(ctx context.Context, cmd *cobra.Command, userConfig *bbgo.

// buildAndRun builds the package natively and run the binary with the given args
func buildAndRun(ctx context.Context, userConfig *bbgo.Config, args ...string) (*exec.Cmd, error) {
packageDir, err := ioutil.TempDir("build", "bbgow")
packageDir, err := os.MkdirTemp("build", "bbgow")
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit b23c7a7

Please sign in to comment.