Prerequisites
- A running Injective node with the Chain Stream gRPC server enabled
- The
[injective-websocket]section configured in your node’sapp.toml
Configuration
Configure the WebSocket server in your node’sapp.toml under the [injective-websocket] section.
| Option | Type | Default | Description |
|---|---|---|---|
address | string | "" (disabled) | Address and port to bind the WebSocket server (e.g., "0.0.0.0:9998"). Leave empty to disable. |
max-open-connections | int | 0 (unlimited) | Maximum simultaneous WebSocket connections. Set a reasonable limit in production. |
read-timeout | duration | 10s | Maximum time to wait for reading a complete client request. |
write-timeout | duration | 10s | Maximum time to wait for writing a response to the client. |
max-body-bytes | int64 | 1000000 (1MB) | Maximum HTTP request body size in bytes. |
max-header-bytes | int | 1048576 (1MB) | Maximum HTTP header size in bytes. |
max-request-batch-size | int | 10 | Maximum RPC calls allowed in a single batch request. |
Example configuration
app.toml
The WebSocket server requires the Chain Stream server to be enabled. Ensure the following is also configured in your
app.toml:Connecting to the server
Connect to the WebSocket endpoint at:example.js
Subscribing to events
Send a JSON-RPC 2.0 request with thesubscribe method. Each request must include:
jsonrpc— Always"2.0"id— A positive integer used to identify responses for this subscriptionmethod—"subscribe"params.req.subscription_id— A client-provided unique identifier for this subscriptionparams.req.filter— An object containing your subscription filters
- Oracle prices
- Spot orders
- Multiple event types
id.
Unsubscribing from events
Send a request with theunsubscribe method and the subscription_id you used when subscribing:
The
subscription_id must match exactly the ID you provided when creating the subscription.Available filters
You can subscribe to any combination of the following event types. At least one filter must be specified. Use"*" as a wildcard to match all values for a parameter.
| Filter | Description | Parameters |
|---|---|---|
bank_balances_filter | Bank balance changes | accounts |
subaccount_deposits_filter | Subaccount deposit changes | subaccount_ids |
spot_trades_filter | Spot market trades | market_ids, subaccount_ids |
derivative_trades_filter | Derivative market trades | market_ids, subaccount_ids |
spot_orders_filter | Spot order updates | market_ids, subaccount_ids |
derivative_orders_filter | Derivative order updates | market_ids, subaccount_ids |
spot_orderbooks_filter | Spot orderbook updates | market_ids |
derivative_orderbooks_filter | Derivative orderbook updates | market_ids |
positions_filter | Position updates | subaccount_ids, market_ids |
oracle_price_filter | Oracle price updates | symbol |
order_failures_filter | Order failure notifications | accounts |
conditional_order_trigger_failures_filter | Conditional order trigger failures | subaccount_ids, market_ids |
Response format
Stream responses follow the JSON-RPC 2.0 format. Each response contains updates for a single block. Only fields matching your subscription filters contain data.Security considerations
The WebSocket server has certain security limitations to be aware of when deploying to production.No origin validation
No origin validation
The server accepts connections from any origin. Deploy behind a reverse proxy that validates the
Origin header to mitigate Cross-Site WebSocket Hijacking.No TLS/SSL support
No TLS/SSL support
The server only supports unencrypted
ws:// connections. Use a TLS-terminating reverse proxy to provide wss:// connections.No authentication
No authentication
The server does not implement authentication. Use a reverse proxy with authentication middleware, API key validation, or network-level access controls (firewalls, VPNs).
No per-client rate limiting
No per-client rate limiting
While
max-open-connections limits total connections, there is no per-client rate limiting. Implement rate limiting at the proxy level:Operational notes
- When a connection closes, all associated subscriptions are automatically cancelled
- The server sends ping frames periodically to detect stale connections
- The
subscription_idmust be unique within your connection — different connections can reuse the same IDs - Implement reconnection logic with exponential backoff on the client side
- Use specific filters rather than wildcards (
*) when possible to reduce data volume - Always set
max-open-connectionsto a reasonable limit in production
