-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TRA-571] Add query to get intervaled PnL ticks. #2247
Conversation
WalkthroughThe changes introduce a feature for retrieving profit and loss (PnL) ticks at specified intervals, namely hourly and daily. This includes the addition of an asynchronous function Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant Database
Client->>API: Request PnL ticks at intervals
API->>Database: Execute SQL query for PnL ticks
Database-->>API: Return PnL ticks data
API-->>Client: Send PnL ticks response
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
indexer/packages/postgres/__tests__/stores/pnl-ticks-table.test.ts (1)
594-594
: Nitpick: Remove the empty line.The empty line is unnecessary and can be removed.
Apply this diff to remove the empty line:
- async function setupIntervalPnlTicks(): Promise<PnlTicksFromDatabase[]> {
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- indexer/packages/postgres/tests/stores/pnl-ticks-table.test.ts (3 hunks)
- indexer/packages/postgres/src/stores/pnl-ticks-table.ts (2 hunks)
- indexer/packages/postgres/src/types/pnl-ticks-types.ts (1 hunks)
Additional comments not posted (5)
indexer/packages/postgres/src/types/pnl-ticks-types.ts (1)
25-29
: LGTM!The addition of the
PnlTickInterval
enum is a clean and effective way to represent the supported PnL tick intervals. Using string enum members enhances code readability and maintainability. This change aligns well with the PR objective of enabling PnL tick retrieval at specific intervals.indexer/packages/postgres/src/stores/pnl-ticks-table.ts (1)
464-507
: LGTM! Verify the function usage.The
getPnlTicksAtIntervals
function looks good and effectively retrieves PnL ticks at the specified intervals for the given subaccounts and time range. The SQL query is well-structured and uses a windowing function to efficiently get the first PnL tick of each interval window.To ensure the function is being used correctly, you can run the following script:
Verification successful
Function Usage Verified
The
getPnlTicksAtIntervals
function is used in the test fileindexer/packages/postgres/__tests__/stores/pnl-ticks-table.test.ts
, indicating that it is being tested. This suggests that the function's behavior is verified, supporting its correctness and integration.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `getPnlTicksAtIntervals` function. # Test: Search for the function usage. Expect: Occurrences with correct arguments. ast-grep --lang typescript --pattern $'getPnlTicksAtIntervals($_, $_, $_)'Length of output: 75
Script:
#!/bin/bash # Description: Search for the usage of `getPnlTicksAtIntervals` function using ripgrep. # Test: Search for the function name in the codebase. Expect: Occurrences of the function name. rg 'getPnlTicksAtIntervals' --type=ts --type=tsx --type=js --type=jsx -A 2Length of output: 102
Script:
#!/bin/bash # Description: Search for the usage of `getPnlTicksAtIntervals` function using ripgrep. # Test: Search for the function name in the codebase. Expect: Occurrences of the function name. rg 'getPnlTicksAtIntervals' --type=ts --type=js --type=jsx -A 2Length of output: 91
Script:
#!/bin/bash # Description: Search for the usage of `getPnlTicksAtIntervals` function using ripgrep. # Test: Search for the function name in the codebase. Expect: Occurrences of the function name. rg 'getPnlTicksAtIntervals' --type=ts --type=js -A 2Length of output: 647
indexer/packages/postgres/__tests__/stores/pnl-ticks-table.test.ts (3)
5-5
: LGTM!The imports are necessary for the new test cases.
Also applies to: 8-8
444-487
: Excellent test case!The test case is well-structured and covers the important scenarios for the
getPnlTicksAtIntervals
function. It uses theit.each
function to avoid code duplication for hourly and daily intervals, and a setup function to create test data. The test case also compares the result with the expected results, which is a good practice.
595-708
: Great setup function!The setup function is well-structured and creates test data at different time intervals, which is necessary for testing the
getPnlTicksAtIntervals
function. It uses theDateTime
class from theluxon
library to create time intervals, which is a good practice. The setup function also returns the created PnL ticks, which can be used in the test case to compare with the expected results.
* @param subaccountIds Set of subaccounts to get pnl ticks for. | ||
* @returns | ||
*/ | ||
export async function getPnlTicksAtIntervals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where will this be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the vault controller.
Changelist
Add new query function to pnl ticks table to get pnl ticks with specific interval / timeframe to support vault pnl queries (need coarser interval than hourly).
Test Plan
Unit tests.
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.Summary by CodeRabbit
New Features
Bug Fixes