pivotshort: use notify and always collect trades

This commit is contained in:
c9s 2022-06-05 12:51:45 +08:00
parent e7078edacd
commit 4bd322feb4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -173,6 +173,7 @@ func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Valu
s.orderStore.Add(createdOrders...) s.orderStore.Add(createdOrders...)
s.activeMakerOrders.Add(createdOrders...) s.activeMakerOrders.Add(createdOrders...)
s.tradeCollector.Process()
return err return err
} }
func (s *Strategy) InstanceID() string { func (s *Strategy) InstanceID() string {
@ -317,18 +318,17 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
R := kline.Close.Div(s.Position.AverageCost) R := kline.Close.Div(s.Position.AverageCost)
if R.Compare(fixedpoint.One.Add(s.Exit.StopLossPercentage)) > 0 { if R.Compare(fixedpoint.One.Add(s.Exit.StopLossPercentage)) > 0 {
// SL // SL
log.Infof("%s SL triggered", s.Symbol) s.Notify("%s SL triggered", s.Symbol)
s.ClosePosition(ctx, fixedpoint.One) s.ClosePosition(ctx, fixedpoint.One)
s.tradeCollector.Process() s.tradeCollector.Process()
} else if R.Compare(fixedpoint.One.Sub(s.Exit.TakeProfitPercentage)) < 0 { } else if R.Compare(fixedpoint.One.Sub(s.Exit.TakeProfitPercentage)) < 0 {
// TP // TP
log.Infof("%s TP triggered", s.Symbol) s.Notify("%s TP triggered", s.Symbol)
s.ClosePosition(ctx, fixedpoint.One) s.ClosePosition(ctx, fixedpoint.One)
} else if kline.GetLowerShadowHeight().Div(kline.Close).Compare(s.Exit.ShadowTPRatio) > 0 { } else if kline.GetLowerShadowHeight().Div(kline.Close).Compare(s.Exit.ShadowTPRatio) > 0 {
// shadow TP // shadow TP
log.Infof("%s shadow TP triggered", s.Symbol) s.Notify("%s shadow TP triggered", s.Symbol)
s.ClosePosition(ctx, fixedpoint.One) s.ClosePosition(ctx, fixedpoint.One)
s.tradeCollector.Process()
} }
} }
s.LastLow = fixedpoint.Zero s.LastLow = fixedpoint.Zero