Skip to content

Commit 0690518

Browse files
committed
add option to rebalance on start
1 parent 640001f commit 0690518

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

config/rebalance.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ exchangeStrategies:
3939
maxAmount: 1_000 # max amount to buy or sell per order
4040
orderType: LIMIT_MAKER # LIMIT, LIMIT_MAKER or MARKET
4141
dryRun: false
42+
onStart: false

pkg/strategy/rebalance/strategy.go

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Strategy struct {
3434
MaxAmount fixedpoint.Value `json:"maxAmount"` // max amount to buy or sell per order
3535
OrderType types.OrderType `json:"orderType"`
3636
DryRun bool `json:"dryRun"`
37+
OnStart bool `json:"onStart"` // rebalance on start
3738

3839
PositionMap PositionMap `persistence:"positionMap"`
3940
ProfitStatsMap ProfitStatsMap `persistence:"profitStatsMap"`
@@ -114,6 +115,12 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
114115
s.activeOrderBook = bbgo.NewActiveOrderBook("")
115116
s.activeOrderBook.BindStream(s.session.UserDataStream)
116117

118+
session.UserDataStream.OnStart(func() {
119+
if s.OnStart {
120+
s.rebalance(ctx)
121+
}
122+
})
123+
117124
s.session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
118125
s.rebalance(ctx)
119126
})

0 commit comments

Comments
 (0)