From 188231e2fbe1c462c60930e924f2957d50e02ebc Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 6 Mar 2024 17:47:18 +0800 Subject: [PATCH] add more logs to profitFixer --- pkg/strategy/xdepthmaker/profitfixer.go | 2 ++ pkg/strategy/xdepthmaker/strategy.go | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/strategy/xdepthmaker/profitfixer.go b/pkg/strategy/xdepthmaker/profitfixer.go index 66905580e..129792b15 100644 --- a/pkg/strategy/xdepthmaker/profitfixer.go +++ b/pkg/strategy/xdepthmaker/profitfixer.go @@ -47,6 +47,7 @@ func (f *ProfitFixer) batchQueryTrades( } func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *types.ProfitStats, position *types.Position) error { + log.Infof("starting profitFixer with time range %s <=> %s", since, until) var mu sync.Mutex var allTrades = make([]types.Trade, 0, 1000) @@ -80,5 +81,6 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *ty position.AddTrade(trade) } + log.Infof("profitFixer done: profitStats and position are updated from %d trades", len(allTrades)) return nil } diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index d87d2bd84..e875014ea 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -320,6 +320,8 @@ func (s *Strategy) CrossRun( log.Infof("makerSession: %s hedgeSession: %s", makerSession.Name, hedgeSession.Name) if s.ProfitFixerConfig != nil { + log.Infof("profitFixer is enabled, checking checkpoint: %+v", s.ProfitFixerConfig.TradesSince) + if s.ProfitFixerConfig.TradesSince.Time().IsZero() { return errors.New("tradesSince time can not be zero") } @@ -329,8 +331,15 @@ func (s *Strategy) CrossRun( s.CrossExchangeMarketMakingStrategy.ProfitStats = types.NewProfitStats(makerMarket) fixer := NewProfitFixer(makerMarket) - fixer.AddExchange(makerSession.Name, makerSession.Exchange.(types.ExchangeTradeHistoryService)) - fixer.AddExchange(hedgeSession.Name, hedgeSession.Exchange.(types.ExchangeTradeHistoryService)) + if ss, ok := makerSession.Exchange.(types.ExchangeTradeHistoryService); ok { + log.Infof("adding makerSession %s to profitFixer", makerSession.Name) + fixer.AddExchange(makerSession.Name, ss) + } + + if ss, ok := hedgeSession.Exchange.(types.ExchangeTradeHistoryService); ok { + log.Infof("adding hedgeSession %s to profitFixer", hedgeSession.Name) + fixer.AddExchange(hedgeSession.Name, ss) + } if err2 := fixer.Fix(ctx, s.ProfitFixerConfig.TradesSince.Time(), time.Now(), s.CrossExchangeMarketMakingStrategy.ProfitStats, s.CrossExchangeMarketMakingStrategy.Position); err2 != nil { return err2