From badadafa2d0dbc1df8389bfbc68fe92d68e10591 Mon Sep 17 00:00:00 2001 From: narumi Date: Fri, 13 Oct 2023 18:11:21 +0800 Subject: [PATCH] remove adjustQuantity from config --- config/random.yaml | 2 -- pkg/strategy/random/strategy.go | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/config/random.yaml b/config/random.yaml index 551e397fc..269c5d8a8 100644 --- a/config/random.yaml +++ b/config/random.yaml @@ -6,7 +6,5 @@ exchangeStrategies: # https://pkg.go.dev/github.com/robfig/cron#hdr-Predefined_schedules cronExpression: "@every 8h" quantity: 8 - # adjust quantity by minimal notional and minimal quantity - adjustQuantity: true onStart: true dryRun: true diff --git a/pkg/strategy/random/strategy.go b/pkg/strategy/random/strategy.go index f1bae583b..96b56cb5a 100644 --- a/pkg/strategy/random/strategy.go +++ b/pkg/strategy/random/strategy.go @@ -10,7 +10,6 @@ import ( "github.com/sirupsen/logrus" "github.com/c9s/bbgo/pkg/bbgo" - "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/strategy/common" "github.com/c9s/bbgo/pkg/types" ) @@ -29,13 +28,12 @@ type Strategy struct { Environment *bbgo.Environment Market types.Market - Symbol string `json:"symbol"` - CronExpression string `json:"cronExpression"` - Quantity fixedpoint.Value `json:"quantity"` - AdjustQuantity bool `json:"adjustQuantity"` - OnStart bool `json:"onStart"` - DryRun bool `json:"dryRun"` + Symbol string `json:"symbol"` + CronExpression string `json:"cronExpression"` + OnStart bool `json:"onStart"` + DryRun bool `json:"dryRun"` + bbgo.QuantityOrAmount cron *cron.Cron } @@ -59,6 +57,10 @@ func (s *Strategy) Validate() error { if s.CronExpression == "" { return fmt.Errorf("cronExpression is required") } + + if err := s.QuantityOrAmount.Validate(); err != nil { + return err + } return nil } @@ -107,12 +109,10 @@ func (s *Strategy) placeOrder() { return } - sellQuantity := s.Quantity - buyQuantity := s.Quantity - if s.AdjustQuantity { - sellQuantity = s.Market.AdjustQuantityByMinNotional(s.Quantity, ticker.Sell) - buyQuantity = fixedpoint.Max(s.Quantity, s.Market.MinQuantity) - } + sellQuantity := s.CalculateQuantity(ticker.Sell) + buyQuantity := s.CalculateQuantity(ticker.Buy) + sellQuantity = s.Market.AdjustQuantityByMinNotional(sellQuantity, ticker.Sell) + buyQuantity = s.Market.AdjustQuantityByMinNotional(buyQuantity, ticker.Buy) orderForm := []types.SubmitOrder{} if baseBalance.Available.Compare(sellQuantity) > 0 {