feat: add portfolio

This commit is contained in:
2026-08-13 22:45:00 +03:00
parent 6e89c1a8f7
commit 9156f29707
11 changed files with 594 additions and 12 deletions
@@ -0,0 +1,36 @@
import { useQuery } from "@tanstack/react-query";
import { apiClient } from "../../../shared/api";
import type { paths } from "../../../shared/api/generated/schema";
export const portfolioQueryKey = (accountId: string) =>
["portfolio", accountId] as const;
export const portfolioQueryPolicy = {
staleTime: 30_000,
retry: false,
} as const;
export type Portfolio =
paths["/api/v1/brokerage-accounts/{accountId}/portfolio"]["get"]["responses"][200]["content"]["application/json"];
export function usePortfolio(
accountId: string | undefined,
accessToken: string | null,
) {
return useQuery({
queryKey: portfolioQueryKey(accountId ?? ""),
enabled: Boolean(accountId && accessToken),
...portfolioQueryPolicy,
queryFn: async () => {
const { data, error } = await apiClient.GET(
"/api/v1/brokerage-accounts/{accountId}/portfolio",
{
params: { path: { accountId: accountId ?? "" } },
headers: { Authorization: `Bearer ${accessToken}` },
},
);
if (error) throw error;
return data as Portfolio;
},
});
}