skip buy records not covered by selector
This commit is contained in:
+15
-5
@@ -68,7 +68,8 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-progTicker.C:
|
||||
slog.InfoContext(ctx, "Progress update",
|
||||
slog.InfoContext(
|
||||
ctx, "Progress update",
|
||||
slog.Int64("total_records", buysCount+sellsCount),
|
||||
slog.Int64("sell_records", sellsCount),
|
||||
slog.Int64("buy_records", buysCount),
|
||||
@@ -108,10 +109,13 @@ func BuildReport(ctx context.Context, reader RecordReader, writer ReportWriter,
|
||||
|
||||
// processRecord either adds buys to the queue or consumes buys from the queue when processing a
|
||||
// sell record.
|
||||
// Selectors are only applied on sells for performance reasons. It's much cheaper to just accumulate
|
||||
// buys and only actually inspect a record once a sell happens due to potential network requests to
|
||||
//
|
||||
// NOTE: Selectors are only applied when processing sell records for performance reasons. It's much
|
||||
// cheaper to just accumulate buys and only actually inspect any records once a sell happens. This
|
||||
// avoids potential network requests to for every single record.
|
||||
func processRecord(ctx context.Context, q *FillerQueue, rec Record, sel Selector, writer ReportWriter) error {
|
||||
slog.Debug("Report: processing record",
|
||||
slog.Debug(
|
||||
"Report: processing record",
|
||||
slog.String("symbol", rec.Symbol()),
|
||||
slog.String("side", rec.Kind().String()),
|
||||
)
|
||||
@@ -122,7 +126,8 @@ func processRecord(ctx context.Context, q *FillerQueue, rec Record, sel Selector
|
||||
|
||||
case KindSell:
|
||||
if !sel(rec) {
|
||||
slog.Debug("Report: skipping record",
|
||||
slog.Debug(
|
||||
"Report: skipping record",
|
||||
slog.String("symbol", rec.Symbol()),
|
||||
slog.String("side", rec.Kind().String()),
|
||||
)
|
||||
@@ -137,6 +142,11 @@ func processRecord(ctx context.Context, q *FillerQueue, rec Record, sel Selector
|
||||
return ErrInsufficientBoughtVolume
|
||||
}
|
||||
|
||||
// Since we don't apply selectors while processing buys we need to apply them here.
|
||||
if !sel(buy) {
|
||||
continue
|
||||
}
|
||||
|
||||
matchedQty, filled := buy.Fill(unmatchedQty)
|
||||
|
||||
if filled {
|
||||
|
||||
Reference in New Issue
Block a user