move currency formatter to market struct

This commit is contained in:
c9s 2021-10-15 11:50:37 +08:00
parent 790b3357d7
commit 952bdf8218
2 changed files with 15 additions and 6 deletions

View File

@ -6,7 +6,6 @@ import (
"fmt"
"github.com/c9s/bbgo/pkg/exchange/binance"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/leekchan/accounting"
"github.com/sirupsen/logrus"
"strings"
"time"
@ -198,11 +197,8 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
return
}
prettyBaseVolume := accounting.DefaultAccounting(s.Market.BaseCurrency, s.Market.VolumePrecision)
prettyBaseVolume.Format = "%v %s"
prettyQuoteVolume := accounting.DefaultAccounting(s.Market.QuoteCurrency, 0)
prettyQuoteVolume.Format = "%v %s"
prettyBaseVolume := s.Market.BaseCurrencyFormatter()
prettyQuoteVolume := s.Market.QuoteCurrencyFormatter()
if detection.MinVolume > 0 && kline.Volume > detection.MinVolume.Float64() {
s.Notifiability.Notify("Detected %s %s support base volume %s > min base volume %s, quote volume %s",

View File

@ -3,6 +3,7 @@ package types
import (
"encoding/json"
"fmt"
"github.com/leekchan/accounting"
"math"
"strconv"
"time"
@ -70,6 +71,18 @@ type Market struct {
TickSize float64
}
func (m Market) BaseCurrencyFormatter() *accounting.Accounting {
a := accounting.DefaultAccounting(m.BaseCurrency, m.VolumePrecision)
a.Format = "%v %s"
return a
}
func (m Market) QuoteCurrencyFormatter() *accounting.Accounting {
a := accounting.DefaultAccounting(m.QuoteCurrency, m.PricePrecision)
a.Format = "%v %s"
return a
}
func (m Market) FormatPriceCurrency(val float64) string {
switch m.QuoteCurrency {