grid2: add newOrderUpdateHandler and send profit to notification

This commit is contained in:
c9s 2022-12-15 18:47:45 +08:00
parent c2133a1712
commit 051aa19989
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -349,6 +349,9 @@ func (s *Strategy) processFilledOrder(o types.Order) {
s.logger.Infof("GENERATED GRID PROFIT: %+v", profit)
s.GridProfitStats.AddProfit(profit)
bbgo.Notify(profit)
bbgo.Notify(s.GridProfitStats)
case types.SideTypeBuy:
newSide = types.SideTypeSell
if !s.ProfitSpread.IsZero() {
@ -652,6 +655,13 @@ func (s *Strategy) newTriggerPriceHandler(ctx context.Context, session *bbgo.Exc
})
}
func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.ExchangeSession) func(o types.Order) {
return func(o types.Order) {
s.handleOrderFilled(o)
bbgo.Sync(ctx, s)
}
}
func (s *Strategy) newStopLossPriceHandler(ctx context.Context, session *bbgo.ExchangeSession) types.KLineCallback {
return types.KLineWith(s.Symbol, types.Interval1m, func(k types.KLine) {
if s.StopLossPrice.Compare(k.Low) < 0 {
@ -1034,10 +1044,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.
orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) {
bbgo.Sync(ctx, s)
})
orderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) {
s.handleOrderFilled(o)
bbgo.Sync(context.Background(), s)
})
orderExecutor.ActiveMakerOrders().OnFilled(s.newOrderUpdateHandler(ctx, session))
s.orderExecutor = orderExecutor