알림목록 전략지표 없음 문제 수정
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
/**
|
||||
* 매매 시그널 알림 — strategyId·전략명으로 StrategyDto 해석
|
||||
* (서버 DB와 알림 이력의 strategyId 불일치 시 전략명 fallback)
|
||||
* 매매 시그널 알림 — strategyId·전략명·종목별 live 설정으로 StrategyDto 해석
|
||||
*/
|
||||
import {
|
||||
isStrategyMissingOnServer,
|
||||
loadLiveStrategySettings,
|
||||
loadStrategies,
|
||||
loadStrategy,
|
||||
loadStrategyForNotification,
|
||||
type StrategyDto,
|
||||
} from './backendApi';
|
||||
import { reconcileStrategyMissingWithValidIds } from './strategyMissingCache';
|
||||
import { reconcileStrategyMissingWithValidIds, unmarkStrategyMissingOnServer } from './strategyMissingCache';
|
||||
import { coerceFiniteNumber } from './safeFormat';
|
||||
import { hydrateStrategyDto, normalizeMarketCode } from './strategyHydrate';
|
||||
import { extractVirtualConditions } from './virtualStrategyConditions';
|
||||
|
||||
let strategiesCache: StrategyDto[] | null = null;
|
||||
let strategiesCacheAt = 0;
|
||||
@@ -34,6 +35,28 @@ async function getStrategiesList(force = false): Promise<StrategyDto[]> {
|
||||
return strategiesCache;
|
||||
}
|
||||
|
||||
function findStrategyByName(list: StrategyDto[], name: string): StrategyDto | undefined {
|
||||
const trimmed = name.trim();
|
||||
if (!trimmed) return undefined;
|
||||
const exact = list.find(s => s.name?.trim() === trimmed);
|
||||
if (exact) return exact;
|
||||
const lower = trimmed.toLowerCase();
|
||||
return list.find(s => {
|
||||
const n = s.name?.trim().toLowerCase();
|
||||
return n === lower || n?.includes(lower) || lower.includes(n ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
function pickStrategy(dto: StrategyDto, strategyId: number): ResolvedNotificationStrategy {
|
||||
const hydrated = hydrateStrategyDto(dto);
|
||||
unmarkStrategyMissingOnServer(strategyId);
|
||||
return { strategy: hydrated, strategyId };
|
||||
}
|
||||
|
||||
function hasExtractableConditions(strategy: StrategyDto): boolean {
|
||||
return extractVirtualConditions(hydrateStrategyDto(strategy)).length > 0;
|
||||
}
|
||||
|
||||
export interface ResolvedNotificationStrategy {
|
||||
strategy: StrategyDto | undefined;
|
||||
/** live-conditions·차트에 사용할 유효 strategyId */
|
||||
@@ -44,16 +67,20 @@ export async function resolveNotificationStrategy(
|
||||
strategyId: unknown,
|
||||
strategyName?: string | null,
|
||||
prefetched?: StrategyDto[],
|
||||
market?: string | null,
|
||||
): Promise<ResolvedNotificationStrategy> {
|
||||
const normalizedId = normalizeStrategyId(strategyId);
|
||||
const list = prefetched ?? await getStrategiesList();
|
||||
|
||||
if (normalizedId != null && !isStrategyMissingOnServer(normalizedId)) {
|
||||
if (normalizedId != null) {
|
||||
const fromList = list.find(s => s.id === normalizedId);
|
||||
if (fromList) {
|
||||
return { strategy: fromList, strategyId: normalizedId };
|
||||
if (fromList?.id != null && hasExtractableConditions(fromList)) {
|
||||
return pickStrategy(fromList, normalizedId);
|
||||
}
|
||||
const loaded = await loadStrategyForNotification(normalizedId);
|
||||
if (loaded && extractVirtualConditions(loaded).length > 0) {
|
||||
return { strategy: loaded, strategyId: normalizedId };
|
||||
}
|
||||
const loaded = await loadStrategy(normalizedId);
|
||||
if (loaded) {
|
||||
return { strategy: loaded, strategyId: normalizedId };
|
||||
}
|
||||
@@ -61,9 +88,31 @@ export async function resolveNotificationStrategy(
|
||||
|
||||
const name = strategyName?.trim();
|
||||
if (name) {
|
||||
const byName = list.find(s => s.name?.trim() === name);
|
||||
const byName = findStrategyByName(list, name);
|
||||
if (byName?.id != null && byName.id > 0) {
|
||||
return { strategy: byName, strategyId: byName.id };
|
||||
if (hasExtractableConditions(byName)) {
|
||||
return pickStrategy(byName, byName.id);
|
||||
}
|
||||
const loaded = await loadStrategyForNotification(byName.id);
|
||||
if (loaded) {
|
||||
return { strategy: loaded, strategyId: byName.id };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedMarket = market ? normalizeMarketCode(market) : null;
|
||||
if (normalizedMarket) {
|
||||
try {
|
||||
const live = await loadLiveStrategySettings(normalizedMarket);
|
||||
const liveId = normalizeStrategyId(live.strategyId);
|
||||
if (liveId != null) {
|
||||
const loaded = await loadStrategyForNotification(liveId);
|
||||
if (loaded) {
|
||||
return { strategy: loaded, strategyId: liveId };
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user