fix: get_time_series 카테고리별 endpoint 분기 (indicators 404 스팸 제거) #75

Merged
xhh merged 1 commit from fix/streamlit-indicators-routing into main 2026-05-26 02:06:58 +09:00
Owner

문제

운영 API 로그에 /api/indicators/{symbol} 404 가 매 페이지 로드마다 누적되고 있었음. 예:

GET /api/indicators/SPY?... HTTP/1.1 404 Not Found
GET /api/prices/SPY?... HTTP/1.1 200 OK
GET /api/indicators/IWM?... HTTP/1.1 404 Not Found
GET /api/prices/IWM?... HTTP/1.1 200 OK

원인

/api/indicators/{symbol} 라우터는 EconomicIndicator 테이블만 조회하는 FRED 전용 엔드포인트. 호출자 frontend/streamlit/utils/data_loader.get_time_series 는 심볼 카테고리를 모르니까 "indicators 먼저 try → 404 면 prices fallback" 패턴이라, prices 심볼마다 404 가 한 줄씩 찍힘. 동작은 정상이지만 로그 스팸 + 매 호출 round-trip 1회 낭비.

변경

  • _fred_symbol_set() 헬퍼 추가: /api/meta/symbols 응답에서 category=="fred" 인 심볼 set 추출, @st.cache_data(ttl=600).
  • get_time_series 가 symbol 이 FRED set 에 있으면 /api/indicators/ 만, 아니면 /api/prices/ 만 호출 (미정의 심볼도 prices 폴백 그대로).

검증 (NAS 로컬, 리빌드된 컨테이너 내부 in-process 호출)

심볼 호출 endpoint 응답 rows
M2SL (FRED) /api/indicators/M2SL 200 27
SPY (ETF) /api/prices/SPY 200 7
^VIX (index) /api/prices/%5EVIX 200 7

호출 시점 60초간 API 로그에 indicators 404 0건.

영향 범위

응답 데이터 동일, FRED 심볼 분기시 prices 폴백 경로가 사라지므로 캐시된 FRED set 이 누락되면 fred 심볼 조회가 빈 DF 반환 (이 상황은 /api/meta/symbols 자체가 실패해야 하고 그 경우 어차피 다른 동작도 어려움).

## 문제 운영 API 로그에 `/api/indicators/{symbol}` 404 가 매 페이지 로드마다 누적되고 있었음. 예: ``` GET /api/indicators/SPY?... HTTP/1.1 404 Not Found GET /api/prices/SPY?... HTTP/1.1 200 OK GET /api/indicators/IWM?... HTTP/1.1 404 Not Found GET /api/prices/IWM?... HTTP/1.1 200 OK ``` ## 원인 `/api/indicators/{symbol}` 라우터는 `EconomicIndicator` 테이블만 조회하는 **FRED 전용** 엔드포인트. 호출자 `frontend/streamlit/utils/data_loader.get_time_series` 는 심볼 카테고리를 모르니까 "indicators 먼저 try → 404 면 prices fallback" 패턴이라, prices 심볼마다 404 가 한 줄씩 찍힘. 동작은 정상이지만 로그 스팸 + 매 호출 round-trip 1회 낭비. ## 변경 - `_fred_symbol_set()` 헬퍼 추가: `/api/meta/symbols` 응답에서 `category=="fred"` 인 심볼 set 추출, `@st.cache_data(ttl=600)`. - `get_time_series` 가 symbol 이 FRED set 에 있으면 `/api/indicators/` 만, 아니면 `/api/prices/` 만 호출 (미정의 심볼도 prices 폴백 그대로). ## 검증 (NAS 로컬, 리빌드된 컨테이너 내부 in-process 호출) | 심볼 | 호출 endpoint | 응답 | rows | |---|---|---|---| | M2SL (FRED) | `/api/indicators/M2SL` | 200 | 27 | | SPY (ETF) | `/api/prices/SPY` | 200 | 7 | | ^VIX (index) | `/api/prices/%5EVIX` | 200 | 7 | 호출 시점 60초간 API 로그에 indicators 404 **0건**. ## 영향 범위 응답 데이터 동일, FRED 심볼 분기시 prices 폴백 경로가 사라지므로 캐시된 FRED set 이 누락되면 fred 심볼 조회가 빈 DF 반환 (이 상황은 `/api/meta/symbols` 자체가 실패해야 하고 그 경우 어차피 다른 동작도 어려움).
fix: get_time_series 가 카테고리별로 indicators/prices 분기
All checks were successful
Tests (PR) / pytest (pull_request) Successful in 32s
8ccfcc6acb
기존엔 모든 심볼에 대해 /api/indicators/{symbol} 먼저 시도하고 404 시
/api/prices/{symbol} 로 폴백하는 패턴이라, prices 심볼(SPY, IWM, ^VIX,
^W5000 등) 호출마다 API 측에 404 액세스 로그가 한 줄씩 찍혔다.

`/api/meta/symbols` 응답에서 category=="fred" 인 심볼 set 을 10분 캐시
(`st.cache_data`) 후, 그 set 에 속하는 심볼만 indicators 로, 나머지는
prices 로 직접 호출한다. 의도되지 않은 404 가 사라지고 round-trip 도
절감.

검증:
- 컨테이너 리빌드 후 in-process 호출:
  - M2SL → /api/indicators/M2SL 200 (27 rows)
  - SPY  → /api/prices/SPY 200 (7 rows), indicators 호출 없음
  - ^VIX → /api/prices/%5EVIX 200 (7 rows), indicators 호출 없음
- 60초 API 로그에 indicators 404 발생 0건.
xhh merged commit ac0c8c9a0e into main 2026-05-26 02:06:58 +09:00
xhh deleted branch fix/streamlit-indicators-routing 2026-05-26 02:06:58 +09:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
xhh/financial-data-platform!75
No description provided.