API Overview
Understanding the Deriv API ecosystem and its core capabilities.
Deriv API provides programmatic access to trading services, account management, and market data for the Options trading platform. The API enables developers to integrate Deriv's robust trading infrastructure into their applications using REST endpoints for account setup and WebSocket connections for real-time trading.
Key features
- Options account creation and management (REST)
- Real-time market data streaming (WebSocket)
- Contract trading (buy, sell, update) (WebSocket)
- Portfolio and account monitoring (WebSocket)
- Historical data access (WebSocket)
- Subscription-based real-time updates (WebSocket)
- Secured access via OAuth 2.0 or Personal Access Token (PAT)
API architecture
The Deriv API consists of two complementary components designed to work together seamlessly:
- Account creation and management
- OTP generation for WebSocket authentication
- System health monitoring
- Standard HTTP methods (GET, POST)
- Stateless requests
- Authentication via
Deriv-App-IDheader +Authorization: Bearertoken (OAuth 2.0 or PAT)
- Real-time trading operations (buy, sell, proposals)
- Live market data streaming (ticks, symbols)
- Account data subscriptions (balance, portfolio)
- Persistent bidirectional connection
- Real-time push notifications
- Three endpoint types: public (no auth), demo, and real (both authenticated via OTP)
When to use REST vs WebSocket
| Feature | REST API | WebSocket API |
|---|---|---|
| Use Case | Account setup and management | Real-time trading and market data |
| Connection Type | Stateless HTTP requests | Persistent connection |
| Authentication | Deriv-App-ID header + Bearer token (OAuth 2.0 or PAT) | OTP-based (obtained via REST API); public endpoint requires no auth |
| Real-time Updates | No (request-response only) | Yes (subscriptions) |
| Examples | POST /trading/v1/options/accounts, POST .../{accountId}/otp, GET /v1/health | Buy contract, stream ticks, get balance |
Typical workflow
- REST: Get an authenticated WebSocket URL via the OTP endpoint (requires your Bearer token)
- WebSocket: Connect using the authenticated URL returned in the OTP response
- WebSocket: Perform real-time trading operations
Note: Users receive a default demo account upon signup — you do not need to create one via the API before trading.
API endpoints
REST base URL:
1https://api.derivws.comWebSocket endpoints:
1# Public (no authentication required)
2wss://api.derivws.com/trading/v1/options/ws/public
3
4# Demo account (authenticated via OTP)
5wss://api.derivws.com/trading/v1/options/ws/demo?otp=YOUR_OTP
6
7# Real account (authenticated via OTP)
8wss://api.derivws.com/trading/v1/options/ws/real?otp=YOUR_OTPThe OTP is obtained by calling POST /trading/v1/options/accounts/{accountId}/otp — the response contains a ready-to-use WebSocket URL with the OTP already embedded.
Connection requirements:
- WebSocket-capable client (browser or server-side)
- Stable internet connection
- Valid
Deriv-App-IDand Bearer token for REST calls and OTP generation
Next steps
Continue with these guides to start building with the Deriv API:
Authentication
Compare OAuth 2.0 and PAT authentication methods and choose the right one for your use case.
OAuth 2.0
Step-by-step guide to the OAuth 2.0 Authorization Code flow with PKCE.
Complete Workflows
End-to-end examples combining REST and WebSocket APIs for common trading scenarios.
Options REST API
Full reference for all REST endpoints: accounts, OTP, WebSocket setup, and more.