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

subscribe

Register a subscription. Returns an int id usable with unsubscribe.

Signature

def subscribe(
    self,
    document: str,
    variables: dict[str, Any],
    callback: Callable[[dict[str, Any]], None],
) -> int

Example

from dango.websocket_manager import WebsocketManager
 
manager = WebsocketManager("https://api-mainnet.dango.zone")
manager.start()
 
document = """
subscription Trades($pairId: String!) {
  perpsTrades(pairId: $pairId) {
    fillPrice
    fillSize
  }
}
"""
 
sid = manager.subscribe(document, {"pairId": "perp/ethusd"}, print)

Parameters

documentstr. A GraphQL subscription document (subscription { ... }).

variablesdict[str, Any]. Variables for the subscription.

callbackCallable[[dict[str, Any]], None]. Invoked with each next message's payload. The full payload ({"data": ..., "extensions": ...}) is passed; the Info wrappers unwrap to the inner node before invoking your callback. Errors arrive as {"_error": payload}.

Returns

int — a subscription id. Subscriptions opened before the server's connection_ack are queued and flushed once the ack arrives.

Notes

  • For typed unwrapping and per-channel ergonomics, prefer the Info.subscribe_* methods.
  • Callbacks fire on the WebSocket reader thread. Keep them fast.

See also

  • unsubscribe — drop a subscription
  • Info — high-level wrappers around this transport