Skip to content

Commit

Permalink
Move query to view.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwschau committed Dec 13, 2024
1 parent decb5a7 commit 411a4aa
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 79 deletions.
28 changes: 28 additions & 0 deletions indexer/packages/postgres/src/stores/vault-pnl-ticks-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,31 @@ export async function getVaultsPnl(

return result.rows;
}

export async function getLatestVaultPnl(): Promise<PnlTicksFromDatabase[]> {
const result: {
rows: PnlTicksFromDatabase[],
} = await knexReadReplica.getConnection().raw(
`
SELECT
DISTINCT ON ("subaccountId")
"id",
"subaccountId",
"equity",
"totalPnl",
"netTransfers",
"createdAt",
"blockHeight",
"blockTime"
FROM
${VAULT_HOURLY_PNL_VIEW}
ORDER BY
"subaccountId",
"blockTime" DESC
`,
) as unknown as {
rows: PnlTicksFromDatabase[],
};

return result.rows;
}
Loading

0 comments on commit 411a4aa

Please sign in to comment.