rename cronExpression to schedule

This commit is contained in:
narumi 2024-01-06 17:37:13 +08:00
parent 6367bd79d3
commit dc2895c4dc
4 changed files with 22 additions and 48 deletions

View File

@ -4,7 +4,7 @@ exchangeStrategies:
random:
symbol: USDCUSDT
# https://pkg.go.dev/github.com/robfig/cron#hdr-Predefined_schedules
cronExpression: "@every 8h"
schedule: "@every 8h"
quantity: 8
onStart: true
dryRun: true

View File

@ -1,39 +1,13 @@
---
notifications:
slack:
defaultChannel: "bbgo"
errorChannel: "bbgo-error"
switches:
trade: true
orderUpdate: true
submitOrder: true
backtest:
startTime: "2022-01-01"
endTime: "2022-10-01"
symbols:
- BTCUSDT
- ETHUSDT
- MAXUSDT
account:
max:
makerFeeRate: 0.075%
takerFeeRate: 0.075%
balances:
BTC: 0.0
ETH: 0.0
MAX: 0.0
USDT: 10000.0
exchangeStrategies:
- on: max
rebalance:
cronExpression: "@every 1s"
quoteCurrency: USDT
schedule: "@every 1s"
quoteCurrency: TWD
targetWeights:
BTC: 50%
ETH: 25%
USDT: 25%
BTC: 60%
ETH: 30%
TWD: 10%
threshold: 1%
maxAmount: 1_000 # max amount to buy or sell per order
orderType: LIMIT_MAKER # LIMIT, LIMIT_MAKER or MARKET

View File

@ -28,10 +28,10 @@ type Strategy struct {
Environment *bbgo.Environment
Market types.Market
Symbol string `json:"symbol"`
CronExpression string `json:"cronExpression"`
OnStart bool `json:"onStart"`
DryRun bool `json:"dryRun"`
Symbol string `json:"symbol"`
Schedule string `json:"schedule"`
OnStart bool `json:"onStart"`
DryRun bool `json:"dryRun"`
bbgo.QuantityOrAmount
cron *cron.Cron
@ -55,8 +55,8 @@ func (s *Strategy) InstanceID() string {
}
func (s *Strategy) Validate() error {
if s.CronExpression == "" {
return fmt.Errorf("cronExpression is required")
if s.Schedule == "" {
return fmt.Errorf("schedule is required")
}
if err := s.QuantityOrAmount.Validate(); err != nil {
@ -83,7 +83,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
})
s.cron = cron.New()
s.cron.AddFunc(s.CronExpression, s.placeOrder)
s.cron.AddFunc(s.Schedule, s.placeOrder)
s.cron.Start()
return nil

View File

@ -27,14 +27,14 @@ type Strategy struct {
Environment *bbgo.Environment
CronExpression string `json:"cronExpression"`
QuoteCurrency string `json:"quoteCurrency"`
TargetWeights types.ValueMap `json:"targetWeights"`
Threshold fixedpoint.Value `json:"threshold"`
MaxAmount fixedpoint.Value `json:"maxAmount"` // max amount to buy or sell per order
OrderType types.OrderType `json:"orderType"`
DryRun bool `json:"dryRun"`
OnStart bool `json:"onStart"` // rebalance on start
Schedule string `json:"schedule"`
QuoteCurrency string `json:"quoteCurrency"`
TargetWeights types.ValueMap `json:"targetWeights"`
Threshold fixedpoint.Value `json:"threshold"`
MaxAmount fixedpoint.Value `json:"maxAmount"` // max amount to buy or sell per order
OrderType types.OrderType `json:"orderType"`
DryRun bool `json:"dryRun"`
OnStart bool `json:"onStart"` // rebalance on start
symbols []string
markets map[string]types.Market
@ -130,7 +130,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
})
s.cron = cron.New()
s.cron.AddFunc(s.CronExpression, func() {
s.cron.AddFunc(s.Schedule, func() {
s.rebalance(ctx)
})
s.cron.Start()