> For the complete documentation index, see [llms.txt](https://docs.tokenbot.com/home/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tokenbot.com/home/api-docs/graphql-api/subscriptions.md).

# Subscriptions

TokenBot exposes real-time subscriptions over [graphql-ws](https://github.com/enisdenjo/graphql-ws). The bot engines publish events to Redis, and the GraphQL server fans them out to WebSocket subscribers.

## Available Subscriptions

| Subscription      | Source                                                                                | Arguments                             |
| ----------------- | ------------------------------------------------------------------------------------- | ------------------------------------- |
| `tradeSignal`     | Trading engine (Redis channel `tokenbot.trading.signals`)                             | `strategyId` (optional filter)        |
| `orderbookUpdate` | Market-maker engine (Redis channel `tokenbot.mm.orderbook`)                           | `exchangeId!`, `symbol!`              |
| `ping`            | Timer only (not Redis) — an **unauthenticated** smoke-test of the WebSocket transport | `intervalMs` (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.

## Connecting

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](/home/api-docs/authentication.md) for details. The `tokenbot` CLI does this for you.

```graphql
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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tokenbot.com/home/api-docs/graphql-api/subscriptions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
