add option to rebalance on start

This commit is contained in:
narumi 2023-03-13 22:43:42 +08:00
parent 640001ffa1
commit 0690518dc7
2 changed files with 8 additions and 0 deletions

View File

@ -39,3 +39,4 @@ exchangeStrategies:
maxAmount: 1_000 # max amount to buy or sell per order
orderType: LIMIT_MAKER # LIMIT, LIMIT_MAKER or MARKET
dryRun: false
onStart: false

View File

@ -34,6 +34,7 @@ type Strategy struct {
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
PositionMap PositionMap `persistence:"positionMap"`
ProfitStatsMap ProfitStatsMap `persistence:"profitStatsMap"`
@ -114,6 +115,12 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
s.activeOrderBook = bbgo.NewActiveOrderBook("")
s.activeOrderBook.BindStream(s.session.UserDataStream)
session.UserDataStream.OnStart(func() {
if s.OnStart {
s.rebalance(ctx)
}
})
s.session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
s.rebalance(ctx)
})