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

SubscriptionVariables

Helper trait for subscription variables with an associated subscription type. Lets users call vars.subscribe(&ws) instead of ws.subscribe::<Q>(vars).

Definition

pub trait SubscriptionVariables: Variables {
    fn subscribe(
        self,
        client: &WsClient,
    ) -> impl std::future::Future<
        Output = Result<
            SubscriptionStream<<<Self as Variables>::Query as GraphQLQuery>::ResponseData>,
            anyhow::Error,
        >,
    > + Send
    where
        Self: Sized + Unpin + Send + Sync + 'static,
        <Self as Variables>::Query: Unpin + Send + Sync + 'static,
        <<Self as Variables>::Query as GraphQLQuery>::ResponseData:
            DeserializeOwned + Unpin + Send + Sync + 'static;
}

The provided method calls client.subscribe::<Self::Query>(self).

Example

use {
    anyhow::Result,
    dango_sdk::{SubscriptionVariables, WsClient, subscribe_block},
    futures::StreamExt,
};
 
#[tokio::main]
async fn main() -> Result<()> {
    let ws = WsClient::new("wss://api-mainnet.dango.zone/graphql")?;
 
    let mut stream = subscribe_block::Variables {}.subscribe(&ws).await?;
    while let Some(item) = stream.next().await {
        println!("{item:?}");
    }
    Ok(())
}

Implementations

SubscriptionVariables is implemented for the 13 codegen Variables types under indexer_graphql_types. Each variant maps to a GraphQLQuery marker struct (SubscribeBlock, SubscribeAccounts, …) via impl Variables for <module>::Variables.

Variant moduleQuery typeWhat it streams
subscribe_blockSubscribeBlockNewly finalized blocks.
subscribe_accountsSubscribeAccountsAccount lifecycle events.
subscribe_transfersSubscribeTransfersBank transfers.
subscribe_transactionsSubscribeTransactionsTransactions as they are included.
subscribe_messagesSubscribeMessagesPer-message records from new transactions.
subscribe_eventsSubscribeEventsIndexer events filtered by type/contract.
subscribe_event_by_addressesSubscribeEventByAddressesEvents filtered by a list of addresses.
subscribe_candlesSubscribeCandlesDEX candles for a pair.
subscribe_perps_candlesSubscribePerpsCandlesPerps candles for a pair.
subscribe_tradesSubscribeTradesDEX fills for a pair.
subscribe_perps_tradesSubscribePerpsTradesPerps fills for a pair.
subscribe_query_appSubscribeQueryAppA streaming query_app snapshot.
subscribe_query_storeSubscribeQueryStoreA streaming query_store snapshot.
subscribe_query_statusSubscribeQueryStatusNode status snapshots.

Each Variables struct derives Default, so partial construction is idiomatic — subscribe_events::Variables::default(). Most subscription schemas only expose pagination and sort_by arguments; filter on the streamed payload client-side.

Notes

  • The trait bound mirrors WsClient::subscribe: Send + Sync + 'static, plus Unpin for the variables and DeserializeOwned for the response data. Every codegen type satisfies these out of the box.
  • This is sugar only. The underlying call path is identical to client.subscribe::<Q>(vars). Use whichever reads better.
  • Calls WsClient::subscribe — each invocation opens a dedicated connection. To multiplex multiple subscriptions over a single socket, use Session::subscribe directly.

See also