mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
common: pull out aggregateAllTrades from Fix() method
This commit is contained in:
parent
acb232242c
commit
83b526940a
|
@ -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 {
|
func (f *ProfitFixer) aggregateAllTrades(ctx context.Context, market types.Market, since, until time.Time) ([]types.Trade, error) {
|
||||||
log.Infof("starting profitFixer with time range %s <=> %s", since, until)
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
var allTrades = make([]types.Trade, 0, 1000)
|
var allTrades = make([]types.Trade, 0, 1000)
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *ty
|
||||||
sessionName := n
|
sessionName := n
|
||||||
service := s
|
service := s
|
||||||
g.Go(func() error {
|
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)
|
trades, err := f.batchQueryTrades(subCtx, service, f.market.Symbol, since, until)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("unable to batch query trades for fixer")
|
log.WithError(err).Errorf("unable to batch query trades for fixer")
|
||||||
|
@ -74,10 +73,20 @@ func (f *ProfitFixer) Fix(ctx context.Context, since, until time.Time, stats *ty
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.Wait(); err != nil {
|
if err := g.Wait(); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
allTrades = types.SortTradesAscending(allTrades)
|
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)
|
f.FixFromTrades(allTrades, stats, position)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user