WebsocketManager
Thread-based graphql-transport-ws subscription manager. Subclass of threading.Thread (daemon=True).
In practice this class is constructed lazily by Info on the first subscribe_* call. Direct construction is rare — document here because the class is part of the public surface.
Setup
from dango.websocket_manager import WebsocketManager
manager = WebsocketManager("https://api-mainnet.dango.zone")
manager.start()start() (inherited from threading.Thread) launches run() in a daemon thread.
Constructor
WebsocketManager(base_url: str) -> NoneConfiguration
base_url — str. HTTP base URL; converted internally to a wss:// (or ws://) URL ending in /graphql.
Methods
| Method | Description |
|---|---|
run | threading.Thread entry point (called by start()) |
stop | Signal shutdown and close the connection |
subscribe | Register a subscription |
unsubscribe | Drop a subscription |
End-to-end example
from dango.websocket_manager import WebsocketManager
manager = WebsocketManager("https://api-mainnet.dango.zone")
manager.start()
document = """
subscription {
perpsTrades(pairId: "perp/ethusd") { fillPrice fillSize }
}
"""
sid = manager.subscribe(document, {}, print)
# ... receive events ...
manager.unsubscribe(sid)
manager.stop()
manager.join(timeout=5.0)Notes
- The manager owns ONE WebSocket connection. The server caps each connection at 30 simultaneous subscriptions.
- The manager pings every 15 seconds at the protocol layer (
{"type": "ping"}) to defeat the server's 30-second idle timeout. - Subscriptions opened before the server's
connection_ackare queued and flushed once the ack arrives. - Subscription errors arrive through the callback as
{"_error": payload}, not as exceptions. After an error, the manager has already dropped the callback — the subscription is terminal. stop()signals shutdown and closes the socket but does not wait for the thread to exit. Calljoin(timeout=...)if you need to block.
See also
Info— the high-level wrapper that builds and owns one manager- Concepts: Subscriptions — sharding, callback contract, errors