From 8e5bb1b6e447cc48e8927651e6fe13695efc6b5a Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 4 Nov 2024 16:06:17 +0800 Subject: [PATCH] xalign: improve logs --- pkg/strategy/common/strategy.go | 5 ++++- pkg/strategy/liquiditymaker/strategy.go | 4 +++- pkg/strategy/xalign/strategy.go | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/strategy/common/strategy.go b/pkg/strategy/common/strategy.go index 26240b50e..026f5974a 100644 --- a/pkg/strategy/common/strategy.go +++ b/pkg/strategy/common/strategy.go @@ -38,7 +38,9 @@ type Strategy struct { RiskController } -func (s *Strategy) Initialize(ctx context.Context, environ *bbgo.Environment, session *bbgo.ExchangeSession, market types.Market, strategyID, instanceID string) { +func (s *Strategy) Initialize( + ctx context.Context, environ *bbgo.Environment, session *bbgo.ExchangeSession, market types.Market, strategyID, instanceID string, +) { s.parent = ctx s.ctx, s.cancel = context.WithCancel(ctx) @@ -92,6 +94,7 @@ func (s *Strategy) IsHalted(t time.Time) bool { if s.circuitBreakRiskControl == nil { return false } + _, isHalted := s.circuitBreakRiskControl.IsHalted(t) return isHalted } diff --git a/pkg/strategy/liquiditymaker/strategy.go b/pkg/strategy/liquiditymaker/strategy.go index 5e61961f1..20dcf6f98 100644 --- a/pkg/strategy/liquiditymaker/strategy.go +++ b/pkg/strategy/liquiditymaker/strategy.go @@ -168,7 +168,9 @@ func (s *Strategy) liquidityWorker(ctx context.Context, interval types.Interval) return case <-metricsTicker.C: - s.updateMarketMetrics(ctx) + if err := s.updateMarketMetrics(ctx); err != nil { + s.logger.WithError(err).Errorf("unable to update market metrics") + } case <-ticker.C: s.placeLiquidityOrders(ctx) diff --git a/pkg/strategy/xalign/strategy.go b/pkg/strategy/xalign/strategy.go index 3920aa981..db1fd9820 100644 --- a/pkg/strategy/xalign/strategy.go +++ b/pkg/strategy/xalign/strategy.go @@ -502,7 +502,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange q := s.calculateRefillQuantity(totalBalances, currency, expectedBalance) if s.Duration > 0 { - log.Infof("checking fault balance records...") + log.Infof("checking %s fault balance records...", currency) if faultBalance, ok := s.faultBalanceRecords[currency]; ok && len(faultBalance) > 0 { if time.Since(faultBalance[0].Time) < s.Duration.Duration() { log.Infof("%s fault record since: %s < persistence period %s", currency, faultBalance[0].Time, s.Duration.Duration()) @@ -513,9 +513,9 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange selectedSession, submitOrder := s.selectSessionForCurrency(ctx, sessions, currency, q) if selectedSession != nil && submitOrder != nil { - log.Infof("placing order on %s: %+v", selectedSession.Name, submitOrder) + log.Infof("placing %s order on %s: %+v", submitOrder.Symbol, selectedSession.Name, submitOrder) - bbgo.Notify("Aligning position on exchange session %s, delta: %f", selectedSession.Name, q.Float64(), submitOrder) + bbgo.Notify("Aligning %s position on exchange session %s, delta: %f", currency, selectedSession.Name, q.Float64(), submitOrder) if s.DryRun { return @@ -523,7 +523,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange createdOrder, err := selectedSession.Exchange.SubmitOrder(ctx, *submitOrder) if err != nil { - log.WithError(err).Errorf("can not place order") + log.WithError(err).Errorf("can not place order: %+v", submitOrder) return } @@ -533,6 +533,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange } else { log.Errorf("orderbook %s not found", selectedSession.Name) } + s.orderBooks[selectedSession.Name].Add(*createdOrder) } }