40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
AUTOTRADE_API_ERROR_CODE,
|
|
AUTOTRADE_WORKER_TOKEN_HEADER,
|
|
createAutotradeErrorResponse,
|
|
isAutotradeWorkerAuthorized,
|
|
listAutotradeSessions,
|
|
sanitizeAutotradeError,
|
|
sweepExpiredAutotradeSessions,
|
|
} from "@/app/api/autotrade/_shared";
|
|
|
|
export async function POST(request: Request) {
|
|
if (!isAutotradeWorkerAuthorized(request.headers)) {
|
|
return createAutotradeErrorResponse({
|
|
status: 401,
|
|
code: AUTOTRADE_API_ERROR_CODE.AUTH_REQUIRED,
|
|
message: `${AUTOTRADE_WORKER_TOKEN_HEADER} 인증이 필요합니다.`,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const sweep = sweepExpiredAutotradeSessions();
|
|
const sessions = listAutotradeSessions();
|
|
|
|
return NextResponse.json({
|
|
ok: true,
|
|
sweep,
|
|
runningSessions: sessions.filter((session) => session.runtimeState === "RUNNING").length,
|
|
stoppedSessions: sessions.filter((session) => session.runtimeState === "STOPPED").length,
|
|
checkedAt: new Date().toISOString(),
|
|
});
|
|
} catch (error) {
|
|
return createAutotradeErrorResponse({
|
|
status: 500,
|
|
code: AUTOTRADE_API_ERROR_CODE.INTERNAL,
|
|
message: sanitizeAutotradeError(error, "자동매매 워커 점검 중 오류가 발생했습니다."),
|
|
});
|
|
}
|
|
}
|