Files
auto-trade/app/api/kis/domestic/_shared.ts

46 lines
1.5 KiB
TypeScript
Raw Normal View History

2026-02-12 14:20:07 +09:00
import { parseKisAccountParts } from "@/lib/kis/account";
import {
normalizeTradingEnv,
type KisCredentialInput,
} from "@/lib/kis/config";
/**
* @description KIS .
* @param headers
* @returns KIS
* @see app/api/kis/domestic/balance/route.ts API
* @see app/api/kis/domestic/indices/route.ts API
*/
export function readKisCredentialsFromHeaders(headers: Headers): KisCredentialInput {
const appKey = headers.get("x-kis-app-key")?.trim();
const appSecret = headers.get("x-kis-app-secret")?.trim();
const tradingEnv = normalizeTradingEnv(
headers.get("x-kis-trading-env") ?? undefined,
);
return {
appKey,
appSecret,
tradingEnv,
};
}
/**
* @description ( ) (8-2) .
* @param headers
* @returns (8 + 2) null
* @see app/api/kis/domestic/balance/route.ts
*/
export function readKisAccountParts(headers: Headers) {
const headerAccountNo = headers.get("x-kis-account-no");
const headerAccountProductCode = headers.get("x-kis-account-product-code");
const envAccountNo = process.env.KIS_ACCOUNT_NO;
const envAccountProductCode = process.env.KIS_ACCOUNT_PRODUCT_CODE;
return (
parseKisAccountParts(headerAccountNo, headerAccountProductCode) ??
parseKisAccountParts(envAccountNo, envAccountProductCode)
);
}