Deriv Options Trading WebSocket API
API Overview
The Deriv Options Trading WebSocket API provides real-time access to financial markets for trading binary options, multipliers, and accumulators. The API uses WebSocket protocol for bidirectional communication, enabling real-time market data streaming and trading operations.
Key Features
- Real-time market data streaming
- Contract trading (buy, sell, update)
- Portfolio and account management
- Historical data access
- Subscription-based updates
- Multi-currency support
WebSocket Connection
Endpoint:
1wss://ws.binaryws.com/websockets/v3Connection Requirements:
- WebSocket-capable client (browser or server-side)
- Stable internet connection
- Valid authentication credentials for protected endpoints
Authentication Flow
The API uses a two-step authentication process:
1. Obtain Session Token
- Exchange one-time token (from brand) for session token
- One-time token has short lifetime and single-use only
- Use
get_session_tokenendpoint
2. Authorise Connection
- Use session token with
authorizeendpoint - Session token is long-lived and reusable
- Required for all authenticated operations
authentication-example.json
json
1// Step 1: Exchange one-time token for session token
2{
3 "get_session_token": "lbHmLdIPUAjw8Ry4wzjH8HHNkEc",
4 "req_id": 1
5}
6
7// Response
8{
9 "get_session_token": {
10 "expires": "2025-08-29T13:33:00.787760323Z",
11 "token": "zGpIpSGpjSxAZehF_usH2sPv9TN"
12 },
13 "msg_type": "get_session_token",
14 "req_id": 1
15}
16
17// Step 2: Authorise using session token
18{
19 "authorize": "zGpIpSGpjSxAZehF_usH2sPv9TN",
20 "req_id": 2
21}Request Format
All requests must be sent as JSON-formatted strings over the WebSocket connection.
1{
2 "endpoint_name": value,
3 "param1": value1,
4 "param2": value2,
5 "req_id": optional_request_id
6}Error Handling
Errors are returned in the following format:
1{
2 "error": {
3 "code": "ErrorCode",
4 "message": "Human-readable error message"
5 },
6 "msg_type": "endpoint_name",
7 "echo_req": { ...echoed request... },
8 "req_id": request_id_if_provided
9}Error Handling Best Practices
- Check for
errorfield in every response - Implement retry logic for network-related errors
- Log errors with request context for debugging
- Handle connection drops gracefully with reconnection logic
API Endpoints
Account Endpoints
7
Authentication and account management
Data Endpoints
4
Market data and symbols
Trading Endpoints
7
Buy, sell, and manage contracts
Subscription Management
2
Manage WebSocket subscriptions