23 lines
586 B
Python
23 lines
586 B
Python
|
|
"""
|
||
|
|
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()
|