Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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) -> None

Configuration

base_urlstr. HTTP base URL; converted internally to a wss:// (or ws://) URL ending in /graphql.

Methods

MethodDescription
runthreading.Thread entry point (called by start())
stopSignal shutdown and close the connection
subscribeRegister a subscription
unsubscribeDrop 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_ack are 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. Call join(timeout=...) if you need to block.

See also