Skip to content

Commit

Permalink
common: pull out aggregateAllTrades from Fix() method
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Mar 6, 2024
1 parent acb2322 commit 83b5269
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/strategy/common/profit_fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,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)
func (f *ProfitFixer) aggregateAllTrades(ctx context.Context, market types.Market, since, until time.Time) ([]types.Trade, error) {
var mu sync.Mutex
var allTrades = make([]types.Trade, 0, 1000)

Expand All @@ -59,7 +58,7 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *ty
sessionName := n
service := s
g.Go(func() error {
log.Infof("batch querying %s trade history from %s since %s until %s", f.market.Symbol, sessionName, since.String(), until.String())
log.Infof("batch querying %s trade history from %s since %s until %s", market.Symbol, sessionName, since.String(), until.String())
trades, err := f.batchQueryTrades(subCtx, service, f.market.Symbol, since, until)
if err != nil {
log.WithError(err).Errorf("unable to batch query trades for fixer")
Expand All @@ -74,10 +73,20 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *ty
}

if err := g.Wait(); err != nil {
return err
return nil, err
}

allTrades = types.SortTradesAscending(allTrades)
return allTrades, nil
}

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)
allTrades, err := f.aggregateAllTrades(ctx, f.market, since, until)
if err != nil {
return err
}

f.FixFromTrades(allTrades, stats, position)
return nil
}
Expand Down

0 comments on commit 83b5269

Please sign in to comment.