From 577caab3f588ce002c5939a8e1ff31a73d0bb598 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 11 Jul 2020 20:40:19 +0800 Subject: [PATCH] refactor volume calculator --- bbgo/exchange/binance/exchange.go | 5 +++++ bbgo/market.go | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bbgo/exchange/binance/exchange.go b/bbgo/exchange/binance/exchange.go index 17c2e6420..8bfd1d323 100644 --- a/bbgo/exchange/binance/exchange.go +++ b/bbgo/exchange/binance/exchange.go @@ -97,6 +97,11 @@ func toLocalOrderType(orderType types.OrderType) (binance.OrderType, error) { } func (e *Exchange) QueryKLines(ctx context.Context, symbol, interval string, limit int) ([]types.KLine, error) { + if limit == 0 { + // default limit == 500 + limit = 500 + } + logrus.Infof("[binance] querying kline %s %s limit %d", symbol, interval, limit) resp, err := e.Client.NewKlinesService().Symbol(symbol).Interval(interval).Limit(limit).Do(ctx) diff --git a/bbgo/market.go b/bbgo/market.go index c406a733b..d9d44b0be 100644 --- a/bbgo/market.go +++ b/bbgo/market.go @@ -1,6 +1,9 @@ package bbgo -import "strconv" +import ( + "math" + "strconv" +) type Market struct { Symbol string @@ -20,6 +23,11 @@ func (m Market) FormatVolume(val float64) string { return strconv.FormatFloat(val, 'f', m.VolumePrecision, 64) } +func (m Market) CanonicalizeVolume(val float64) float64 { + p := math.Pow10(m.VolumePrecision) + return math.Trunc(p * val) / p +} + // Binance Markets, this should be defined per exchange var MarketBTCUSDT = Market{