Skip to content

GraphQL Subscriptions

TokenBot exposes real-time subscriptions over graphql-ws. The bot engines publish events to Redis, and the GraphQL server fans them out to WebSocket subscribers.

SubscriptionSourceArguments
tradeSignalTrading engine (Redis channel tokenbot.trading.signals)strategyId (optional filter)
orderbookUpdateMarket-maker engine (Redis channel tokenbot.mm.orderbook)exchangeId!, symbol!
pingTimer only (not Redis) — an unauthenticated smoke-test of the WebSocket transportintervalMs (default 5000, 50–60000)

Both tradeSignal and orderbookUpdate are backed by Redis pub/sub: the bot engines publish to the channels above and the GraphQL server fans out to WebSocket subscribers. ping is a transport health check only.

Connect to the /graphql WebSocket endpoint:

wss://gql-api.tokenbot.com/graphql

The handshake is authenticated with the CLI signed-request scheme: the four x-tb-* values are sent in the graphql-ws connectionParams, signed over the canonical string CONNECT\n/graphql\n<timestamp>\n<nonce>\n<sha256("")>. A rejected handshake closes with code 4403. See Authentication for details. The tokenbot CLI does this for you.

subscription {
tradeSignal(strategyId: "str_123") {
id
symbol
action
price
timestamp
}
}

Note: GraphQL previously ran on AWS AppSync, which exposed a different set of on* subscriptions (e.g. onTradeCreated). AppSync has been retired (PR #148); the subscriptions above are the current ones.