Files
auto-trade/features/dashboard/apis/dashboard.api.ts

124 lines
3.6 KiB
TypeScript
Raw Normal View History

2026-02-12 14:20:07 +09:00
import type { KisRuntimeCredentials } from "@/features/settings/store/use-kis-runtime-store";
2026-02-26 09:05:17 +09:00
import {
buildKisRequestHeaders,
resolveKisApiErrorMessage,
type KisApiErrorPayload,
} from "@/features/settings/apis/kis-api-utils";
2026-02-12 14:20:07 +09:00
import type {
DashboardActivityResponse,
2026-02-12 14:20:07 +09:00
DashboardBalanceResponse,
DashboardIndicesResponse,
2026-03-12 09:26:27 +09:00
DashboardMarketHubResponse,
2026-02-12 14:20:07 +09:00
} 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",
2026-02-26 09:05:17 +09:00
headers: buildKisRequestHeaders(credentials, { includeAccountNo: true }),
2026-02-12 14:20:07 +09:00
cache: "no-store",
});
const payload = (await response.json()) as
| DashboardBalanceResponse
2026-02-26 09:05:17 +09:00
| KisApiErrorPayload;
2026-02-12 14:20:07 +09:00
if (!response.ok) {
2026-02-26 09:05:17 +09:00
throw new Error(resolveKisApiErrorMessage(payload, "잔고 조회 중 오류가 발생했습니다."));
2026-02-12 14:20:07 +09:00
}
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
2026-02-26 09:05:17 +09:00
| KisApiErrorPayload;
2026-02-12 14:20:07 +09:00
if (!response.ok) {
2026-02-26 09:05:17 +09:00
throw new Error(resolveKisApiErrorMessage(payload, "지수 조회 중 오류가 발생했습니다."));
2026-02-12 14:20:07 +09:00
}
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",
2026-02-26 09:05:17 +09:00
headers: buildKisRequestHeaders(credentials, { includeAccountNo: true }),
cache: "no-store",
});
const payload = (await response.json()) as
| DashboardActivityResponse
2026-02-26 09:05:17 +09:00
| KisApiErrorPayload;
if (!response.ok) {
2026-02-26 09:05:17 +09:00
throw new Error(resolveKisApiErrorMessage(payload, "활동 데이터 조회 중 오류가 발생했습니다."));
}
return payload as DashboardActivityResponse;
}
2026-03-12 09:26:27 +09:00
/**
* // .
* @param credentials KIS
* @returns
* @see app/api/kis/domestic/market-hub/route.ts
*/
export async function fetchDashboardMarketHub(
credentials: KisRuntimeCredentials,
): Promise<DashboardMarketHubResponse> {
const response = await fetch("/api/kis/domestic/market-hub", {
method: "GET",
headers: buildKisRequestHeaders(credentials),
cache: "no-store",
});
const payload = (await response.json()) as
| DashboardMarketHubResponse
| KisApiErrorPayload;
if (!response.ok) {
throw new Error(
resolveKisApiErrorMessage(payload, "시장 허브 조회 중 오류가 발생했습니다."),
);
}
return payload as DashboardMarketHubResponse;
}