테스트 강화 및 코드 품질 개선

This commit is contained in:
2025-12-17 00:01:46 +09:00
parent 37a150bd0d
commit 00c57ddd32
51 changed files with 10670 additions and 217 deletions

43
main.py
View File

@@ -26,15 +26,33 @@ except Exception:
def minutes_to_timeframe(minutes: int) -> str:
"""분 단위를 캔들봉 timeframe 문자열로 변환 (예: 60 -> '1h', 240 -> '4h')"""
"""분 단위를 Upbit 지원 캔들봉 timeframe 문자열로 변환
Upbit 지원: 1m, 3m, 5m, 10m, 15m, 30m, 60m, 240m
일봉/주봉 지원: 1d, 1w
"""
# Upbit 분봉 화이트리스트
valid_minutes = {1, 3, 5, 10, 15, 30, 60, 240}
if minutes in valid_minutes:
return f"{minutes}m"
# 일봉 처리
if minutes == 1440: # 24시간
return "1d"
# 예외 처리: 근사값 매핑
if minutes < 60:
return f"{minutes}m"
elif minutes % 1440 == 0:
return f"{minutes // 1440}d"
elif minutes % 60 == 0:
return f"{minutes // 60}h"
# 가장 가까운 분봉 찾기
closest = min(valid_minutes, key=lambda x: abs(x - minutes))
logger.warning(f"[CONFIG] 지원하지 않는 분봉 {minutes}m -> {closest}m 로 대체됨")
return f"{closest}m"
elif minutes < 240:
logger.warning(f"[CONFIG] 지원하지 않는 분봉 {minutes}m -> 60m 로 대체됨")
return "60m"
else:
return f"{minutes}m"
logger.warning(f"[CONFIG] 지원하지 않는 분봉 {minutes}m -> 240m (4시간) 로 대체됨")
return "240m"
def _check_buy_signals(cfg, symbols_to_check, config):
@@ -149,12 +167,21 @@ def process_symbols_and_holdings(
# Upbit 최신 보유 정보 동기화
if cfg.upbit_access_key and cfg.upbit_secret_key:
from src.holdings import fetch_holdings_from_upbit, save_holdings
from src.holdings import fetch_holdings_from_upbit, get_current_price, save_holdings, update_max_price
updated_holdings = fetch_holdings_from_upbit(cfg)
if updated_holdings is not None:
holdings = updated_holdings
save_holdings(holdings, HOLDINGS_FILE)
# ✅ CRITICAL-002: 보유 종목별 최고가 갱신
for symbol in holdings.keys():
try:
current_price = get_current_price(symbol)
if current_price and current_price > 0:
update_max_price(symbol, current_price, HOLDINGS_FILE)
except Exception as e:
logger.warning("[%s] 최고가 갱신 실패: %s", symbol, e)
else:
logger.error("Upbit에서 보유 정보를 가져오지 못했습니다. 이번 주기에서는 매도 분석을 건너뜁니다.")