strategy: return the createdOrders objects instead in submitOrders()

This commit is contained in:
Andy Cheng 2022-01-24 12:11:26 +08:00
parent f673fc30ad
commit 1bd787f44c
No known key found for this signature in database
GPG Key ID: 936427CF651A9D28

View File

@ -248,7 +248,7 @@ func (s *Strategy) LoadState() error {
return nil
}
func (s *Strategy) submitOrders(ctx context.Context, orderExecutor bbgo.OrderExecutor, orderForms ...types.SubmitOrder) ([]uint64, error) {
func (s *Strategy) submitOrders(ctx context.Context, orderExecutor bbgo.OrderExecutor, orderForms ...types.SubmitOrder) (types.OrderSlice, error) {
for _, o := range orderForms {
s.Notifiability.Notify(o)
}
@ -260,7 +260,7 @@ func (s *Strategy) submitOrders(ctx context.Context, orderExecutor bbgo.OrderExe
s.orderStore.Add(createdOrders...)
s.tradeCollector.Emit()
return createdOrders.IDs(), nil
return createdOrders, nil
}
// Cancel order
@ -411,11 +411,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// Place new order if the target price is higher than the minimum target price
if s.trailingStopControl.IsHigherThanMin(minTargetPrice) {
orderForm := s.trailingStopControl.GenerateStopOrder(position.Base.Float64())
ids, err := s.submitOrders(ctx, orderExecutor, orderForm)
orders, err := s.submitOrders(ctx, orderExecutor, orderForm)
if err != nil {
log.WithError(err).Error("submit profit trailing stop order error")
} else {
s.trailingStopControl.OrderID = ids[0]
s.trailingStopControl.OrderID = orders.IDs()[0]
}
}
}
@ -464,11 +464,11 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// Place new order if the target price is higher than the minimum target price
if s.trailingStopControl.IsHigherThanMin(minTargetPrice) {
orderForm := s.trailingStopControl.GenerateStopOrder(s.state.Position.Base.Float64())
ids, err := s.submitOrders(ctx, orderExecutor, orderForm)
orders, err := s.submitOrders(ctx, orderExecutor, orderForm)
if err != nil {
log.WithError(err).Error("submit profit trailing stop order error")
} else {
s.trailingStopControl.OrderID = ids[0]
s.trailingStopControl.OrderID = orders.IDs()[0]
}
}
}