fix: apply gofmt on all files, add revive action

This commit is contained in:
zenix 2022-06-17 13:01:15 +09:00
parent 1000214c1e
commit 55fa4cc8f1
71 changed files with 2650 additions and 2680 deletions

View File

@ -72,6 +72,12 @@ jobs:
go test -race -coverprofile coverage_dnum.txt -covermode atomic -tags dnum ./pkg/... go test -race -coverprofile coverage_dnum.txt -covermode atomic -tags dnum ./pkg/...
sed -i -e '/_requestgen.go/d' coverage_dnum.txt sed -i -e '/_requestgen.go/d' coverage_dnum.txt
- name: Revive Check
uses: morphy2k/revive-action@v2
with:
reporter: github-pr-review
fail_on_error: true
- name: Upload Coverage Report - name: Upload Coverage Report
uses: codecov/codecov-action@v3 uses: codecov/codecov-action@v3
with: with:

View File

@ -1,12 +1,12 @@
package main package main
import ( import (
"fmt"
"github.com/c9s/bbgo/pkg/cmd" "github.com/c9s/bbgo/pkg/cmd"
"github.com/spf13/cobra/doc" "github.com/spf13/cobra/doc"
"log"
"path" "path"
"runtime" "runtime"
"fmt"
"log"
) )
func main() { func main() {

View File

@ -39,4 +39,3 @@ var accountsCmd = &cobra.Command{
return nil return nil
}, },
} }

View File

@ -32,7 +32,6 @@ func init() {
ordersCmd.AddCommand(historyOrdersCmd) ordersCmd.AddCommand(historyOrdersCmd)
} }
// go run ./examples/kucoin orders // go run ./examples/kucoin orders
var ordersCmd = &cobra.Command{ var ordersCmd = &cobra.Command{
Use: "orders", Use: "orders",
@ -73,7 +72,6 @@ var ordersCmd = &cobra.Command{
}, },
} }
// go run ./examples/kucoin orders history // go run ./examples/kucoin orders history
var historyOrdersCmd = &cobra.Command{ var historyOrdersCmd = &cobra.Command{
Use: "history [--symbol SYMBOL]", Use: "history [--symbol SYMBOL]",
@ -105,7 +103,6 @@ var historyOrdersCmd = &cobra.Command{
}, },
} }
// usage: // usage:
// go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy // go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy
var placeOrderCmd = &cobra.Command{ var placeOrderCmd = &cobra.Command{
@ -124,14 +121,12 @@ var placeOrderCmd = &cobra.Command{
req.OrderType(kucoinapi.OrderType(orderType)) req.OrderType(kucoinapi.OrderType(orderType))
side, err := cmd.Flags().GetString("side") side, err := cmd.Flags().GetString("side")
if err != nil { if err != nil {
return err return err
} }
req.Side(kucoinapi.SideType(side)) req.Side(kucoinapi.SideType(side))
symbol, err := cmd.Flags().GetString("symbol") symbol, err := cmd.Flags().GetString("symbol")
if err != nil { if err != nil {
return err return err
@ -155,7 +150,6 @@ var placeOrderCmd = &cobra.Command{
} }
size, err := cmd.Flags().GetString("size") size, err := cmd.Flags().GetString("size")
if err != nil { if err != nil {
return err return err
@ -172,8 +166,6 @@ var placeOrderCmd = &cobra.Command{
}, },
} }
// usage: // usage:
var cancelOrderCmd = &cobra.Command{ var cancelOrderCmd = &cobra.Command{
Use: "cancel", Use: "cancel",

View File

@ -25,4 +25,3 @@ var symbolsCmd = &cobra.Command{
return nil return nil
}, },
} }

View File

@ -36,7 +36,6 @@ var tickersCmd = &cobra.Command{
logrus.Infof("ticker: %+v", ticker) logrus.Infof("ticker: %+v", ticker)
tickerStats, err := client.MarketDataService.GetTicker24HStat(args[0]) tickerStats, err := client.MarketDataService.GetTicker24HStat(args[0])
if err != nil { if err != nil {
return err return err
@ -46,4 +45,3 @@ var tickersCmd = &cobra.Command{
return nil return nil
}, },
} }

View File

@ -131,7 +131,6 @@ var websocketCmd = &cobra.Command{
logrus.WithError(err).Error("websocket ping error", err) logrus.WithError(err).Error("websocket ping error", err)
} }
case <-interrupt: case <-interrupt:
logrus.Infof("interrupt") logrus.Infof("interrupt")

View File

@ -69,7 +69,6 @@ var rootCmd = &cobra.Command{
log.Infof("%+v", account) log.Infof("%+v", account)
log.Infof("ASSET BALANCES:") log.Infof("ASSET BALANCES:")
assetBalances, err := client.AssetBalances() assetBalances, err := client.AssetBalances()
if err != nil { if err != nil {

View File

@ -30,6 +30,7 @@ var klineMatchingLogger *logrus.Entry = nil
// FeeToken is used to simulate the exchange platform fee token // FeeToken is used to simulate the exchange platform fee token
// This is to ease the back-testing environment for closing positions. // This is to ease the back-testing environment for closing positions.
const FeeToken = "FEE" const FeeToken = "FEE"
var useFeeToken = true var useFeeToken = true
func init() { func init() {

View File

@ -34,7 +34,6 @@ func TestStateRecorder(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Len(t, recorder.writers, 1) assert.Len(t, recorder.writers, 1)
st.Position.AddTrade(types.Trade{ st.Position.AddTrade(types.Trade{
OrderID: 1, OrderID: 1,
Exchange: types.ExchangeBinance, Exchange: types.ExchangeBinance,

View File

@ -69,4 +69,3 @@ func (m *Notifiability) NotifyTo(channel string, obj interface{}, args ...interf
n.NotifyTo(channel, obj, args...) n.NotifyTo(channel, obj, args...)
} }
} }

View File

@ -1,2 +1 @@
package bbgo package bbgo

View File

@ -100,4 +100,3 @@ func newTypeValueInterface(typ reflect.Type) interface{} {
dst := reflect.New(typ) dst := reflect.New(typ)
return dst.Interface() return dst.Interface()
} }

View File

@ -1,2 +1 @@
package bbgo package bbgo

View File

@ -1,2 +1 @@
package cmdutil package cmdutil

View File

@ -1,2 +1 @@
package batch package batch

View File

@ -84,7 +84,6 @@ func TestClient_NewSpotRebateHistoryRequest(t *testing.T) {
t.Logf("spot rebate history: %+v", history) t.Logf("spot rebate history: %+v", history)
} }
func TestClient_NewGetMarginInterestRateHistoryRequest(t *testing.T) { func TestClient_NewGetMarginInterestRateHistoryRequest(t *testing.T) {
client := getTestClientOrSkip(t) client := getTestClientOrSkip(t)
ctx := context.Background() ctx := context.Background()
@ -131,7 +130,7 @@ func TestClient_privateCall(t *testing.T) {
assert.NotEmpty(t, feeStructs) assert.NotEmpty(t, feeStructs)
} }
} else { } else {
dump, _ := httputil.DumpRequest(req, true); dump, _ := httputil.DumpRequest(req, true)
log.Printf("request: %s", dump) log.Printf("request: %s", dump)
} }
} }

View File

@ -119,4 +119,3 @@ func Test_toLocalOrderTypeWithMarket(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, ftxapi.OrderTypeMarket, orderType) assert.Equal(t, ftxapi.OrderTypeMarket, orderType)
} }

View File

@ -66,7 +66,6 @@ func (c *RestClient) NewGetPositionsRequest() *GetPositionsRequest {
} }
} }
type Balance struct { type Balance struct {
Coin string `json:"coin"` Coin string `json:"coin"`
Free fixedpoint.Value `json:"free"` Free fixedpoint.Value `json:"free"`

View File

@ -200,5 +200,3 @@ func castPayload(payload interface{}) ([]byte, error) {
return nil, nil return nil, nil
} }

View File

@ -33,6 +33,7 @@ type Market struct {
SizeIncrement fixedpoint.Value `json:"sizeIncrement"` SizeIncrement fixedpoint.Value `json:"sizeIncrement"`
Restricted bool `json:"restricted"` Restricted bool `json:"restricted"`
} }
//go:generate GetRequest -url "api/markets" -type GetMarketsRequest -responseDataType []Market //go:generate GetRequest -url "api/markets" -type GetMarketsRequest -responseDataType []Market
type GetMarketsRequest struct { type GetMarketsRequest struct {
client requestgen.APIClient client requestgen.APIClient

View File

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
package main package main

View File

@ -5,8 +5,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
) )
// ex: 2019-03-05T09:56:55.728933+00:00 // ex: 2019-03-05T09:56:55.728933+00:00

View File

@ -42,4 +42,3 @@ func (r *walletRequest) DepositHistory(ctx context.Context, since time.Time, unt
return d, nil return d, nil
} }

View File

@ -1,5 +1,6 @@
// Code generated by go generate; DO NOT EDIT. // Code generated by go generate; DO NOT EDIT.
package ftx package ftx
var symbolMap = map[string]string{ var symbolMap = map[string]string{
"1INCH-0325": "1INCH-0325", "1INCH-0325": "1INCH-0325",
"1INCH-PERP": "1INCH-PERP", "1INCH-PERP": "1INCH-PERP",

View File

@ -245,4 +245,3 @@ func toGlobalTrade(fill kucoinapi.Fill) types.Trade {
} }
return trade return trade
} }

View File

@ -61,7 +61,6 @@ type GetPublicBulletRequest struct {
client requestgen.APIClient client requestgen.APIClient
} }
//go:generate requestgen -type GetPrivateBulletRequest -method "POST" -url "/api/v1/bullet-private" -responseType .APIResponse -responseDataField Data -responseDataType .Bullet //go:generate requestgen -type GetPrivateBulletRequest -method "POST" -url "/api/v1/bullet-private" -responseType .APIResponse -responseDataField Data -responseDataType .Bullet
type GetPrivateBulletRequest struct { type GetPrivateBulletRequest struct {
client requestgen.AuthenticatedAPIClient client requestgen.AuthenticatedAPIClient

View File

@ -9,9 +9,9 @@ import (
"github.com/c9s/bbgo/pkg/depth" "github.com/c9s/bbgo/pkg/depth"
"github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi" "github.com/c9s/bbgo/pkg/exchange/kucoin/kucoinapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util" "github.com/c9s/bbgo/pkg/util"
"github.com/c9s/bbgo/pkg/fixedpoint"
) )
const readTimeout = 30 * time.Second const readTimeout = 30 * time.Second

View File

@ -110,4 +110,3 @@ func TestAccountService_NewGetDepositHistoryRequest(t *testing.T) {
assert.NotEmpty(t, deposits) assert.NotEmpty(t, deposits)
t.Logf("deposits: %+v", deposits) t.Logf("deposits: %+v", deposits)
} }

View File

@ -22,5 +22,3 @@ func integrationTestConfigured(t *testing.T, prefix string) (key, secret string,
} }
return key, secret, ok return key, secret, ok
} }

View File

@ -158,4 +158,3 @@ type MarginRepayRequest struct {
currency string `param:"currency,slug,required"` currency string `param:"currency,slug,required"`
amount string `param:"amount"` amount string `param:"amount"`
} }

View File

@ -28,4 +28,3 @@ type WebsocketCommand struct {
Action string `json:"action"` Action string `json:"action"`
Subscriptions []Subscription `json:"subscriptions,omitempty"` Subscriptions []Subscription `json:"subscriptions,omitempty"`
} }

View File

@ -31,7 +31,6 @@ func TestExchange_QueryTickers_SomeSymbols(t *testing.T) {
return return
} }
e := New(key, secret) e := New(key, secret)
got, err := e.QueryTickers(context.Background(), "BTCUSDT", "ETHUSDT") got, err := e.QueryTickers(context.Background(), "BTCUSDT", "ETHUSDT")
if assert.NoError(t, err) { if assert.NoError(t, err) {

View File

@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
package main package main

View File

@ -514,4 +514,3 @@ var spotSymbolMap = map[string]string{
"ZRXUSDT": "ZRX-USDT", "ZRXUSDT": "ZRX-USDT",
"ZYROUSDT": "ZYRO-USDT", "ZYROUSDT": "ZYRO-USDT",
} }

View File

@ -1,10 +1,10 @@
package fixedpoint package fixedpoint
import ( import (
"encoding/json"
"github.com/stretchr/testify/assert"
"math/big" "math/big"
"testing" "testing"
"github.com/stretchr/testify/assert"
"encoding/json"
) )
const Delta = 1e-9 const Delta = 1e-9
@ -167,7 +167,6 @@ func TestJson(t *testing.T) {
assert.Equal(t, "0.00000000", p.FormatString(8)) assert.Equal(t, "0.00000000", p.FormatString(8))
assert.Equal(t, "0.00000000", string(e)) assert.Equal(t, "0.00000000", string(e))
_ = json.Unmarshal([]byte("0.00153917575"), &p) _ = json.Unmarshal([]byte("0.00153917575"), &p)
assert.Equal(t, "0.00153917", p.FormatString(8)) assert.Equal(t, "0.00153917", p.FormatString(8))

View File

@ -2,8 +2,8 @@ package indicator
import ( import (
"encoding/json" "encoding/json"
"testing"
"fmt" "fmt"
"testing"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
@ -51,7 +51,11 @@ func Test_DMI(t *testing.T) {
return klines return klines
} }
type output struct{dip float64; dim float64; adx float64} type output struct {
dip float64
dim float64
adx float64
}
tests := []struct { tests := []struct {
name string name string

View File

@ -76,4 +76,3 @@ func (store JsonStore) Save(val interface{}) error {
p := filepath.Join(store.Directory, store.ID) + ".json" p := filepath.Join(store.Directory, store.ID) + ".json"
return ioutil.WriteFile(p, data, 0666) return ioutil.WriteFile(p, data, 0666)
} }

View File

@ -93,8 +93,6 @@ func (s *RewardService) Sync(ctx context.Context, exchange types.Exchange) error
return <-errC return <-errC
} }
type CurrencyPositionMap map[string]fixedpoint.Value type CurrencyPositionMap map[string]fixedpoint.Value
func (s *RewardService) AggregateUnspentCurrencyPosition(ctx context.Context, ex types.ExchangeName, since time.Time) (CurrencyPositionMap, error) { func (s *RewardService) AggregateUnspentCurrencyPosition(ctx context.Context, ex types.ExchangeName, since time.Time) (CurrencyPositionMap, error) {

View File

@ -74,7 +74,6 @@ func TestRewardService_InsertAndQueryUnspent(t *testing.T) {
assert.Equal(t, types.RewardCommission, rewards[0].Type) assert.Equal(t, types.RewardCommission, rewards[0].Type)
} }
func TestRewardService_AggregateUnspentCurrencyPosition(t *testing.T) { func TestRewardService_AggregateUnspentCurrencyPosition(t *testing.T) {
db, err := prepareDB(t) db, err := prepareDB(t)
if err != nil { if err != nil {

View File

@ -7,8 +7,8 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
) )
func TestWithdrawService(t *testing.T) { func TestWithdrawService(t *testing.T) {

View File

@ -340,7 +340,6 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
log.WithError(err).Errorf("can not place order") log.WithError(err).Errorf("can not place order")
} }
if err := s.activeAdjustmentOrders.GracefulCancel(ctx, s.session.Exchange); err != nil { if err := s.activeAdjustmentOrders.GracefulCancel(ctx, s.session.Exchange); err != nil {
log.WithError(err).Errorf("graceful cancel order error") log.WithError(err).Errorf("graceful cancel order error")
} }

View File

@ -125,7 +125,7 @@ func Test_formatPrice(t *testing.T) {
binanceFormatRE := regexp.MustCompile("^([0-9]{1,20})(.[0-9]{1,20})?$") binanceFormatRE := regexp.MustCompile("^([0-9]{1,20})(.[0-9]{1,20})?$")
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := formatPrice(tt.args.price, tt.args.tickSize); got := formatPrice(tt.args.price, tt.args.tickSize)
if got != tt.want { if got != tt.want {
t.Errorf("formatPrice() = %v, want %v", got, tt.want) t.Errorf("formatPrice() = %v, want %v", got, tt.want)
} }
@ -135,7 +135,6 @@ func Test_formatPrice(t *testing.T) {
} }
} }
func Test_formatQuantity(t *testing.T) { func Test_formatQuantity(t *testing.T) {
type args struct { type args struct {
quantity fixedpoint.Value quantity fixedpoint.Value
@ -183,7 +182,7 @@ func Test_formatQuantity(t *testing.T) {
binanceFormatRE := regexp.MustCompile("^([0-9]{1,20})(.[0-9]{1,20})?$") binanceFormatRE := regexp.MustCompile("^([0-9]{1,20})(.[0-9]{1,20})?$")
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := formatQuantity(tt.args.quantity, tt.args.tickSize); got := formatQuantity(tt.args.quantity, tt.args.tickSize)
if got != tt.want { if got != tt.want {
t.Errorf("formatQuantity() = %v, want %v", got, tt.want) t.Errorf("formatQuantity() = %v, want %v", got, tt.want)
} }

View File

@ -227,7 +227,6 @@ func NewProfitStats(market Market) *ProfitStats {
} }
} }
func (s *ProfitStats) Init(market Market) { func (s *ProfitStats) Init(market Market) {
s.Symbol = market.Symbol s.Symbol = market.Symbol
s.BaseCurrency = market.BaseCurrency s.BaseCurrency = market.BaseCurrency

View File

@ -1,2 +1 @@
package util package util

View File

@ -1,3 +1,4 @@
//go:build !release
// +build !release // +build !release
package version package version
@ -5,4 +6,3 @@ package version
const Version = "v1.35.0-daaa3352-dev" const Version = "v1.35.0-daaa3352-dev"
const VersionGitRef = "daaa3352" const VersionGitRef = "daaa3352"

View File

@ -1,3 +1,4 @@
//go:build release
// +build release // +build release
package version package version
@ -5,4 +6,3 @@ package version
const Version = "v1.35.0-daaa3352" const Version = "v1.35.0-daaa3352"
const VersionGitRef = "daaa3352" const VersionGitRef = "daaa3352"