대시보드 구현
This commit is contained in:
45
app/api/kis/domestic/_shared.ts
Normal file
45
app/api/kis/domestic/_shared.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user