95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import type { KisRuntimeCredentials } from "@/features/settings/store/use-kis-runtime-store";
|
|
import {
|
|
buildKisRequestHeaders,
|
|
resolveKisApiErrorMessage,
|
|
type KisApiErrorPayload,
|
|
} from "@/features/settings/apis/kis-api-utils";
|
|
import type {
|
|
DashboardActivityResponse,
|
|
DashboardBalanceResponse,
|
|
DashboardIndicesResponse,
|
|
} from "@/features/dashboard/types/dashboard.types";
|
|
|
|
/**
|
|
* @file features/dashboard/apis/dashboard.api.ts
|
|
* @description 대시보드 잔고/지수 API 클라이언트
|
|
*/
|
|
|
|
/**
|
|
* 계좌 잔고/보유종목을 조회합니다.
|
|
* @param credentials KIS 인증 정보
|
|
* @returns 잔고 응답
|
|
* @see app/api/kis/domestic/balance/route.ts 서버 라우트
|
|
*/
|
|
export async function fetchDashboardBalance(
|
|
credentials: KisRuntimeCredentials,
|
|
): Promise<DashboardBalanceResponse> {
|
|
const response = await fetch("/api/kis/domestic/balance", {
|
|
method: "GET",
|
|
headers: buildKisRequestHeaders(credentials, { includeAccountNo: true }),
|
|
cache: "no-store",
|
|
});
|
|
|
|
const payload = (await response.json()) as
|
|
| DashboardBalanceResponse
|
|
| KisApiErrorPayload;
|
|
|
|
if (!response.ok) {
|
|
throw new Error(resolveKisApiErrorMessage(payload, "잔고 조회 중 오류가 발생했습니다."));
|
|
}
|
|
|
|
return payload as DashboardBalanceResponse;
|
|
}
|
|
|
|
/**
|
|
* 시장 지수(KOSPI/KOSDAQ)를 조회합니다.
|
|
* @param credentials KIS 인증 정보
|
|
* @returns 지수 응답
|
|
* @see app/api/kis/domestic/indices/route.ts 서버 라우트
|
|
*/
|
|
export async function fetchDashboardIndices(
|
|
credentials: KisRuntimeCredentials,
|
|
): Promise<DashboardIndicesResponse> {
|
|
const response = await fetch("/api/kis/domestic/indices", {
|
|
method: "GET",
|
|
headers: buildKisRequestHeaders(credentials),
|
|
cache: "no-store",
|
|
});
|
|
|
|
const payload = (await response.json()) as
|
|
| DashboardIndicesResponse
|
|
| KisApiErrorPayload;
|
|
|
|
if (!response.ok) {
|
|
throw new Error(resolveKisApiErrorMessage(payload, "지수 조회 중 오류가 발생했습니다."));
|
|
}
|
|
|
|
return payload as DashboardIndicesResponse;
|
|
}
|
|
|
|
/**
|
|
* 주문내역/매매일지(활동 데이터)를 조회합니다.
|
|
* @param credentials KIS 인증 정보
|
|
* @returns 활동 데이터 응답
|
|
* @see app/api/kis/domestic/activity/route.ts 서버 라우트
|
|
*/
|
|
export async function fetchDashboardActivity(
|
|
credentials: KisRuntimeCredentials,
|
|
): Promise<DashboardActivityResponse> {
|
|
const response = await fetch("/api/kis/domestic/activity", {
|
|
method: "GET",
|
|
headers: buildKisRequestHeaders(credentials, { includeAccountNo: true }),
|
|
cache: "no-store",
|
|
});
|
|
|
|
const payload = (await response.json()) as
|
|
| DashboardActivityResponse
|
|
| KisApiErrorPayload;
|
|
|
|
if (!response.ok) {
|
|
throw new Error(resolveKisApiErrorMessage(payload, "활동 데이터 조회 중 오류가 발생했습니다."));
|
|
}
|
|
|
|
return payload as DashboardActivityResponse;
|
|
}
|