grid2: log base fee rounding precision

This commit is contained in:
c9s 2023-03-01 21:49:15 +08:00
parent b2bbf2d6ca
commit f553ee05a0
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 33 additions and 30 deletions

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/c9s/bbgo/pkg/backtest" "github.com/c9s/bbgo/pkg/backtest"
@ -14,6 +15,7 @@ import (
"github.com/c9s/bbgo/pkg/exchange" "github.com/c9s/bbgo/pkg/exchange"
"github.com/c9s/bbgo/pkg/service" "github.com/c9s/bbgo/pkg/service"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/util"
) )
func RunBacktest(t *testing.T, strategy bbgo.SingleExchangeStrategy) { func RunBacktest(t *testing.T, strategy bbgo.SingleExchangeStrategy) {
@ -154,3 +156,29 @@ func RunBacktest(t *testing.T, strategy bbgo.SingleExchangeStrategy) {
<-doneC <-doneC
// }}} // }}}
} }
func TestBacktestStrategy(t *testing.T) {
if v, ok := util.GetEnvVarBool("TEST_BACKTEST"); !ok || !v {
t.Skip("backtest flag is required")
return
}
market := types.Market{
BaseCurrency: "BTC",
QuoteCurrency: "USDT",
TickSize: number(0.01),
PricePrecision: 2,
VolumePrecision: 8,
}
strategy := &Strategy{
logger: logrus.NewEntry(logrus.New()),
Symbol: "BTCUSDT",
Market: market,
GridProfitStats: newGridProfitStats(market),
UpperPrice: number(60_000),
LowerPrice: number(28_000),
GridNum: 100,
QuoteInvestment: number(9000.0),
}
RunBacktest(t, strategy)
}

View File

@ -417,7 +417,10 @@ func (s *Strategy) processFilledOrder(o types.Order) {
s.logger.Infof("GRID BUY ORDER BASE FEE: %s %s", baseSellQuantityReduction.String(), s.Market.BaseCurrency) s.logger.Infof("GRID BUY ORDER BASE FEE: %s %s", baseSellQuantityReduction.String(), s.Market.BaseCurrency)
baseSellQuantityReduction = baseSellQuantityReduction.Round(s.Market.VolumePrecision, fixedpoint.Up) baseSellQuantityReduction = baseSellQuantityReduction.Round(s.Market.VolumePrecision, fixedpoint.Up)
s.logger.Infof("GRID BUY ORDER BASE FEE (Rounding): %s %s", baseSellQuantityReduction.String(), s.Market.BaseCurrency) s.logger.Infof("GRID BUY ORDER BASE FEE (Rounding with precision %d): %s %s",
s.Market.VolumePrecision,
baseSellQuantityReduction.String(),
s.Market.BaseCurrency)
newQuantity = newQuantity.Sub(baseSellQuantityReduction) newQuantity = newQuantity.Sub(baseSellQuantityReduction)

View File

@ -13,11 +13,9 @@ import (
"github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
gridmocks "github.com/c9s/bbgo/pkg/strategy/grid2/mocks"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
"github.com/c9s/bbgo/pkg/types/mocks" "github.com/c9s/bbgo/pkg/types/mocks"
"github.com/c9s/bbgo/pkg/util"
gridmocks "github.com/c9s/bbgo/pkg/strategy/grid2/mocks"
) )
func init() { func init() {
@ -919,29 +917,3 @@ func TestStrategy_checkMinimalQuoteInvestment(t *testing.T) {
assert.EqualError(t, err, "need at least 14979.995500 USDT for quote investment, 10000.000000 USDT given") assert.EqualError(t, err, "need at least 14979.995500 USDT for quote investment, 10000.000000 USDT given")
}) })
} }
func TestBacktestStrategy(t *testing.T) {
if v, ok := util.GetEnvVarBool("TEST_BACKTEST"); !ok || !v {
t.Skip("backtest flag is required")
return
}
market := types.Market{
BaseCurrency: "BTC",
QuoteCurrency: "USDT",
TickSize: number(0.01),
PricePrecision: 2,
VolumePrecision: 8,
}
strategy := &Strategy{
logger: logrus.NewEntry(logrus.New()),
Symbol: "BTCUSDT",
Market: market,
GridProfitStats: newGridProfitStats(market),
UpperPrice: number(60_000),
LowerPrice: number(28_000),
GridNum: 100,
QuoteInvestment: number(9000.0),
}
RunBacktest(t, strategy)
}