xdepthmaker: remove legacy s.activeMakerOrders

This commit is contained in:
c9s 2023-11-28 16:32:26 +08:00
parent e0686d11c8
commit 99723fc1f4
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -132,8 +132,7 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
s.orderStore = core.NewOrderStore(s.Position.Symbol) s.orderStore = core.NewOrderStore(s.Position.Symbol)
s.orderStore.BindStream(hedgeSession.UserDataStream) s.orderStore.BindStream(hedgeSession.UserDataStream)
s.orderStore.BindStream(makerSession.UserDataStream) s.orderStore.BindStream(makerSession.UserDataStream)
s.tradeCollector = core.NewTradeCollector(s.Position.Symbol, s.Position, s.orderStore) s.tradeCollector = core.NewTradeCollector(symbol, s.Position, s.orderStore)
return nil return nil
} }
@ -197,8 +196,6 @@ type Strategy struct {
// pricingBook is the order book (depth) from the hedging session // pricingBook is the order book (depth) from the hedging session
pricingBook *types.StreamOrderBook pricingBook *types.StreamOrderBook
activeMakerOrders *bbgo.ActiveOrderBook
hedgeErrorLimiter *rate.Limiter hedgeErrorLimiter *rate.Limiter
hedgeErrorRateReservation *rate.Reservation hedgeErrorRateReservation *rate.Reservation
@ -305,9 +302,6 @@ func (s *Strategy) CrossRun(
s.pricingBook = types.NewStreamBook(s.Symbol) s.pricingBook = types.NewStreamBook(s.Symbol)
s.pricingBook.BindStream(s.hedgeSession.MarketDataStream) s.pricingBook.BindStream(s.hedgeSession.MarketDataStream)
s.activeMakerOrders = bbgo.NewActiveOrderBook(s.Symbol)
s.activeMakerOrders.BindStream(s.makerSession.UserDataStream)
if s.NotifyTrade { if s.NotifyTrade {
s.tradeCollector.OnTrade(notifyTrade) s.tradeCollector.OnTrade(notifyTrade)
} }
@ -361,7 +355,7 @@ func (s *Strategy) CrossRun(
defer reportTicker.Stop() defer reportTicker.Stop()
defer func() { defer func() {
if err := s.activeMakerOrders.GracefulCancel(context.Background(), s.makerSession.Exchange); err != nil { if err := s.MakerOrderExecutor.GracefulCancel(context.Background()); err != nil {
log.WithError(err).Errorf("can not cancel %s orders", s.Symbol) log.WithError(err).Errorf("can not cancel %s orders", s.Symbol)
} }
}() }()
@ -425,7 +419,7 @@ func (s *Strategy) CrossRun(
shutdownCtx, cancelShutdown := context.WithTimeout(context.TODO(), time.Minute) shutdownCtx, cancelShutdown := context.WithTimeout(context.TODO(), time.Minute)
defer cancelShutdown() defer cancelShutdown()
if err := s.activeMakerOrders.GracefulCancel(shutdownCtx, s.makerSession.Exchange); err != nil { if err := s.MakerOrderExecutor.GracefulCancel(shutdownCtx); err != nil {
log.WithError(err).Errorf("graceful cancel error") log.WithError(err).Errorf("graceful cancel error")
} }
@ -575,13 +569,13 @@ func (s *Strategy) tradeRecover(ctx context.Context) {
} }
func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter) { func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.OrderExecutionRouter) {
if err := s.activeMakerOrders.GracefulCancel(ctx, s.makerSession.Exchange); err != nil { if err := s.MakerOrderExecutor.GracefulCancel(ctx); err != nil {
log.Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol) log.Warnf("there are some %s orders not canceled, skipping placing maker orders", s.Symbol)
s.activeMakerOrders.Print() s.MakerOrderExecutor.ActiveMakerOrders().Print()
return return
} }
if s.activeMakerOrders.NumOfOrders() > 0 { if s.MakerOrderExecutor.ActiveMakerOrders().NumOfOrders() > 0 {
return return
} }
@ -818,14 +812,11 @@ func (s *Strategy) updateQuote(ctx context.Context, orderExecutionRouter bbgo.Or
return return
} }
makerOrders, err := orderExecutionRouter.SubmitOrdersTo(ctx, s.MakerExchange, submitOrders...) _, err := s.MakerOrderExecutor.SubmitOrders(ctx, submitOrders...)
if err != nil { if err != nil {
log.WithError(err).Errorf("order error: %s", err.Error()) log.WithError(err).Errorf("order error: %s", err.Error())
return return
} }
s.activeMakerOrders.Add(makerOrders...)
s.orderStore.Add(makerOrders...)
} }
func selectSessions2( func selectSessions2(