Open TRON-FAN opened 3 months ago
Sometimes, unfortunately, the ping mechanism does not detect when a WebSocket connection has stopped retrieving up-to-date prices. Therefore, you should implement a function that continuously checks if new data is flowing. If no new data is received, the WebSocket connection should be manually closed, and you should wait until the thread is fully terminated. Otherwise, the system may create numerous threads. Additionally, you should implement a reconnect mechanism and consider an emergency fetch, either through the API or other methods.
I have adjusted the file accordingly.
It might also be useful to incorporate a time check in the ping mechanism to verify if fresh data is coming in. If not, a new connection should be established.
import websocket import threading import time import json from ._http_manager import generate_signature import logging import copy from uuid import uuid4 from . import _helpers
from websocket._exceptions import WebSocketConnectionClosedException # Importiere die Ausnahme
logger = logging.getLogger(name)
SUBDOMAIN_TESTNET = "stream-testnet" SUBDOMAIN_MAINNET = "stream" DEMO_SUBDOMAIN_TESTNET = "stream-demo-testnet" DEMO_SUBDOMAIN_MAINNET = "stream-demo" DOMAIN_MAIN = "bybit" DOMAIN_ALT = "bytick"
class _WebSocketManager: def init( self, callback_function, ws_name, testnet, domain="", demo=False, rsa_authentication=False, api_key=None, api_secret=None, ping_interval=20, ping_timeout=10, retries=10, restart_on_error=True, trace_logging=False, private_auth_expire=1, ): self.testnet = testnet self.domain = domain self.rsa_authentication = rsa_authentication self.demo = demo
Set API keys.
class _V5WebSocketManager(_WebSocketManager): def init(self, ws_name, kwargs): callback_function = ( kwargs.pop("callback_function") if kwargs.get("callback_function") else self._handle_incoming_message ) super().init(callback_function, ws_name, kwargs)