xRocket WebSocket API
xRocket WebSocket API enables streaming real-time data for trading and account management.
How to connect?β
Use the following URL to connect your project to xRocket WebSocket API:
wss://exchange.app-api.xrocket.exchange/wss://exchange.app-api.testnet.xrocket.exchange/To keep the connection alive and prevent the server from closing idle connections after 60 seconds, send a ping message every 30 seconds.
Example ping message:
{
"id": "12345",
"method": "ping"
}
Authenticationβ
- Create an xRocket account
Start @xRocket (for Mainnet) or @xrocket_testnet_bot (for Testnet) in Telegram to automatically create your xRocket wallet/account linked to your Telegram account.
- Get your Bearer Token (API Key)
In @xRocket (for Mainnet) or @xrocket_testnet_bot (for Testnet) go to Menu > Settings > Exchange settings > API token.
- Send the token via the
authmethod right after connecting
Authentication request example:
{
"id": "1",
"method": "auth",
"params": {
"token": "<YOUR_API_TOKEN>"
}
}
Your Bearer Token (API Key) provides full access to your account, including trading, transfers, and withdrawals. Handle it with the same level of security as your account password β never share it publicly!
Successful response:
{
"id": "1",
"result": {
"success": true
}
}
Error response:
{
"id": "1",
"error": {
"code": -32034,
"message": "User Blocked",
"data": {
"detail": "Invalid authentication"
}
}
}
Message Formatβ
All messages use JSON format with the following structure:
{
"id": "12345",
"method": "method_name",
"params": {
// method-specific parameters, for example, channel name to subscribe, ticker or auth token
}
}
Request ID guidelines:
- Each request must include a unique
idfield, that is a string or number value. idis used to match requests with their corresponding responses.
Example subscription request:
{
"id": "request_id",
"method": "subscribe",
"params": {
"channel": "ticker",
"symbol": "BTC-USDT",
"interval": "1day"
}
}
Channel push notifications use the subscription format:
{
"method": "subscription",
"params": {
"channel": "ticker",
"symbol": "BTC-USDT",
"interval": "1day",
"data": {
// channel-specific data
}
}
}
Channelsβ
| Channel | Description |
|---|---|
| Public channels | Provide public market data like tickers, order books, and more. No authentication required. |
| Ticker | Ticker updates for specific symbols. |
| All tickers | Ticker updates for all symbols. |
| Order book | Order book updates. |
| Trades | Trade updates for specific symbols. |
| Candles | Candlestick data. |
| Private channels | Provide account-specific data and require authentication. |
| Balances | Account balance updates. |
| Active orders | Updates for active orders. |
Methodsβ
pingβ Health check and connection testingauthβ Authenticate connection for private channelssubscribeβ Subscribe to a channelunsubscribeβ Unsubscribe from a channelunsubscribeAllβ Unsubscribe from all active channels
Unsubscribeβ
Unsubscribe from a specific channel request example:
{
"id": "12345",
"method": "unsubscribe",
"params": {
"channel": "channel_name"
}
}
Unsubscribe Allβ
Unsubscribe from all active channel subscriptions request example:
{
"id": "12345",
"method": "unsubscribeAll"
}
Error Handlingβ
xRocket WebSocket API error codes comply with JSON-RPC specification.
Our Error Codesβ
| Error code | Description |
|---|---|
| -32700 | Parse error β Invalid JSON was received by the server. |
| -32600 | Invalid request β The JSON sent is not a valid Request object. |
| -32601 | Method not found β The method does not exist or is not available. |
| -32602 | Invalid params β Invalid method parameter(s). |
| -32603 | Internal error β Internal JSON-RPC error. |
| -32000 | Incorrect decimal places β The requested number of decimal places is not supported. |
| -32001 | Order not found β The specified order not found. |
| -32002 | Already subscribed β The connection is already subscribed to this channel. |
| -32003 | Not subscribed β Attempted to unsubscribe from a channel without an active subscription. |
| -32005 | Symbol not found β The requested trading symbol not found. |
| -32006 | Symbol incorrect β The provided symbol is invalid. |
| -32007 | Symbol not available β The symbol is not currently available for trading. |
| -32008 | Interval too big β The requested time interval is too big. |
| -32009 | Symbol not opened β Trading for this symbol has not started or is suspended. |
| -32010 | Asset not available β The requested asset is not available. |
| -32011 | Incorrect precision β The requested price or quantity precision is not supported. |
| -32030 | Invalid token β The provided authentication token is invalid, expired, or revoked. |
| -32032 | Validation error β An error occurred while validating the incoming data. |
| -32033 | Unauthorized β Insufficient permissions to perform the operation. |
| -32034 | User Blocked β The user account has been blocked. |
| -32050 | Rate limit exceeded β Too many requests. Please try again later. |
Error Response Formatβ
{
"id": "1205411",
"error": {
"code": -32034,
"message": "User Blocked",
"data": {
// error-specific fields and data
"detail": "Invalid authentication"
}
}
}