> For the complete documentation index, see [llms.txt](https://docs.afx.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.afx.xyz/api-reference/websocket/market-data.md).

# Market Data

## Order Book

> Subscribe to order book depth updates. Sends initial snapshot then incremental deltas.\
> \
> \`\`\`json\
> { "method": "subscribe", "subscription": { "type": "orderBook", "symbol": "BTCUSDC", "depth": 50 } }\
> \`\`\`\
> \
> \| Param | Type | Required | Description |\
> \|-------|------|----------|-------------|\
> \| symbol | string | Yes | Symbol name |\
> \| depth | integer | No | Depth level (default 5) |<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX WebSocket API","version":"1.0.0"},"servers":[{"url":"wss://ws.afx.xyz/ws/dex","description":"Mainnet"},{"url":"wss://ws-testnet.afx.xyz/ws/dex","description":"Testnet"}],"paths":{"/ws/subscribe/orderBook":{"post":{"operationId":"wsOrderBook","summary":"Order Book","tags":["Market Data"],"description":"Subscribe to order book depth updates. Sends initial snapshot then incremental deltas.\n\n```json\n{ \"method\": \"subscribe\", \"subscription\": { \"type\": \"orderBook\", \"symbol\": \"BTCUSDC\", \"depth\": 50 } }\n```\n\n| Param | Type | Required | Description |\n|-------|------|----------|-------------|\n| symbol | string | Yes | Symbol name |\n| depth | integer | No | Depth level (default 5) |\n","responses":{"200":{"description":"Push data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OrderBookPush"}}}}}}}},"components":{"schemas":{"OrderBookPush":{"type":"object","properties":{"channel":{"type":"string"},"data":{"type":"object","properties":{"type":{"type":"string","description":"`snapshot` or `incremental`"},"symbolCode":{"type":"integer","description":"Symbol code"},"symbol":{"type":"string","description":"Symbol name"},"block":{"type":"integer","description":"Block height"},"sequence":{"type":"integer","description":"Sequence number"},"depth":{"type":"integer","description":"Requested depth"},"timestamp":{"type":"integer","description":"Timestamp (ms)"},"book":{"type":"object","properties":{"bids":{"type":"array","description":"Bid levels `[price, qty]`","items":{"type":"array","items":{"type":"string"}}},"asks":{"type":"array","description":"Ask levels `[price, qty]`","items":{"type":"array","items":{"type":"string"}}}}}}}}}}}}
````

## Kline / Candle

> Subscribe to candlestick (OHLCV) data.\
> \
> \`\`\`json\
> { "method": "subscribe", "subscription": { "type": "candle", "symbol": "BTCUSDC", "interval": "60" } }\
> \`\`\`\
> \
> \| Param | Type | Required | Description |\
> \|-------|------|----------|-------------|\
> \| symbol | string | Yes | Symbol name |\
> \| interval | string | Yes | Interval in seconds ("60", "300", "900", "3600", "86400") |<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX WebSocket API","version":"1.0.0"},"servers":[{"url":"wss://ws.afx.xyz/ws/dex","description":"Mainnet"},{"url":"wss://ws-testnet.afx.xyz/ws/dex","description":"Testnet"}],"paths":{"/ws/subscribe/candle":{"post":{"operationId":"wsCandle","summary":"Kline / Candle","tags":["Market Data"],"description":"Subscribe to candlestick (OHLCV) data.\n\n```json\n{ \"method\": \"subscribe\", \"subscription\": { \"type\": \"candle\", \"symbol\": \"BTCUSDC\", \"interval\": \"60\" } }\n```\n\n| Param | Type | Required | Description |\n|-------|------|----------|-------------|\n| symbol | string | Yes | Symbol name |\n| interval | string | Yes | Interval in seconds (\"60\", \"300\", \"900\", \"3600\", \"86400\") |\n","responses":{"200":{"description":"Push data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CandlePush"}}}}}}}},"components":{"schemas":{"CandlePush":{"type":"object","properties":{"channel":{"type":"string"},"data":{"type":"object","properties":{"symbolName":{"type":"string","description":"Symbol name"},"timestamp":{"type":"integer","description":"Candle start time (seconds)"},"intrvl":{"type":"integer","description":"Interval (seconds)"},"open":{"type":"string","description":"Open price"},"high":{"type":"string","description":"High price"},"low":{"type":"string","description":"Low price"},"close":{"type":"string","description":"Close price"},"volume":{"type":"string","description":"Trading volume"},"turnover":{"type":"string","description":"Trading turnover (value)"},"tradeCount":{"type":"integer","description":"Number of trades"}}}}}}}}
````

## Recent Trades

> Subscribe to recent trade updates.\
> \
> \`\`\`json\
> { "method": "subscribe", "subscription": { "type": "trades", "symbol": "BTCUSDC" } }\
> \`\`\`\
> \
> \| Param | Type | Required |\
> \|-------|------|----------|\
> \| symbol | string | Yes |<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX WebSocket API","version":"1.0.0"},"servers":[{"url":"wss://ws.afx.xyz/ws/dex","description":"Mainnet"},{"url":"wss://ws-testnet.afx.xyz/ws/dex","description":"Testnet"}],"paths":{"/ws/subscribe/trades":{"post":{"operationId":"wsTrades","summary":"Recent Trades","tags":["Market Data"],"description":"Subscribe to recent trade updates.\n\n```json\n{ \"method\": \"subscribe\", \"subscription\": { \"type\": \"trades\", \"symbol\": \"BTCUSDC\" } }\n```\n\n| Param | Type | Required |\n|-------|------|----------|\n| symbol | string | Yes |\n","responses":{"200":{"description":"Push data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TradesPush"}}}}}}}},"components":{"schemas":{"TradesPush":{"type":"object","properties":{"channel":{"type":"string"},"data":{"type":"object","properties":{"type":{"type":"string","description":"`snapshot` or `incremental`"},"sequence":{"type":"integer","description":"Sequence number"},"symbol":{"type":"string","description":"Symbol name"},"trades":{"type":"array","items":{"type":"object","properties":{"symbol":{"type":"string"},"ordSide":{"type":"string","description":"BUY or SELL"},"filledPx":{"type":"string","description":"Trade price"},"filledQty":{"type":"string","description":"Trade quantity"},"transactionTime":{"type":"integer","description":"Timestamp (ms)"},"txHash":{"type":"string","description":"On-chain tx hash"}}}}}}}}}}}
````

## Ticker

> Subscribe to single symbol ticker.\
> \
> \`\`\`json\
> { "method": "subscribe", "subscription": { "type": "ticker", "symbol": "BTCUSDC" } }\
> \`\`\`\
> \
> \| Param | Type | Required |\
> \|-------|------|----------|\
> \| symbol | string | Yes |<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX WebSocket API","version":"1.0.0"},"servers":[{"url":"wss://ws.afx.xyz/ws/dex","description":"Mainnet"},{"url":"wss://ws-testnet.afx.xyz/ws/dex","description":"Testnet"}],"paths":{"/ws/subscribe/ticker":{"post":{"operationId":"wsTicker","summary":"Ticker","tags":["Market Data"],"description":"Subscribe to single symbol ticker.\n\n```json\n{ \"method\": \"subscribe\", \"subscription\": { \"type\": \"ticker\", \"symbol\": \"BTCUSDC\" } }\n```\n\n| Param | Type | Required |\n|-------|------|----------|\n| symbol | string | Yes |\n","responses":{"200":{"description":"Push data","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TickerPush"}}}}}}}},"components":{"schemas":{"TickerPush":{"type":"object","properties":{"channel":{"type":"string"},"data":{"type":"object","properties":{"type":{"type":"string","description":"`snapshot` or `incremental`"},"sequence":{"type":"integer","description":"Sequence number"},"timestamp":{"type":"integer","description":"Timestamp (ms)"},"symbol":{"type":"string","description":"Symbol name"},"ticker":{"type":"object","properties":{"s":{"type":"string","description":"Symbol"},"p":{"type":"string","description":"Last price"},"op":{"type":"string","description":"Oracle price"},"mp":{"type":"string","description":"Mark price"},"mid":{"type":"string","description":"Mid price"},"oi":{"type":"string","description":"Open interest"},"fr":{"type":"string","description":"Funding rate"},"lfr":{"type":"string","description":"Last funding rate"},"o":{"type":"string","description":"24h open"},"h":{"type":"string","description":"24h high"},"l":{"type":"string","description":"24h low"},"v":{"type":"string","description":"24h volume"},"tv":{"type":"string","description":"24h turnover"},"P":{"type":"string","description":"24h change %"}}}}}}}}}}
````

## All Tickers

> Subscribe to all tickers. Same ticker structure as single ticker, but returns an array.\
> \
> \`\`\`json\
> { "method": "subscribe", "subscription": { "type": "allTickers" } }\
> \`\`\`\
> \
> No parameters required.<br>

````json
{"openapi":"3.0.3","info":{"title":"AFX DEX WebSocket API","version":"1.0.0"},"servers":[{"url":"wss://ws.afx.xyz/ws/dex","description":"Mainnet"},{"url":"wss://ws-testnet.afx.xyz/ws/dex","description":"Testnet"}],"paths":{"/ws/subscribe/allTickers":{"post":{"operationId":"wsAllTickers","summary":"All Tickers","tags":["Market Data"],"description":"Subscribe to all tickers. Same ticker structure as single ticker, but returns an array.\n\n```json\n{ \"method\": \"subscribe\", \"subscription\": { \"type\": \"allTickers\" } }\n```\n\nNo parameters required.\n","responses":{"200":{"description":"Push data — same as ticker but with `tickers` array","content":{"application/json":{}}}}}}}}
````


---

# 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:

```
GET https://docs.afx.xyz/api-reference/websocket/market-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
