remove adjustQuantity from config

This commit is contained in:
narumi 2023-10-13 18:11:21 +08:00
parent fb110a1d5b
commit badadafa2d
2 changed files with 13 additions and 15 deletions

View File

@ -6,7 +6,5 @@ exchangeStrategies:
# https://pkg.go.dev/github.com/robfig/cron#hdr-Predefined_schedules # https://pkg.go.dev/github.com/robfig/cron#hdr-Predefined_schedules
cronExpression: "@every 8h" cronExpression: "@every 8h"
quantity: 8 quantity: 8
# adjust quantity by minimal notional and minimal quantity
adjustQuantity: true
onStart: true onStart: true
dryRun: true dryRun: true

View File

@ -10,7 +10,6 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/c9s/bbgo/pkg/bbgo" "github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/strategy/common" "github.com/c9s/bbgo/pkg/strategy/common"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
@ -29,13 +28,12 @@ type Strategy struct {
Environment *bbgo.Environment Environment *bbgo.Environment
Market types.Market Market types.Market
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
CronExpression string `json:"cronExpression"` CronExpression string `json:"cronExpression"`
Quantity fixedpoint.Value `json:"quantity"` OnStart bool `json:"onStart"`
AdjustQuantity bool `json:"adjustQuantity"` DryRun bool `json:"dryRun"`
OnStart bool `json:"onStart"`
DryRun bool `json:"dryRun"`
bbgo.QuantityOrAmount
cron *cron.Cron cron *cron.Cron
} }
@ -59,6 +57,10 @@ func (s *Strategy) Validate() error {
if s.CronExpression == "" { if s.CronExpression == "" {
return fmt.Errorf("cronExpression is required") return fmt.Errorf("cronExpression is required")
} }
if err := s.QuantityOrAmount.Validate(); err != nil {
return err
}
return nil return nil
} }
@ -107,12 +109,10 @@ func (s *Strategy) placeOrder() {
return return
} }
sellQuantity := s.Quantity sellQuantity := s.CalculateQuantity(ticker.Sell)
buyQuantity := s.Quantity buyQuantity := s.CalculateQuantity(ticker.Buy)
if s.AdjustQuantity { sellQuantity = s.Market.AdjustQuantityByMinNotional(sellQuantity, ticker.Sell)
sellQuantity = s.Market.AdjustQuantityByMinNotional(s.Quantity, ticker.Sell) buyQuantity = s.Market.AdjustQuantityByMinNotional(buyQuantity, ticker.Buy)
buyQuantity = fixedpoint.Max(s.Quantity, s.Market.MinQuantity)
}
orderForm := []types.SubmitOrder{} orderForm := []types.SubmitOrder{}
if baseBalance.Available.Compare(sellQuantity) > 0 { if baseBalance.Available.Compare(sellQuantity) > 0 {