refactor volume calculator

This commit is contained in:
c9s 2020-07-11 20:40:19 +08:00
parent cb4afca815
commit 577caab3f5
2 changed files with 14 additions and 1 deletions

View File

@ -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) { 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) 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) resp, err := e.Client.NewKlinesService().Symbol(symbol).Interval(interval).Limit(limit).Do(ctx)

View File

@ -1,6 +1,9 @@
package bbgo package bbgo
import "strconv" import (
"math"
"strconv"
)
type Market struct { type Market struct {
Symbol string Symbol string
@ -20,6 +23,11 @@ func (m Market) FormatVolume(val float64) string {
return strconv.FormatFloat(val, 'f', m.VolumePrecision, 64) 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 // Binance Markets, this should be defined per exchange
var MarketBTCUSDT = Market{ var MarketBTCUSDT = Market{