diff --git a/config/random.yaml b/config/random.yaml index 269c5d8a8..290adf12b 100644 --- a/config/random.yaml +++ b/config/random.yaml @@ -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 diff --git a/config/rebalance.yaml b/config/rebalance.yaml index bdcd5f6f5..e98c5a82c 100644 --- a/config/rebalance.yaml +++ b/config/rebalance.yaml @@ -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 diff --git a/pkg/strategy/random/strategy.go b/pkg/strategy/random/strategy.go index a9ccd9888..686be9112 100644 --- a/pkg/strategy/random/strategy.go +++ b/pkg/strategy/random/strategy.go @@ -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 diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 33ea2ef8b..0b1a0909a 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -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()