Files
auto-trade/lib/kis/account.ts

51 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2026-02-12 14:20:07 +09:00
/**
* @file lib/kis/account.ts
* @description KIS (8-2) /
*/
export interface KisAccountParts {
accountNo: string;
accountProductCode: string;
}
/**
* KIS (8-2) .
* @param accountNoInput (: 12345678-01 1234567801)
* @param accountProductCodeInput (2, )
* @returns accountNo/accountProductCode
* @see app/api/kis/domestic/balance/route.ts API에서 .
*/
export function parseKisAccountParts(
accountNoInput?: string | null,
accountProductCodeInput?: string | null,
): KisAccountParts | null {
const accountDigits = toDigits(accountNoInput);
const productDigits = toDigits(accountProductCodeInput);
if (accountDigits.length >= 10) {
return {
accountNo: accountDigits.slice(0, 8),
accountProductCode: accountDigits.slice(8, 10),
};
}
if (accountDigits.length === 8 && productDigits.length === 2) {
return {
accountNo: accountDigits,
accountProductCode: productDigits,
};
}
return null;
}
/**
* .
* @param value
* @returns
* @see lib/kis/account.ts parseKisAccountParts
*/
function toDigits(value?: string | null) {
return (value ?? "").replace(/\D/g, "");
}