mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 08:45:16 +00:00
add option to rebalance on start
This commit is contained in:
parent
640001ffa1
commit
0690518dc7
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user