Skip to content

Commit

Permalink
fix: apply gofmt on all files, add revive action
Browse files Browse the repository at this point in the history
  • Loading branch information
zenixls2 committed Jun 17, 2022
1 parent 1000214 commit 55fa4cc
Show file tree
Hide file tree
Showing 71 changed files with 2,650 additions and 2,680 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
go test -race -coverprofile coverage_dnum.txt -covermode atomic -tags dnum ./pkg/...
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
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion cmd/bbgo-lorca/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
return
}

if err := trader.LoadState() ; err != nil {
if err := trader.LoadState(); err != nil {
log.WithError(err).Error("failed to load strategy states")
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/bbgo-webview/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func main() {
return
}

if err := trader.LoadState() ; err != nil {
if err := trader.LoadState(); err != nil {
log.WithError(err).Error("failed to load strategy states")
return
}
Expand All @@ -123,7 +123,7 @@ func main() {
}

// find a free port for binding the server
ln, err := net.Listen("tcp", "127.0.0.1:" + strconv.Itoa(portNum))
ln, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(portNum))
if err != nil {
log.WithError(err).Error("can not bind listener")
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/update-doc/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"fmt"
"github.com/c9s/bbgo/pkg/cmd"
"github.com/spf13/cobra/doc"
"log"
"path"
"runtime"
"fmt"
"log"
)

func main() {
Expand Down
1 change: 0 additions & 1 deletion examples/kucoin/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ var accountsCmd = &cobra.Command{
return nil
},
}

8 changes: 0 additions & 8 deletions examples/kucoin/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func init() {
ordersCmd.AddCommand(historyOrdersCmd)
}


// go run ./examples/kucoin orders
var ordersCmd = &cobra.Command{
Use: "orders",
Expand Down Expand Up @@ -73,7 +72,6 @@ var ordersCmd = &cobra.Command{
},
}


// go run ./examples/kucoin orders history
var historyOrdersCmd = &cobra.Command{
Use: "history [--symbol SYMBOL]",
Expand Down Expand Up @@ -105,7 +103,6 @@ var historyOrdersCmd = &cobra.Command{
},
}


// usage:
// go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy
var placeOrderCmd = &cobra.Command{
Expand All @@ -124,14 +121,12 @@ var placeOrderCmd = &cobra.Command{

req.OrderType(kucoinapi.OrderType(orderType))


side, err := cmd.Flags().GetString("side")
if err != nil {
return err
}
req.Side(kucoinapi.SideType(side))


symbol, err := cmd.Flags().GetString("symbol")
if err != nil {
return err
Expand All @@ -155,7 +150,6 @@ var placeOrderCmd = &cobra.Command{

}


size, err := cmd.Flags().GetString("size")
if err != nil {
return err
Expand All @@ -172,8 +166,6 @@ var placeOrderCmd = &cobra.Command{
},
}



// usage:
var cancelOrderCmd = &cobra.Command{
Use: "cancel",
Expand Down
1 change: 0 additions & 1 deletion examples/kucoin/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ var symbolsCmd = &cobra.Command{
return nil
},
}

2 changes: 0 additions & 2 deletions examples/kucoin/tickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var tickersCmd = &cobra.Command{

logrus.Infof("ticker: %+v", ticker)


tickerStats, err := client.MarketDataService.GetTicker24HStat(args[0])
if err != nil {
return err
Expand All @@ -46,4 +45,3 @@ var tickersCmd = &cobra.Command{
return nil
},
}

21 changes: 10 additions & 11 deletions examples/kucoin/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ var websocketCmd = &cobra.Command{
id := time.Now().UnixNano() / int64(time.Millisecond)
wsCmds := []kucoin.WebSocketCommand{
/*
{
Id: id+1,
Type: "subscribe",
Topic: "/market/ticker:ETH-USDT",
PrivateChannel: false,
Response: true,
},
{
Id: id+1,
Type: "subscribe",
Topic: "/market/ticker:ETH-USDT",
PrivateChannel: false,
Response: true,
},
*/
{
Id: id+2,
Id: id + 2,
Type: "subscribe",
Topic: "/market/candles:ETH-USDT_1min",
PrivateChannel: false,
Expand Down Expand Up @@ -131,7 +131,6 @@ var websocketCmd = &cobra.Command{
logrus.WithError(err).Error("websocket ping error", err)
}


case <-interrupt:
logrus.Infof("interrupt")

Expand All @@ -144,8 +143,8 @@ var websocketCmd = &cobra.Command{
}

select {
case <-done:
case <-time.After(time.Second):
case <-done:
case <-time.After(time.Second):
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion examples/okex-book/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ var rootCmd = &cobra.Command{

log.Infof("%+v", account)


log.Infof("ASSET BALANCES:")
assetBalances, err := client.AssetBalances()
if err != nil {
Expand Down
26 changes: 13 additions & 13 deletions pkg/backtest/dumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ func TestKLineDumper(t *testing.T) {

t1 := time.Now()
err := dumper.Record(types.KLine{
Exchange: types.ExchangeBinance,
Symbol: "BTCUSDT",
StartTime: types.Time(t1),
EndTime: types.Time(t1.Add(time.Minute)),
Interval: types.Interval1m,
Open: fixedpoint.NewFromFloat(1000.0),
High: fixedpoint.NewFromFloat(2000.0),
Low: fixedpoint.NewFromFloat(3000.0),
Close: fixedpoint.NewFromFloat(4000.0),
Volume: fixedpoint.NewFromFloat(5000.0),
QuoteVolume: fixedpoint.NewFromFloat(6000.0),
NumberOfTrades: 10,
Closed: true,
Exchange: types.ExchangeBinance,
Symbol: "BTCUSDT",
StartTime: types.Time(t1),
EndTime: types.Time(t1.Add(time.Minute)),
Interval: types.Interval1m,
Open: fixedpoint.NewFromFloat(1000.0),
High: fixedpoint.NewFromFloat(2000.0),
Low: fixedpoint.NewFromFloat(3000.0),
Close: fixedpoint.NewFromFloat(4000.0),
Volume: fixedpoint.NewFromFloat(5000.0),
QuoteVolume: fixedpoint.NewFromFloat(6000.0),
NumberOfTrades: 10,
Closed: true,
})
assert.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions pkg/backtest/matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var klineMatchingLogger *logrus.Entry = nil
// FeeToken is used to simulate the exchange platform fee token
// This is to ease the back-testing environment for closing positions.
const FeeToken = "FEE"

var useFeeToken = true

func init() {
Expand Down
1 change: 0 additions & 1 deletion pkg/backtest/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestStateRecorder(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, recorder.writers, 1)


st.Position.AddTrade(types.Trade{
OrderID: 1,
Exchange: types.ExchangeBinance,
Expand Down
2 changes: 1 addition & 1 deletion pkg/bbgo/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func (environ *Environment) syncWithUserConfig(ctx context.Context, userConfig *
syncSymbolMap, restSymbols := categorizeSyncSymbol(userConfig.Sync.Symbols)
for _, session := range sessions {
syncSymbols := restSymbols
if ss, ok := syncSymbolMap[session.Name] ; ok {
if ss, ok := syncSymbolMap[session.Name]; ok {
syncSymbols = append(syncSymbols, ss...)
}

Expand Down
1 change: 0 additions & 1 deletion pkg/bbgo/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,3 @@ func (m *Notifiability) NotifyTo(channel string, obj interface{}, args ...interf
n.NotifyTo(channel, obj, args...)
}
}

1 change: 0 additions & 1 deletion pkg/bbgo/profitstats.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package bbgo

1 change: 0 additions & 1 deletion pkg/bbgo/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,3 @@ func newTypeValueInterface(typ reflect.Type) interface{} {
dst := reflect.New(typ)
return dst.Interface()
}

1 change: 0 additions & 1 deletion pkg/bbgo/trader_test.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package bbgo

1 change: 0 additions & 1 deletion pkg/cmd/cmdutil/exchange.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package cmdutil

1 change: 0 additions & 1 deletion pkg/exchange/batch/batch_test.go
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package batch

4 changes: 2 additions & 2 deletions pkg/exchange/batch/margin_interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type MarginInterestBatchQuery struct {

func (e *MarginInterestBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.MarginInterest, errC chan error) {
query := &AsyncTimeRangedBatchQuery{
Type: types.MarginInterest{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
Type: types.MarginInterest{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
JumpIfEmpty: time.Hour * 24 * 30,
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.QueryInterestHistory(ctx, asset, &startTime, &endTime)
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchange/batch/margin_liquidation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type MarginLiquidationBatchQuery struct {

func (e *MarginLiquidationBatchQuery) Query(ctx context.Context, startTime, endTime time.Time) (c chan types.MarginLiquidation, errC chan error) {
query := &AsyncTimeRangedBatchQuery{
Type: types.MarginLiquidation{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
Type: types.MarginLiquidation{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
JumpIfEmpty: time.Hour * 24 * 30,
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.QueryLiquidationHistory(ctx, &startTime, &endTime)
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchange/batch/margin_repay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type MarginRepayBatchQuery struct {

func (e *MarginRepayBatchQuery) Query(ctx context.Context, asset string, startTime, endTime time.Time) (c chan types.MarginRepay, errC chan error) {
query := &AsyncTimeRangedBatchQuery{
Type: types.MarginRepay{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
Type: types.MarginRepay{},
Limiter: rate.NewLimiter(rate.Every(5*time.Second), 2),
JumpIfEmpty: time.Hour * 24 * 30,
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.QueryRepayHistory(ctx, asset, &startTime, &endTime)
Expand Down
2 changes: 1 addition & 1 deletion pkg/exchange/batch/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (e TradeBatchQuery) Query(ctx context.Context, symbol string, options *type
startTime := *options.StartTime
endTime := *options.EndTime
query := &AsyncTimeRangedBatchQuery{
Type: types.Trade{},
Type: types.Trade{},
Q: func(startTime, endTime time.Time) (interface{}, error) {
return e.ExchangeTradeHistoryService.QueryTrades(ctx, symbol, options)
},
Expand Down
7 changes: 3 additions & 4 deletions pkg/exchange/binance/binanceapi/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func TestClient_NewSpotRebateHistoryRequest(t *testing.T) {
t.Logf("spot rebate history: %+v", history)
}


func TestClient_NewGetMarginInterestRateHistoryRequest(t *testing.T) {
client := getTestClientOrSkip(t)
ctx := context.Background()
Expand Down Expand Up @@ -121,8 +120,8 @@ func TestClient_privateCall(t *testing.T) {

resp, err := client.SendRequest(req)
if assert.NoError(t, err) {
var feeStructs []struct{
Symbol string `json:"symbol"`
var feeStructs []struct {
Symbol string `json:"symbol"`
MakerCommission string `json:"makerCommission"`
TakerCommission string `json:"takerCommission"`
}
Expand All @@ -131,7 +130,7 @@ func TestClient_privateCall(t *testing.T) {
assert.NotEmpty(t, feeStructs)
}
} else {
dump, _ := httputil.DumpRequest(req, true);
dump, _ := httputil.DumpRequest(req, true)
log.Printf("request: %s", dump)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchange/binance/binanceapi/get_trade_fee_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
)

type TradeFee struct {
Symbol string `json:"symbol"`
Symbol string `json:"symbol"`
MakerCommission fixedpoint.Value `json:"makerCommission"`
TakerCommission fixedpoint.Value `json:"takerCommission"`
TakerCommission fixedpoint.Value `json:"takerCommission"`
}

//go:generate requestgen -method GET -url "/sapi/v1/asset/tradeFee" -type GetTradeFeeRequest -responseType []TradeFee
Expand Down
1 change: 0 additions & 1 deletion pkg/exchange/ftx/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,3 @@ func Test_toLocalOrderTypeWithMarket(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, ftxapi.OrderTypeMarket, orderType)
}

1 change: 0 additions & 1 deletion pkg/exchange/ftx/ftxapi/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ func (c *RestClient) NewGetPositionsRequest() *GetPositionsRequest {
}
}


type Balance struct {
Coin string `json:"coin"`
Free fixedpoint.Value `json:"free"`
Expand Down
2 changes: 0 additions & 2 deletions pkg/exchange/ftx/ftxapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,3 @@ func castPayload(payload interface{}) ([]byte, error) {

return nil, nil
}


Loading

0 comments on commit 55fa4cc

Please sign in to comment.