feat: replace volatility breakout with DB-backed real-time trend check
- price_history table on Oracle ADB stores prices every 10 minutes - check_trend(): current price vs N hours ago (default 1h, +3% threshold) - check_momentum(): unchanged (MA20 + 2x volume still applies) - Ticker list cached 5 minutes to avoid 429 rate limits - Collector starts 30s after boot to avoid simultaneous API calls - Configurable: TREND_HOURS, TREND_MIN_GAIN_PCT in .env Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import time
|
||||
|
||||
import pyupbit
|
||||
import requests
|
||||
@@ -12,9 +13,17 @@ logger = logging.getLogger(__name__)
|
||||
TOP_N = 20 # 거래량 상위 N개 종목만 스캔
|
||||
_TICKER_URL = "https://api.upbit.com/v1/ticker"
|
||||
|
||||
# 티커 목록 캐시 (5분 TTL — API rate limit 방지)
|
||||
_ticker_cache: list[str] = []
|
||||
_ticker_cache_time: float = 0.0
|
||||
_TICKER_CACHE_TTL = 300 # 5분
|
||||
|
||||
|
||||
def get_top_tickers() -> list[str]:
|
||||
"""24시간 거래대금 상위 KRW 마켓 티커 반환."""
|
||||
"""24시간 거래대금 상위 KRW 마켓 티커 반환 (5분 캐시)."""
|
||||
global _ticker_cache, _ticker_cache_time
|
||||
if _ticker_cache and (time.time() - _ticker_cache_time) < _TICKER_CACHE_TTL:
|
||||
return _ticker_cache
|
||||
try:
|
||||
all_tickers = pyupbit.get_tickers(fiat="KRW")
|
||||
if not all_tickers:
|
||||
@@ -37,11 +46,13 @@ def get_top_tickers() -> list[str]:
|
||||
# 24h 거래대금 기준 정렬
|
||||
ticker_data.sort(key=lambda x: x.get("acc_trade_price_24h", 0), reverse=True)
|
||||
top = [t["market"] for t in ticker_data[:TOP_N]]
|
||||
_ticker_cache = top
|
||||
_ticker_cache_time = time.time()
|
||||
logger.debug(f"상위 {TOP_N}개: {top[:5]}...")
|
||||
return top
|
||||
except Exception as e:
|
||||
logger.error(f"get_top_tickers 실패: {e}")
|
||||
return []
|
||||
return _ticker_cache # 실패 시 이전 캐시 반환
|
||||
|
||||
|
||||
def get_ohlcv(ticker: str, count: int = 21):
|
||||
|
||||
Reference in New Issue
Block a user