[ENG-1369] Fix daily PnL aggregation to exclude child subaccounts created mid-day (backport #3248)#3266
Closed
mergify[bot] wants to merge 1 commit intorelease/indexer/v9.5.xfrom
Closed
Conversation
Contributor
Author
|
Cherry-pick of 3f8d74c has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
6 tasks
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelist
Fixed a bug in
findAllDailyAggregatewhere child subaccounts created mid-day were incorrectly included in daily PnL aggregations, causing mismatched values between the daily and hourly endpoints.Root Cause:
The
DISTINCT ONquery was selecting the first record of each day for each individual subaccount, which meant newly created child subaccounts would contribute their first record (e.g., from 05:00) while existing subaccounts contributed their 00:00 records. This mixed timestamps from different hours within the same daily aggregate.Changes:
Modified
findAllDailyAggregateto first identify the earliest timestamp for each day across ALL subaccountsOnly aggregate records that match that earliest timestamp (typically 00:00:00)
Child subaccounts without records at the earliest timestamp are now correctly excluded from that day's aggregate
This ensures daily aggregated values match hourly aggregated values at 00:00 timestamps
Impact:
Daily PnL endpoint now returns consistent values that match the hourly endpoint at 00:00:00
Fixes incorrect equity, totalPnl, and netTransfers calculations when child subaccounts are created mid-day
Example: For Nov 11, the bug caused equity of 8320.45 (mixing 00:00 and 05:00 data) instead of correct value of 7823.86 (only 00:00 data)
Test Plan
Unit Tests:
Added test Successfully handles child subaccounts created mid-day by excluding them from daily aggregation which verifies:
Day 1: Only parent exists → aggregates only parent
Day 2: Child created at 05:00 → aggregates only parent (at 00:00), excludes child
Day 3: Both have 00:00 records → aggregates both correctly
Added test Daily aggregated values should match hourly aggregated values at 00:00 timestamps which verifies consistency between daily and hourly endpoints across multiple days
Author/Reviewer Checklist
state-breakinglabel.indexer-postgres-breakinglabel.PrepareProposalorProcessProposal, manually add the labelproposal-breaking.feature:[feature-name].backport/[branch-name].refactor,chore,bug.Summary by CodeRabbit
Bug Fixes
Tests
This is an automatic backport of pull request #3248 done by [Mergify](https://mergify.com).