diff --git a/.gitignore b/.gitignore index 543fe0cdc..c1732e82f 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,8 @@ otp*png /.deploy +testoutput + *.swp /pkg/backtest/assets.go diff --git a/.golangci.yml b/.golangci.yml index 081c79221..aba75da15 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,9 @@ run: issues-exit-code: 0 - tests: false + tests: true + timeout: 5m linters: disable-all: true enable: - gofmt + - gosimple diff --git a/pkg/accounting/cost_distribution.go b/pkg/accounting/cost_distribution.go index e66f06592..5c588b182 100644 --- a/pkg/accounting/cost_distribution.go +++ b/pkg/accounting/cost_distribution.go @@ -11,10 +11,6 @@ import ( "github.com/c9s/bbgo/pkg/types" ) -func zero(a float64) bool { - return int(math.Round(a*1e8)) == 0 -} - type Stock types.Trade func (stock *Stock) String() string { diff --git a/pkg/backtest/matching.go b/pkg/backtest/matching.go index 37cced39a..9ea4c64df 100644 --- a/pkg/backtest/matching.go +++ b/pkg/backtest/matching.go @@ -237,7 +237,6 @@ func (m *SimplePriceMatching) executeTrade(trade types.Trade) { m.EmitTradeUpdate(trade) m.EmitBalanceUpdate(m.Account.Balances()) - return } func (m *SimplePriceMatching) newTradeFromOrder(order *types.Order, isMaker bool) types.Trade { diff --git a/pkg/bbgo/environment.go b/pkg/bbgo/environment.go index 370e3b9bb..8aa1d602a 100644 --- a/pkg/bbgo/environment.go +++ b/pkg/bbgo/environment.go @@ -835,7 +835,7 @@ func getAuthStoreID() string { } func (environ *Environment) setupInteraction(persistence service.PersistenceService) error { - var otpQRCodeImagePath = fmt.Sprintf("otp.png") + var otpQRCodeImagePath = "otp.png" var key *otp.Key var keyURL string var authStore = environ.getAuthStore(persistence) diff --git a/pkg/bbgo/trader.go b/pkg/bbgo/trader.go index 56d1525c5..54c6465b0 100644 --- a/pkg/bbgo/trader.go +++ b/pkg/bbgo/trader.go @@ -144,9 +144,8 @@ func (trader *Trader) AttachStrategyOn(session string, strategies ...SingleExcha return fmt.Errorf("session %s is not defined, valid sessions are: %v", session, keys) } - for _, s := range strategies { - trader.exchangeStrategies[session] = append(trader.exchangeStrategies[session], s) - } + trader.exchangeStrategies[session] = append( + trader.exchangeStrategies[session], strategies...) return nil } diff --git a/pkg/datasource/glassnode/glassnodeapi/types.go b/pkg/datasource/glassnode/glassnodeapi/types.go index 0d055e990..bdc50f33b 100644 --- a/pkg/datasource/glassnode/glassnodeapi/types.go +++ b/pkg/datasource/glassnode/glassnodeapi/types.go @@ -84,10 +84,7 @@ type Data struct { } func (s Response) IsEmpty() bool { - if len(s) == 0 { - return true - } - return false + return len(s) == 0 } func (s Response) First() Data { @@ -120,8 +117,5 @@ func (s Response) LastOptions() map[string]float64 { } func (s Response) HasOptions() bool { - if len(s.First().Options) == 0 { - return false - } - return true + return len(s.First().Options) != 0 } diff --git a/pkg/exchange/ftx/rest_responses.go b/pkg/exchange/ftx/rest_responses.go index 6174d6846..15da5e606 100644 --- a/pkg/exchange/ftx/rest_responses.go +++ b/pkg/exchange/ftx/rest_responses.go @@ -82,7 +82,7 @@ func (d *datetime) UnmarshalJSON(b []byte) error { } } */ -type accountResponse struct { +type accountResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result account `json:"result"` } @@ -93,7 +93,7 @@ type account struct { TotalAccountValue fixedpoint.Value `json:"totalAccountValue"` } -type positionsResponse struct { +type positionsResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result []position `json:"result"` } @@ -135,7 +135,7 @@ type position struct { CollateralUsed fixedpoint.Value `json:"collateralUsed"` } -type balances struct { +type balances struct { // nolint:golint,deadcode Success bool `json:"success"` Result []struct { @@ -172,7 +172,7 @@ type balances struct { } ] */ -type marketsResponse struct { +type marketsResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result []market `json:"result"` } @@ -230,19 +230,19 @@ type Candle struct { Volume fixedpoint.Value `json:"volume"` } -type ordersHistoryResponse struct { +type ordersHistoryResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result []order `json:"result"` HasMoreData bool `json:"hasMoreData"` } -type ordersResponse struct { +type ordersResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result []order `json:"result"` } -type cancelOrderResponse struct { +type cancelOrderResponse struct { // nolint:golint,deadcode Success bool `json:"success"` Result string `json:"result"` } diff --git a/pkg/exchange/max/maxapi/trade.go b/pkg/exchange/max/maxapi/trade.go index 149c91d50..bbc61f456 100644 --- a/pkg/exchange/max/maxapi/trade.go +++ b/pkg/exchange/max/maxapi/trade.go @@ -133,16 +133,16 @@ type PrivateRequestParams struct { type GetPrivateTradesRequest struct { client requestgen.AuthenticatedAPIClient - market string `param:"market"` + market string `param:"market"` // nolint:golint,structcheck // timestamp is the seconds elapsed since Unix epoch, set to return trades executed before the time only - timestamp *time.Time `param:"timestamp,seconds"` + timestamp *time.Time `param:"timestamp,seconds"` // nolint:golint,structcheck // From field is a trade id, set ot return trades created after the trade - from *int64 `param:"from"` + from *int64 `param:"from"` // nolint:golint,structcheck // To field trade id, set to return trades created before the trade - to *int64 `param:"to"` + to *int64 `param:"to"` // nolint:golint,structcheck orderBy *string `param:"order_by"` diff --git a/pkg/exchange/okex/convert.go b/pkg/exchange/okex/convert.go index fa70a1352..968544729 100644 --- a/pkg/exchange/okex/convert.go +++ b/pkg/exchange/okex/convert.go @@ -272,7 +272,7 @@ func toGlobalOrderType(orderType okexapi.OrderType) (types.OrderType, error) { } func toLocalInterval(src string) string { - var re = regexp.MustCompile("\\d+[hdw]") + var re = regexp.MustCompile(`\d+[hdw]`) return re.ReplaceAllStringFunc(src, func(w string) string { return strings.ToUpper(w) }) diff --git a/pkg/fixedpoint/convert.go b/pkg/fixedpoint/convert.go index 9d4d83950..3086806f0 100644 --- a/pkg/fixedpoint/convert.go +++ b/pkg/fixedpoint/convert.go @@ -231,7 +231,7 @@ func (v Value) MarshalJSON() ([]byte, error) { } func (v *Value) UnmarshalJSON(data []byte) error { - if bytes.Compare(data, []byte{'n', 'u', 'l', 'l'}) == 0 { + if bytes.Equal(data, []byte{'n', 'u', 'l', 'l'}) { *v = Zero return nil } diff --git a/pkg/fixedpoint/dec_test.go b/pkg/fixedpoint/dec_test.go index 5f63fe7c5..ffbc3bc78 100644 --- a/pkg/fixedpoint/dec_test.go +++ b/pkg/fixedpoint/dec_test.go @@ -16,7 +16,7 @@ func BenchmarkMul(b *testing.B) { for i := 0; i < b.N; i++ { x := NewFromFloat(20.0) y := NewFromFloat(20.0) - x = x.Mul(y) + x = x.Mul(y) // nolint } }) @@ -24,7 +24,7 @@ func BenchmarkMul(b *testing.B) { for i := 0; i < b.N; i++ { x := NewFromFloat(88.12345678) y := NewFromFloat(88.12345678) - x = x.Mul(y) + x = x.Mul(y) // nolint } }) @@ -32,7 +32,7 @@ func BenchmarkMul(b *testing.B) { for i := 0; i < b.N; i++ { x := big.NewFloat(20.0) y := big.NewFloat(20.0) - x = new(big.Float).Mul(x, y) + x = new(big.Float).Mul(x, y) // nolint } }) @@ -40,7 +40,7 @@ func BenchmarkMul(b *testing.B) { for i := 0; i < b.N; i++ { x := big.NewFloat(88.12345678) y := big.NewFloat(88.12345678) - x = new(big.Float).Mul(x, y) + x = new(big.Float).Mul(x, y) // nolint } }) } @@ -170,8 +170,7 @@ func TestJson(t *testing.T) { _ = json.Unmarshal([]byte("0.00153917575"), &p) assert.Equal(t, "0.00153917", p.FormatString(8)) - var q Value - q = NewFromFloat(0.00153917575) + q := NewFromFloat(0.00153917575) assert.Equal(t, p, q) _ = json.Unmarshal([]byte("6e-8"), &p) _ = json.Unmarshal([]byte("0.000062"), &q) diff --git a/pkg/interact/interact.go b/pkg/interact/interact.go index a4c4501ee..a19b56210 100644 --- a/pkg/interact/interact.go +++ b/pkg/interact/interact.go @@ -46,8 +46,6 @@ type Interact struct { states map[State]State statesFunc map[State]interface{} - authenticatedSessions map[string]Session - customInteractions []CustomInteraction messengers []Messenger @@ -97,10 +95,6 @@ func (it *Interact) getNextState(session Session, currentState State) (nextState return session.GetOriginState(), final } -func (it *Interact) handleCallback(session Session, payload string) error { - return nil -} - func (it *Interact) handleResponse(session Session, text string, ctxObjects ...interface{}) error { // We only need response when executing a command switch session.GetState() { diff --git a/pkg/interact/telegram.go b/pkg/interact/telegram.go index 4b1bb13fe..464e9b763 100644 --- a/pkg/interact/telegram.go +++ b/pkg/interact/telegram.go @@ -104,8 +104,6 @@ type Telegram struct { // Private is used to protect the telegram bot, users not authenticated can not see messages or sending commands Private bool `json:"private,omitempty"` - authorizing bool - sessions TelegramSessionMap // textMessageResponder is used for interact to register its message handler @@ -237,7 +235,7 @@ func (tm *Telegram) Sessions() TelegramSessionMap { } func (tm *Telegram) RestoreSessions(sessions TelegramSessionMap) { - if sessions == nil || len(sessions) == 0 { + if len(sessions) == 0 { return } diff --git a/pkg/server/routes.go b/pkg/server/routes.go index 8727e334d..6502c17e1 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -597,7 +597,6 @@ func (s *Server) tradingVolume(c *gin.Context) { } c.JSON(http.StatusOK, gin.H{"tradingVolumes": rows}) - return } func newServer(r http.Handler, bind string) *http.Server { diff --git a/pkg/service/backtest.go b/pkg/service/backtest.go index 41fd06163..8c1edfac0 100644 --- a/pkg/service/backtest.go +++ b/pkg/service/backtest.go @@ -226,7 +226,7 @@ func (s *BacktestService) QueryKLinesCh(since, until time.Time, exchange types.E } func returnError(err error) (chan types.KLine, chan error) { - ch := make(chan types.KLine, 0) + ch := make(chan types.KLine) close(ch) log.WithError(err).Error("backtest query error") diff --git a/pkg/service/deposit.go b/pkg/service/deposit.go index 07ad21838..b892cdb81 100644 --- a/pkg/service/deposit.go +++ b/pkg/service/deposit.go @@ -47,11 +47,7 @@ func (s *DepositService) Sync(ctx context.Context, ex types.Exchange, startTime }, Filter: func(obj interface{}) bool { deposit := obj.(types.Deposit) - if len(deposit.TransactionID) == 0 { - return false - } - - return true + return len(deposit.TransactionID) != 0 }, LogInsert: true, }, diff --git a/pkg/slack/slacklog/logrus_look.go b/pkg/slack/slacklog/logrus_look.go index 5d56375b3..e4349a021 100644 --- a/pkg/slack/slacklog/logrus_look.go +++ b/pkg/slack/slacklog/logrus_look.go @@ -40,7 +40,7 @@ func (t *LogHook) Fire(e *logrus.Entry) error { return nil } - var color = "" + var color string switch e.Level { case logrus.DebugLevel: diff --git a/pkg/strategy/ewoDgtrd/strategy.go b/pkg/strategy/ewoDgtrd/strategy.go index a4312b7fd..fecfb80f7 100644 --- a/pkg/strategy/ewoDgtrd/strategy.go +++ b/pkg/strategy/ewoDgtrd/strategy.go @@ -431,7 +431,7 @@ func (s *Strategy) validateOrder(order *types.SubmitOrder) error { order.Quantity.Compare(s.Market.MinQuantity) < 0 || orderAmount.Compare(s.Market.MinNotional) < 0 { log.Debug("amount fail") - return errors.New(fmt.Sprintf("amount fail: quantity: %v, amount: %v", order.Quantity, orderAmount)) + return fmt.Errorf("amount fail: quantity: %v, amount: %v", order.Quantity, orderAmount) } return nil } else if order.Side == types.SideTypeBuy { @@ -458,7 +458,7 @@ func (s *Strategy) validateOrder(order *types.SubmitOrder) error { orderAmount.Compare(s.Market.MinNotional) < 0 || order.Quantity.Compare(s.Market.MinQuantity) < 0 { log.Debug("amount fail") - return errors.New(fmt.Sprintf("amount fail: quantity: %v, amount: %v", order.Quantity, orderAmount)) + return fmt.Errorf("amount fail: quantity: %v, amount: %v", order.Quantity, orderAmount) } return nil } @@ -801,7 +801,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se store, ok := s.Session.MarketDataStore(s.Symbol) if !ok { - return errors.New(fmt.Sprintf("cannot get marketdatastore of %s", s.Symbol)) + return fmt.Errorf("cannot get marketdatastore of %s", s.Symbol) } s.SetupIndicators(store) @@ -893,27 +893,22 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se percentAvgTPfromCCI = percentAvgTPfromCCI*float64(counterTPfromCCI) + pnlRate counterTPfromCCI += 1 percentAvgTPfromCCI /= float64(counterTPfromCCI) - break case 1: percentAvgTPfromLongShort = percentAvgTPfromLongShort*float64(counterTPfromLongShort) + pnlRate counterTPfromLongShort += 1 percentAvgTPfromLongShort /= float64(counterTPfromLongShort) - break case 2: percentAvgTPfromAtr = percentAvgTPfromAtr*float64(counterTPfromAtr) + pnlRate counterTPfromAtr += 1 percentAvgTPfromAtr /= float64(counterTPfromAtr) - break case 3: percentAvgTPfromPeak = percentAvgTPfromPeak*float64(counterTPfromPeak) + pnlRate counterTPfromPeak += 1 percentAvgTPfromPeak /= float64(counterTPfromPeak) - break case 4: percentAvgSLfromSL = percentAvgSLfromSL*float64(counterSLfromSL) + pnlRate counterSLfromSL += 1 percentAvgSLfromSL /= float64(counterSLfromSL) - break } } @@ -1002,27 +997,22 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se percentAvgTPfromCCI = percentAvgTPfromCCI*float64(counterTPfromCCI) + pnlRate counterTPfromCCI += 1 percentAvgTPfromCCI /= float64(counterTPfromCCI) - break case 1: percentAvgTPfromLongShort = percentAvgTPfromLongShort*float64(counterTPfromLongShort) + pnlRate counterTPfromLongShort += 1 percentAvgTPfromLongShort /= float64(counterTPfromLongShort) - break case 2: percentAvgTPfromAtr = percentAvgTPfromAtr*float64(counterTPfromAtr) + pnlRate counterTPfromAtr += 1 percentAvgTPfromAtr /= float64(counterTPfromAtr) - break case 3: percentAvgTPfromPeak = percentAvgTPfromPeak*float64(counterTPfromPeak) + pnlRate counterTPfromPeak += 1 percentAvgTPfromPeak /= float64(counterTPfromPeak) - break case 4: percentAvgSLfromSL = percentAvgSLfromSL*float64(counterSLfromSL) + pnlRate counterSLfromSL += 1 percentAvgSLfromSL /= float64(counterSLfromSL) - break } } } diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index e35ee2551..8d0bd6561 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -550,8 +550,8 @@ func (s *Strategy) placeBounceSellOrders(ctx context.Context, resistancePrice fi for i := 0; i < numLayers; i++ { balances := s.session.GetAccount().Balances() - quoteBalance, _ := balances[s.Market.QuoteCurrency] - baseBalance, _ := balances[s.Market.BaseCurrency] + quoteBalance := balances[s.Market.QuoteCurrency] + baseBalance := balances[s.Market.BaseCurrency] // price = (resistance_price * (1.0 - ratio)) * ((1.0 + layerSpread) * i) price := resistancePrice.Mul(fixedpoint.One.Sub(s.BounceShort.Ratio)) diff --git a/pkg/strategy/xbalance/strategy.go b/pkg/strategy/xbalance/strategy.go index f3c364e04..0a89815ed 100644 --- a/pkg/strategy/xbalance/strategy.go +++ b/pkg/strategy/xbalance/strategy.go @@ -36,7 +36,7 @@ type State struct { } func (s *State) IsOver24Hours() bool { - return time.Now().Sub(time.Unix(s.Since, 0)) >= 24*time.Hour + return time.Since(time.Unix(s.Since, 0)) >= 24*time.Hour } func (s *State) PlainText() string { diff --git a/pkg/strategy/xgap/strategy.go b/pkg/strategy/xgap/strategy.go index 4f9fc87fe..d82161e12 100644 --- a/pkg/strategy/xgap/strategy.go +++ b/pkg/strategy/xgap/strategy.go @@ -42,7 +42,7 @@ type State struct { } func (s *State) IsOver24Hours() bool { - return time.Now().Sub(s.AccumulatedFeeStartedAt) >= 24*time.Hour + return time.Since(s.AccumulatedFeeStartedAt) >= 24*time.Hour } func (s *State) Reset() { diff --git a/pkg/strategy/xpuremaker/strategy.go b/pkg/strategy/xpuremaker/strategy.go index c6cb53bf8..a5d441bdc 100644 --- a/pkg/strategy/xpuremaker/strategy.go +++ b/pkg/strategy/xpuremaker/strategy.go @@ -113,7 +113,7 @@ func (s *Strategy) update(orderExecutor bbgo.OrderExecutor, session *bbgo.Exchan func (s *Strategy) updateOrders(orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession, side types.SideType) { var book = s.book.Copy() var pvs = book.SideBook(side) - if pvs == nil || len(pvs) == 0 { + if len(pvs) == 0 { log.Warnf("empty side: %s", side) return } diff --git a/pkg/types/asset.go b/pkg/types/asset.go index bbd98dbe1..8b17de422 100644 --- a/pkg/types/asset.go +++ b/pkg/types/asset.go @@ -123,7 +123,7 @@ func (m AssetMap) SlackAttachment() slack.Attachment { Short: false, }) } else { - text := fmt.Sprintf("%s", a.NetAsset.String()) + text := a.NetAsset.String() if !a.Borrowed.IsZero() { text += fmt.Sprintf(" Borrowed: %s", a.Borrowed.String()) diff --git a/pkg/types/balance.go b/pkg/types/balance.go index 7acb04db4..8a69895e7 100644 --- a/pkg/types/balance.go +++ b/pkg/types/balance.go @@ -50,7 +50,7 @@ func (b Balance) Net() fixedpoint.Value { } func (b Balance) ValueString() (o string) { - o = fmt.Sprintf("%s", b.Available.String()) + o = b.Available.String() if b.Locked.Sign() > 0 { o += fmt.Sprintf(" (locked %v)", b.Locked) diff --git a/pkg/types/indicator.go b/pkg/types/indicator.go index 0a3765818..286e1493c 100644 --- a/pkg/types/indicator.go +++ b/pkg/types/indicator.go @@ -135,8 +135,8 @@ func Predict(a Series, lookback int, offset ...int) float64 { if a.Length() < lookback { lookback = a.Length() } - x := make([]float64, lookback, lookback) - y := make([]float64, lookback, lookback) + x := make([]float64, lookback) + y := make([]float64, lookback) var weights []float64 for i := 0; i < lookback; i++ { x[i] = float64(i) @@ -163,9 +163,9 @@ func NextCross(a Series, b Series, lookback int) (int, float64, bool) { if b.Length() < lookback { lookback = b.Length() } - x := make([]float64, lookback, lookback) - y1 := make([]float64, lookback, lookback) - y2 := make([]float64, lookback, lookback) + x := make([]float64, lookback) + y1 := make([]float64, lookback) + y2 := make([]float64, lookback) var weights []float64 for i := 0; i < lookback; i++ { x[i] = float64(i) @@ -295,20 +295,20 @@ func Add(a interface{}, b interface{}) Series { var aa Series var bb Series - switch a.(type) { + switch tp := a.(type) { case float64: - aa = NumberSeries(a.(float64)) + aa = NumberSeries(tp) case Series: - aa = a.(Series) + aa = tp default: panic("input should be either *Series or float64") } - switch b.(type) { + switch tp := b.(type) { case float64: - bb = NumberSeries(b.(float64)) + bb = NumberSeries(tp) case Series: - bb = b.(Series) + bb = tp default: panic("input should be either *Series or float64") @@ -367,19 +367,19 @@ func (a *MinusSeriesResult) Length() int { var _ Series = &MinusSeriesResult{} func switchIface(b interface{}) Series { - switch b.(type) { + switch tp := b.(type) { case float64: - return NumberSeries(b.(float64)) + return NumberSeries(tp) case int32: - return NumberSeries(float64(b.(int32))) + return NumberSeries(float64(tp)) case int64: - return NumberSeries(float64(b.(int64))) + return NumberSeries(float64(tp)) case float32: - return NumberSeries(float64(b.(float32))) + return NumberSeries(float64(tp)) case int: - return NumberSeries(float64(b.(int))) + return NumberSeries(float64(tp)) case Series: - return b.(Series) + return tp default: fmt.Println(reflect.TypeOf(b)) panic("input should be either *Series or float64") @@ -427,19 +427,19 @@ func Mul(a interface{}, b interface{}) Series { var aa Series var bb Series - switch a.(type) { + switch tp := a.(type) { case float64: - aa = NumberSeries(a.(float64)) + aa = NumberSeries(tp) case Series: - aa = a.(Series) + aa = tp default: panic("input should be either Series or float64") } - switch b.(type) { + switch tp := b.(type) { case float64: - bb = NumberSeries(b.(float64)) + bb = NumberSeries(tp) case Series: - bb = b.(Series) + bb = tp default: panic("input should be either Series or float64") @@ -490,7 +490,7 @@ func ToArray(a Series, limit ...int) (result []float64) { if l < a.Length() { l = a.Length() } - result = make([]float64, l, l) + result = make([]float64, l) for i := 0; i < l; i++ { result[i] = a.Index(i) } @@ -510,7 +510,7 @@ func ToReverseArray(a Series, limit ...int) (result Float64Slice) { if l < a.Length() { l = a.Length() } - result = make([]float64, l, l) + result = make([]float64, l) for i := 0; i < l; i++ { result[l-i-1] = a.Index(i) } diff --git a/pkg/types/kline.go b/pkg/types/kline.go index 396a53c8d..6a92ffdf3 100644 --- a/pkg/types/kline.go +++ b/pkg/types/kline.go @@ -563,6 +563,8 @@ type KLineSeries struct { func (k *KLineSeries) Last() float64 { length := len(*k.lines) switch k.kv { + case kOpUnknown: + panic("kline series operator unknown") case kOpenValue: return (*k.lines)[length-1].GetOpen().Float64() case kCloseValue: diff --git a/pkg/types/price_volume_slice.go b/pkg/types/price_volume_slice.go index 7c0c8a60f..a7863702f 100644 --- a/pkg/types/price_volume_slice.go +++ b/pkg/types/price_volume_slice.go @@ -38,13 +38,13 @@ func (slice PriceVolumeSlice) CopyDepth(depth int) PriceVolumeSlice { return slice.Copy() } - var s = make(PriceVolumeSlice, depth, depth) + var s = make(PriceVolumeSlice, depth) copy(s, slice[:depth]) return s } func (slice PriceVolumeSlice) Copy() PriceVolumeSlice { - var s = make(PriceVolumeSlice, len(slice), len(slice)) + var s = make(PriceVolumeSlice, len(slice)) copy(s, slice) return s } diff --git a/pkg/types/sliceorderbook.go b/pkg/types/sliceorderbook.go index c542e7284..777e30333 100644 --- a/pkg/types/sliceorderbook.go +++ b/pkg/types/sliceorderbook.go @@ -153,7 +153,7 @@ func (b *SliceOrderBook) Update(book SliceOrderBook) { } func (b *SliceOrderBook) Print() { - fmt.Printf(b.String()) + fmt.Print(b.String()) } func (b *SliceOrderBook) String() string { diff --git a/pkg/types/time.go b/pkg/types/time.go index aede16dcd..2648d08af 100644 --- a/pkg/types/time.go +++ b/pkg/types/time.go @@ -115,8 +115,7 @@ func (t *MillisecondTimestamp) UnmarshalJSON(data []byte) error { } - // fallback to RFC3339 - return (*time.Time)(t).UnmarshalJSON(data) + // Unreachable } func convertFloat64ToTime(vt string, f float64) (time.Time, error) { diff --git a/pkg/types/trade.go b/pkg/types/trade.go index 2ea6c40c7..c25689fe8 100644 --- a/pkg/types/trade.go +++ b/pkg/types/trade.go @@ -27,7 +27,7 @@ type TradeSlice struct { func (s *TradeSlice) Copy() []Trade { s.mu.Lock() - slice := make([]Trade, len(s.Trades), len(s.Trades)) + slice := make([]Trade, len(s.Trades)) copy(slice, s.Trades) s.mu.Unlock() diff --git a/pkg/util/profile.go b/pkg/util/profile.go index 7ca5f5009..1d3753aa2 100644 --- a/pkg/util/profile.go +++ b/pkg/util/profile.go @@ -19,7 +19,7 @@ func StartTimeProfile(args ...string) TimeProfile { } func (p *TimeProfile) TilNow() time.Duration { - return time.Now().Sub(p.StartTime) + return time.Since(p.StartTime) } func (p *TimeProfile) Stop() time.Duration {