first vibe coding
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""
|
||||
data/collector.py - KIS WebSocket 실시간 시세 수신
|
||||
"""
|
||||
import asyncio, logging
|
||||
from app.execution.kis_client import KISWebSocket
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DataCollector:
|
||||
def __init__(self, kis_client, on_price, on_vi):
|
||||
self.ws = KISWebSocket(kis_client)
|
||||
self.on_price = on_price
|
||||
self.on_vi = on_vi
|
||||
|
||||
async def start(self, tickers: list):
|
||||
self.ws.on_price("*", self.on_price)
|
||||
self.ws.on_vi(self.on_vi)
|
||||
await self.ws.subscribe(tickers)
|
||||
|
||||
async def stop(self):
|
||||
await self.ws.close()
|
||||
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
data/universe.py - 종목 풀 갱신 (08:30)
|
||||
"""
|
||||
import json, os, logging
|
||||
from app.config import MAX_UNIVERSE
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
CACHE_PATH = "data/universe_cache.json"
|
||||
|
||||
|
||||
async def update_universe(kis_client, ai_context: dict) -> list:
|
||||
"""거래량 순위 기반 유니버스 갱신 + AI 필터"""
|
||||
try:
|
||||
rank = await kis_client.get_volume_rank(top_n=MAX_UNIVERSE * 2)
|
||||
tickers = [r["ticker"] for r in rank]
|
||||
|
||||
blacklist = ai_context.get("blacklist_tickers", [])
|
||||
tickers = [t for t in tickers if t not in blacklist]
|
||||
|
||||
boosted = ai_context.get("boosted_tickers", [])
|
||||
tickers = (
|
||||
[t for t in boosted if t in tickers] +
|
||||
[t for t in tickers if t not in boosted]
|
||||
)[:MAX_UNIVERSE]
|
||||
|
||||
os.makedirs(os.path.dirname(CACHE_PATH), exist_ok=True)
|
||||
with open(CACHE_PATH, "w") as f:
|
||||
json.dump({"tickers": tickers, "boosted": boosted}, f)
|
||||
|
||||
logger.info(f"유니버스 갱신: {len(tickers)}종목 (부스트: {len(boosted)})")
|
||||
return tickers
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"유니버스 갱신 실패: {e}")
|
||||
if os.path.exists(CACHE_PATH):
|
||||
with open(CACHE_PATH) as f:
|
||||
return json.load(f).get("tickers", [])
|
||||
return []
|
||||
Reference in New Issue
Block a user