Merge branch 'optymalization' of https://git.kapuscinski.pl/p1otek/hyper into optymalization

This commit is contained in:
DiTus
2026-08-05 20:34:26 +02:00

View File

@ -30,6 +30,8 @@ class LiveCandleFetcher:
self.info = Info(constants.MAINNET_API_URL, skip_ws=False)
self.candle_queue = Queue() # Thread-safe queue for candles
self._last_candle_info = None
self._last_status_log = time.time()
self._ensure_tables_exist()
def _ensure_tables_exist(self):
@ -83,6 +85,7 @@ class LiveCandleFetcher:
db.upsert_candles(conn, table_name, [record])
logging.debug(f"Upserted candle for {coin} at {record[0]}")
self._last_candle_info = (coin, record[0])
except Exception as e:
logging.error(f"Error in database writer thread: {e}")
@ -161,6 +164,14 @@ class LiveCandleFetcher:
while True:
try:
time.sleep(1)
if not self.info.ws_manager.is_alive():
raise ConnectionError("WebSocket connection is not alive")
if time.time() - self._last_status_log >= 300:
if self._last_candle_info:
logging.info(f"LiveCandleFetcher running correctly. Last 1m candle collected: {self._last_candle_info[0]} at {self._last_candle_info[1]}")
else:
logging.info("LiveCandleFetcher running correctly. No candles collected yet.")
self._last_status_log = time.time()
except Exception as e:
logging.error(f"WebSocket connection lost: {e}")
self.info.ws_manager.stop()