보안 점검 및 대시보드 문구 수정
This commit is contained in:
@@ -33,14 +33,6 @@ export function normalizeTradingEnv(value?: string): KisTradingEnv {
|
||||
return (value ?? "mock").toLowerCase() === "real" ? "real" : "mock";
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 거래 환경을 반환합니다.
|
||||
* @returns real | mock
|
||||
*/
|
||||
export function getKisTradingEnv() {
|
||||
return normalizeTradingEnv(process.env.KIS_TRADING_ENV);
|
||||
}
|
||||
|
||||
/**
|
||||
* KIS 웹소켓 URL을 반환합니다.
|
||||
* @param tradingEnvInput 거래 모드(real/mock)
|
||||
@@ -50,10 +42,10 @@ export function getKisWebSocketUrl(tradingEnvInput?: KisTradingEnv) {
|
||||
const tradingEnv = normalizeTradingEnv(tradingEnvInput);
|
||||
|
||||
if (tradingEnv === "real") {
|
||||
return process.env.KIS_WS_URL_REAL ?? DEFAULT_KIS_REAL_WS_URL;
|
||||
return DEFAULT_KIS_REAL_WS_URL;
|
||||
}
|
||||
|
||||
return process.env.KIS_WS_URL_MOCK ?? DEFAULT_KIS_MOCK_WS_URL;
|
||||
return DEFAULT_KIS_MOCK_WS_URL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,14 +54,7 @@ export function getKisWebSocketUrl(tradingEnvInput?: KisTradingEnv) {
|
||||
* @returns 사용 가능 여부
|
||||
*/
|
||||
export function hasKisConfig(input?: KisCredentialInput) {
|
||||
if (input?.appKey && input?.appSecret) return true;
|
||||
|
||||
const env = getKisTradingEnv();
|
||||
if (env === "real") {
|
||||
return Boolean(process.env.KIS_APP_KEY_REAL && process.env.KIS_APP_SECRET_REAL);
|
||||
}
|
||||
|
||||
return Boolean(process.env.KIS_APP_KEY_MOCK && process.env.KIS_APP_SECRET_MOCK);
|
||||
return Boolean(input?.appKey?.trim() && input?.appSecret?.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +63,7 @@ export function hasKisConfig(input?: KisCredentialInput) {
|
||||
* @returns tradingEnv/appKey/appSecret/baseUrl
|
||||
*/
|
||||
export function getKisConfig(input?: KisCredentialInput): KisConfig {
|
||||
if (input?.appKey && input?.appSecret) {
|
||||
if (input?.appKey?.trim() && input?.appSecret?.trim()) {
|
||||
const tradingEnv = normalizeTradingEnv(input.tradingEnv);
|
||||
const baseUrl =
|
||||
input.baseUrl ??
|
||||
@@ -86,37 +71,13 @@ export function getKisConfig(input?: KisCredentialInput): KisConfig {
|
||||
|
||||
return {
|
||||
tradingEnv,
|
||||
appKey: input.appKey,
|
||||
appSecret: input.appSecret,
|
||||
appKey: input.appKey.trim(),
|
||||
appSecret: input.appSecret.trim(),
|
||||
baseUrl,
|
||||
};
|
||||
}
|
||||
|
||||
const tradingEnv = getKisTradingEnv();
|
||||
|
||||
if (tradingEnv === "real") {
|
||||
const appKey = process.env.KIS_APP_KEY_REAL;
|
||||
const appSecret = process.env.KIS_APP_SECRET_REAL;
|
||||
const baseUrl = process.env.KIS_BASE_URL_REAL ?? DEFAULT_KIS_REAL_BASE_URL;
|
||||
|
||||
if (!appKey || !appSecret) {
|
||||
throw new Error(
|
||||
"KIS 실전투자 키가 없습니다. KIS_APP_KEY_REAL, KIS_APP_SECRET_REAL 환경변수를 설정하세요.",
|
||||
);
|
||||
}
|
||||
|
||||
return { tradingEnv, appKey, appSecret, baseUrl };
|
||||
}
|
||||
|
||||
const appKey = process.env.KIS_APP_KEY_MOCK;
|
||||
const appSecret = process.env.KIS_APP_SECRET_MOCK;
|
||||
const baseUrl = process.env.KIS_BASE_URL_MOCK ?? DEFAULT_KIS_MOCK_BASE_URL;
|
||||
|
||||
if (!appKey || !appSecret) {
|
||||
throw new Error(
|
||||
"KIS 모의투자 키가 없습니다. KIS_APP_KEY_MOCK, KIS_APP_SECRET_MOCK 환경변수를 설정하세요.",
|
||||
);
|
||||
}
|
||||
|
||||
return { tradingEnv, appKey, appSecret, baseUrl };
|
||||
throw new Error(
|
||||
"KIS API 키가 없습니다. 설정 화면에서 앱 키와 앱 시크릿을 먼저 입력해 주세요.",
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user