### WebSocket Trading Flow Example Source: https://context7_llms A complete example demonstrating a typical trading flow using the WebSocket API, from getting a session token to buying a contract. ```APIDOC ### Example: Complete Trading Flow This example illustrates a sequence of WebSocket messages to perform a trade: 1. **Get Session Token**: Obtain a temporary token for session authentication. 2. **Authorize**: Authenticate the session using the obtained token. 3. **Get Proposal**: Request a contract proposal with specific trading parameters. 4. **Buy Contract**: Execute a trade by buying the contract using the proposal ID and price. ```javascript const ws = new WebSocket('wss://ws.derivws.com/websockets/v3'); ws.onopen = () => { // Step 1: Get session token ws.send(JSON.stringify({ get_session_token: "YOUR_ONE_TIME_TOKEN", req_id: 1 })); }; ws.onmessage = (event) => { const data = JSON.parse(event.data); if (data.msg_type === 'get_session_token') { // Step 2: Authorize ws.send(JSON.stringify({ authorize: data.get_session_token.token, req_id: 2 })); } if (data.msg_type === 'authorize') { // Step 3: Get proposal ws.send(JSON.stringify({ proposal: 1, amount: 10, basis: "stake", contract_type: "CALL", currency: "USD", duration: 5, duration_unit: "t", underlying_symbol: "1HZ100V", req_id: 3 })); } if (data.msg_type === 'proposal') { // Step 4: Buy contract ws.send(JSON.stringify({ buy: data.proposal.id, price: data.proposal.ask_price, req_id: 4 })); } if (data.msg_type === 'buy') { console.log('Contract purchased:', data.buy.contract_id); } }; ws.onerror = (error) => { console.error('WebSocket Error:', error); }; ws.onclose = () => { console.log('WebSocket Connection Closed'); }; ``` ``` -------------------------------- ### Complete Trading Flow using WebSocket Source: https://context7_llms Demonstrates a complete trading flow using WebSockets, including obtaining a session token, authorizing, getting a contract proposal, and buying a contract. This example uses JavaScript. ```javascript const ws = new WebSocket('wss://ws.derivws.com/websockets/v3'); ws.onopen = () => { // Step 1: Get session token ws.send(JSON.stringify({ get_session_token: "YOUR_ONE_TIME_TOKEN", req_id: 1 })); }; ws.onmessage = (event) => { const data = JSON.parse(event.data); if (data.msg_type === 'get_session_token') { // Step 2: Authorize ws.send(JSON.stringify({ authorize: data.get_session_token.token, req_id: 2 })); } if (data.msg_type === 'authorize') { // Step 3: Get proposal ws.send(JSON.stringify({ proposal: 1, amount: 10, basis: "stake", contract_type: "CALL", currency: "USD", duration: 5, duration_unit: "t", underlying_symbol: "1HZ100V", req_id: 3 })); } if (data.msg_type === 'proposal') { // Step 4: Buy contract ws.send(JSON.stringify({ buy: data.proposal.id, price: data.proposal.ask_price, req_id: 4 })); } if (data.msg_type === 'buy') { console.log('Contract purchased:', data.buy.contract_id); } }; ``` -------------------------------- ### Get List of Registered Applications Source: https://context7_llms Retrieves a list of all applications registered with the Deriv API. The response includes application ID, name, redirect URI, and associated scopes. ```json { "apps": [ { "id": "app_123", "name": "My Trading App", "redirect_uri": "https://myapp.com/callback", "scopes": ["trade", "read"] } ] } ``` -------------------------------- ### API Error Response Example Source: https://context7_llms Illustrates the structure of an error response from the Deriv API. Includes an error code, message, message type, and request ID. ```json { "error": { "code": "AuthorizationRequired", "message": "Please log in." }, "msg_type": "authorize", "req_id": 1 } ``` -------------------------------- ### Get Price Proposal (JSON) Source: https://context7_llms Obtains a price proposal for a contract before purchasing. Requires details like amount, basis, contract type, currency, duration, and underlying symbol. Authentication is not required but recommended for personalized pricing. ```json { "proposal": 1, "amount": 100, "basis": "stake", "contract_type": "CALL", "currency": "USD", "duration": 5, "duration_unit": "t", "underlying_symbol": "1HZ100V", "subscribe": 1, "req_id": 1 } ``` -------------------------------- ### Deriv API v2: Get Portfolio (Open Positions) Source: https://context7_llms Fetches a list of all open positions for the authorized trading account. Requires 'portfolio' parameter set to 1. ```json { "portfolio": 1, "req_id": 4 } ``` -------------------------------- ### Deriv API v2: Get Statement Source: https://context7_llms Retrieves the account statement, providing a history of transactions. Supports filtering with 'limit' and includes 'description' for details. Requires authentication. ```json { "statement": 1, "description": 1, "limit": 100, "req_id": 6 } ``` -------------------------------- ### Get Historical Tick Data (JSON) Source: https://context7_llms Fetches historical tick data for a given symbol. Requires the symbol, end time, and start time. Optional parameters include the number of ticks, style (ticks or candles), and granularity. No authentication is required. ```json { "ticks_history": "1HZ100V", "end": "latest", "start": 1, "count": 100, "style": "ticks", "req_id": 4 } ``` -------------------------------- ### Get Contract Update History Source: https://context7_llms Retrieves the history of updates made to a specific contract. Requires contract ID and a request ID. ```json { "contract_update_history": 1, "contract_id": 12345678, "req_id": 6 } ``` -------------------------------- ### Get Available Contract Types (JSON) Source: https://context7_llms Retrieves a list of available contract types for a given underlying symbol. Requires the symbol, and optionally accepts currency, landing company, and product type for filtering. No authentication is needed. ```json { "contracts_for": "1HZ100V", "currency": "USD", "landing_company": "svg", "product_type": "basic", "req_id": 2 } ``` -------------------------------- ### Deriv API v2: Get Profit Table Source: https://context7_llms Retrieves a summary of profit and loss for completed trades. Supports filtering with 'limit' and 'offset', and includes 'description' for details. Requires authentication. ```json { "profit_table": 1, "description": 1, "limit": 25, "offset": 0, "req_id": 5 } ``` -------------------------------- ### Deriv API v2: Get Active Symbols Source: https://context7_llms Fetches a list of all currently active symbols available for trading. Can retrieve 'brief' or 'full' data and filter by 'product_type'. Authentication is not required. ```json { "active_symbols": "brief", "product_type": "basic", "req_id": 1 } ``` -------------------------------- ### Get Open Contract Status (JSON) Source: https://context7_llms Retrieves the current status of an open contract. Supports subscription for real-time updates. Requires the contract ID. Authentication is required for one's own contracts. ```json { "proposal_open_contract": 1, "contract_id": 12345678, "subscribe": 1, "req_id": 4 } ``` -------------------------------- ### Deriv API v2: Get Session Token Source: https://context7_llms Exchanges a short-lived one-time token for a long-lived session token. This is the first step in the two-step authentication process. Requires a 'get_session_token' parameter. ```json { "get_session_token": "ot_abc123xyz456", "req_id": 1 } ``` -------------------------------- ### Deriv API v2: Get Account Balance Source: https://context7_llms Retrieves the current balance for the authorized account. Supports subscription for real-time balance updates. Requires 'balance' parameter set to 1 and optionally 'subscribe'. ```json { "balance": 1, "subscribe": 1, "req_id": 3 } ``` -------------------------------- ### Create Personal Access Token Source: https://context7_llms Creates a new personal access token (PAT) for API authentication. Requires a name for the token, scopes, and an optional expiration date. ```json { "name": "My API Token", "scopes": ["trade", "read"], "expires_at": "2025-12-31T23:59:59Z" } ``` -------------------------------- ### Application Management API Source: https://context7_llms APIs for managing applications registered with Deriv, including listing, creating, retrieving, updating, and deleting applications. ```APIDOC ## GET /apps ### Description Get a list of registered applications. ### Method GET ### Endpoint /apps ### Parameters #### Query Parameters - **app_id** (string) - Optional - Filter applications by App ID. ### Response #### Success Response (200) - **apps** (array) - An array of application objects. Each object contains: - **id** (string) - The unique identifier for the application. - **name** (string) - The name of the application. - **redirect_uri** (string) - The redirect URI for the application. - **scopes** (array of strings) - The granted scopes for the application. ### Response Example ```json { "apps": [ { "id": "app_123", "name": "My Trading App", "redirect_uri": "https://myapp.com/callback", "scopes": ["trade", "read"] } ] } ``` ## POST /apps ### Description Register a new application. ### Method POST ### Endpoint /apps ### Parameters #### Request Body - **name** (string) - Required - The name of the application. - **redirect_uri** (string) - Required - The redirect URI for the application. - **scopes** (array of strings) - Required - The scopes to grant to the application. ### Request Example ```json { "name": "My Trading App", "redirect_uri": "https://myapp.com/callback", "scopes": ["trade", "read"] } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the newly created application. - **message** (string) - A success message. #### Response Example ```json { "id": "app_456", "message": "Application registered successfully." } ``` ## GET /apps/{id} ### Description Get application details by ID. ### Method GET ### Endpoint /apps/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the application to retrieve. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the application. - **name** (string) - The name of the application. - **redirect_uri** (string) - The redirect URI for the application. - **scopes** (array of strings) - The granted scopes for the application. #### Response Example ```json { "id": "app_123", "name": "My Trading App", "redirect_uri": "https://myapp.com/callback", "scopes": ["trade", "read"] } ``` ## PATCH /apps/{id} ### Description Update application settings. ### Method PATCH ### Endpoint /apps/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the application to update. #### Request Body - **name** (string) - Optional - The new name for the application. - **redirect_uri** (string) - Optional - The new redirect URI for the application. - **scopes** (array of strings) - Optional - The new scopes for the application. ### Response #### Success Response (200) - **message** (string) - A success message indicating the application was updated. #### Response Example ```json { "message": "Application updated successfully." } ``` ## DELETE /apps/{id} ### Description Delete an application. ### Method DELETE ### Endpoint /apps/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the application to delete. ### Response #### Success Response (200) - **message** (string) - A success message indicating the application was deleted. #### Response Example ```json { "message": "Application deleted successfully." } ``` ``` -------------------------------- ### Register New Application Source: https://context7_llms Registers a new application with the Deriv API. Requires the application name, redirect URI, and desired scopes. ```json { "name": "My Trading App", "redirect_uri": "https://myapp.com/callback", "scopes": ["trade", "read"] } ``` -------------------------------- ### buy Source: https://context7_llms Purchases a contract using a proposal ID obtained from the 'proposal' call. This is the actual execution of a trade. ```APIDOC ## buy ### Description Purchase a contract using a proposal ID obtained from the proposal call. ### Method POST ### Endpoint /buy ### Parameters #### Request Body - **buy** (string, required): Proposal ID from proposal response - **price** (number, required): Maximum price willing to pay - **parameters** (object, optional): Override proposal parameters ### Request Example ```json { "buy": "abc123xyz", "price": 10.50, "req_id": 2 } ``` ### Response #### Success Response (200) - **buy** (object) - Contains details of the purchase, including balance_after, buy_price, contract_id, longcode, payout, purchase_time, start_time, and transaction_id. - **msg_type** (string) - The message type, which will be "buy". - **req_id** (integer) - The request ID. #### Response Example ```json { "buy": { "balance_after": 10082.09, "buy_price": 10.50, "contract_id": 12345678, "longcode": "Win payout if Volatility 100 Index is strictly higher...", "payout": 19.90, "purchase_time": 1234567890, "start_time": 1234567890, "transaction_id": 87654321 }, "msg_type": "buy", "req_id": 2 } ``` ``` -------------------------------- ### Personal Access Token (PAT) Management API Source: https://context7_llms APIs for managing Personal Access Tokens (PATs), including listing, creating, verifying, and revoking tokens. ```APIDOC ## GET /pat ### Description Get a list of personal access tokens. ### Method GET ### Endpoint /pat ### Response #### Success Response (200) - **tokens** (array) - An array of PAT objects. Each object contains: - **id** (string) - The unique identifier for the token. - **name** (string) - The name of the token. - **scopes** (array of strings) - The scopes granted to the token. - **created_at** (string) - The timestamp when the token was created. - **expires_at** (string) - The timestamp when the token expires. #### Response Example ```json { "tokens": [ { "id": "pat_abc", "name": "My API Token", "scopes": ["trade", "read"], "created_at": "2023-01-01T10:00:00Z", "expires_at": "2025-12-31T23:59:59Z" } ] } ``` ## POST /pat ### Description Create a new personal access token. ### Method POST ### Endpoint /pat ### Parameters #### Request Body - **name** (string) - Required - The name for the new token. - **scopes** (array of strings) - Required - The scopes to grant to the token. - **expires_at** (string) - Optional - The expiration date and time for the token in ISO 8601 format. ### Request Example ```json { "name": "My API Token", "scopes": ["trade", "read"], "expires_at": "2025-12-31T23:59:59Z" } ``` ### Response #### Success Response (200) - **token** (string) - The newly created personal access token. - **id** (string) - The unique identifier for the token. - **message** (string) - A success message. #### Response Example ```json { "token": "generated_pat_string", "id": "pat_def", "message": "Personal Access Token created successfully." } ``` ## DELETE /pat/{id} ### Description Revoke a personal access token. ### Method DELETE ### Endpoint /pat/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the token to revoke. ### Response #### Success Response (200) - **message** (string) - A success message indicating the token was revoked. #### Response Example ```json { "message": "Personal Access Token revoked successfully." } ``` ## POST /pat/verify ### Description Verify if a token is valid. ### Method POST ### Endpoint /pat/verify ### Parameters #### Request Body - **token** (string) - Required - The token to verify. ### Request Example ```json { "token": "your_personal_access_token" } ``` ### Response #### Success Response (200) - **is_valid** (boolean) - True if the token is valid, false otherwise. - **message** (string) - A message indicating the status of the token. #### Response Example ```json { "is_valid": true, "message": "Token is valid." } ``` ``` -------------------------------- ### proposal Source: https://context7_llms Obtains a price proposal for a specific contract before purchase. This call provides pricing details and conditions for a potential trade. ```APIDOC ## proposal ### Description Get a price proposal for a specific contract. Returns pricing information before buying. ### Method POST ### Endpoint /proposal ### Parameters #### Request Body - **proposal** (integer, required): Must be 1 - **amount** (number, required): Stake or payout amount - **basis** (string, required): "stake" or "payout" - **contract_type** (string, required): Contract type (CALL, PUT, DIGITEVEN, etc.) - **currency** (string, required): Account currency - **duration** (integer, required): Contract duration - **duration_unit** (string, required): "s" (seconds), "m" (minutes), "h" (hours), "d" (days), "t" (ticks) - **underlying_symbol** (string, required): Trading symbol - **barrier** (string, optional): Contract barrier - **barrier2** (string, optional): Second barrier for range contracts - **subscribe** (integer, optional): 1 to subscribe to price updates ### Request Example ```json { "proposal": 1, "amount": 100, "basis": "stake", "contract_type": "CALL", "currency": "USD", "duration": 5, "duration_unit": "t", "underlying_symbol": "1HZ100V", "subscribe": 1, "req_id": 1 } ``` ### Response #### Success Response (200) - **proposal** (object) - Contains proposal details including id, ask_price, display_value, payout, spot, and spot_time. - **msg_type** (string) - The message type, which will be "proposal". - **req_id** (integer) - The request ID. #### Response Example ```json { "proposal": { "id": "abc123xyz", "ask_price": 10.50, "display_value": "10.50", "payout": 19.90, "spot": 5123.44, "spot_time": 1234567890 }, "msg_type": "proposal", "req_id": 1 } ``` ``` -------------------------------- ### Sell Open Contract (JSON) Source: https://context7_llms Sells an open contract before its expiry. Requires the contract ID and the minimum acceptable selling price. Authentication is required. ```json { "sell": 12345678, "price": 15.00, "req_id": 3 } ``` -------------------------------- ### proposal_open_contract Source: https://context7_llms Retrieves the current status of an open contract. Supports subscription for real-time updates on contract status. ```APIDOC ## proposal_open_contract ### Description Get the current status of an open contract. Supports subscription for real-time updates. ### Method POST ### Endpoint /proposal_open_contract ### Parameters #### Request Body - **proposal_open_contract** (integer, required): Must be 1 - **contract_id** (integer, required): The ID of the contract to query - **subscribe** (integer, optional): 1 to subscribe to updates ### Request Example ```json { "proposal_open_contract": 1, "contract_id": 12345678, "subscribe": 1, "req_id": 4 } ``` ### Response #### Success Response (200) *Response structure not explicitly defined in the provided text, but would typically include details about the contract's current state.* #### Response Example ```json { "proposal_open_contract": { "contract_id": 12345678, "status": "open", "barrier_low": "100.00", "barrier_high": "101.00", "bid_price": 10.00, "ask_price": 10.05, "last_tick_display_value": "100.50", "profit_loss": 0.00 }, "echo_req": { "contract_id": 12345678, "proposal_open_contract": 1, "subscribe": 1, "req_id": 4 }, "req_id": 4 } ``` ``` -------------------------------- ### sell Source: https://context7_llms Sells an open contract before its expiry. This allows for closing a position early. ```APIDOC ## sell ### Description Sell an open contract before expiry. ### Method POST ### Endpoint /sell ### Parameters #### Request Body - **sell** (integer, required): Contract ID to sell - **price** (number, required): Minimum acceptable price ### Request Example ```json { "sell": 12345678, "price": 15.00, "req_id": 3 } ``` ### Response #### Success Response (200) - **sell** (object) - Contains details of the sale, including balance_after, contract_id, reference_id, sold_for, and transaction_id. - **msg_type** (string) - The message type, which will be "sell". - **req_id** (integer) - The request ID. #### Response Example ```json { "sell": { "balance_after": 10097.09, "contract_id": 12345678, "reference_id": 87654322, "sold_for": 15.00, "transaction_id": 87654323 }, "msg_type": "sell", "req_id": 3 } ``` ``` -------------------------------- ### Subscription Management API Source: https://context7_llms APIs for managing user subscriptions, including unsubscribing from individual subscriptions or all subscriptions of a certain type. ```APIDOC ## POST /forget ### Description Unsubscribe from a specific subscription using its ID. ### Method POST ### Endpoint /forget ### Parameters #### Request Body - **forget** (string) - Required - Subscription ID to cancel. - **req_id** (integer) - Required - Unique request identifier. ### Request Example ```json { "forget": "abc123subscription", "req_id": 1 } ``` ### Response #### Success Response (200) - **msg_type** (string) - Indicates the message type, e.g., 'forget'. - **forget** (boolean) - True if the subscription was successfully forgotten. - **req_id** (integer) - Unique request identifier. #### Response Example ```json { "msg_type": "forget", "forget": true, "req_id": 1 } ``` ## POST /forget_all ### Description Unsubscribe from all subscriptions of a specific type. ### Method POST ### Endpoint /forget_all ### Parameters #### Request Body - **forget_all** (array of strings or string) - Required - Type(s) of subscriptions to cancel. - **req_id** (integer) - Required - Unique request identifier. ### Request Example ```json { "forget_all": ["ticks", "proposal"], "req_id": 2 } ``` ### Response #### Success Response (200) - **msg_type** (string) - Indicates the message type, e.g., 'forget_all'. - **forget_all** (boolean) - True if all specified subscriptions were successfully forgotten. - **req_id** (integer) - Unique request identifier. #### Response Example ```json { "msg_type": "forget_all", "forget_all": true, "req_id": 2 } ``` ``` -------------------------------- ### Purchase Contract (JSON) Source: https://context7_llms Buys a contract using a proposal ID obtained from the proposal call. Requires the proposal ID and the maximum price. Optional parameters can override proposal settings. Authentication is required. ```json { "buy": "abc123xyz", "price": 10.50, "req_id": 2 } ``` -------------------------------- ### ticks Source: https://context7_llms Subscribes to real-time tick data for a specified symbol. This allows for monitoring live price movements. ```APIDOC ## ticks ### Description Subscribe to a real-time tick stream for a specific symbol. ### Method POST ### Endpoint /ticks ### Parameters #### Request Body - **ticks** (string, required): Symbol to subscribe to - **subscribe** (integer, optional): 1 to subscribe ### Request Example ```json { "ticks": "1HZ100V", "subscribe": 1, "req_id": 3 } ``` ### Response (stream) #### Success Response (200) - **tick** (object) - Contains tick data including ask, bid, epoch, id, pip_size, quote, and symbol. - **msg_type** (string) - The message type, which will be "tick". #### Response Example ```json { "tick": { "ask": 5123.45, "bid": 5123.43, "epoch": 1234567890, "id": "abc123", "pip_size": 2, "quote": 5123.44, "symbol": "1HZ100V" }, "msg_type": "tick" } ``` ``` -------------------------------- ### Authentication Endpoints Source: https://context7_llms Endpoints for authenticating WebSocket connections and managing session tokens. ```APIDOC ## POST /websockets/v3 (WebSocket) ### Description Handles authentication and session token management for Deriv API v2. ### Method POST (WebSocket) ### Endpoint `wss://ws.derivws.com/websockets/v3` ### Parameters #### Request Body - **get_session_token** (object, required) - Object for obtaining a session token. - **get_session_token** (string, required): The one-time token from the brand. - **passthrough** (object, optional): Data to pass through to response. - **req_id** (integer, optional): Request identifier for mapping responses. - **authorize** (object, required) - Object for authorizing the WebSocket connection. - **authorize** (string, required): The session token from get_session_token. - **passthrough** (object, optional): Data to pass through to response. - **req_id** (integer, optional): Request identifier for mapping responses. ### Request Example ```json { "get_session_token": "ot_abc123xyz456", "req_id": 1 } ``` ### Response #### Success Response (200) - **get_session_token** (object) - Contains session token details. - **expires** (string) - Expiration time of the session token. - **token** (string) - The generated session token. - **authorize** (object) - Contains authorization details. - **balance** (number) - Account balance. - **currency** (string) - Account currency. - **is_virtual** (integer) - Indicates if the account is virtual (1) or real (0). - **loginid** (string) - The user's login ID. - **scopes** (array of strings) - Permissions associated with the token. - **msg_type** (string) - Type of message received. - **req_id** (integer) - Request identifier. #### Response Example ```json { "get_session_token": { "expires": "2025-08-29T13:33:00.787760323Z", "token": "zGpIpSGpjSxAZehF_usH2sPv9TN" }, "msg_type": "get_session_token", "req_id": 1 } ``` ```json { "authorize": { "balance": 10092.59, "currency": "USD", "is_virtual": 1, "loginid": "VRTC965733", "scopes": ["trade"] }, "msg_type": "authorize", "req_id": 2 } ``` ``` -------------------------------- ### Account Endpoints Source: https://context7_llms Endpoints for retrieving account information such as balance, portfolio, profit table, and transaction history. ```APIDOC ## POST /websockets/v3 (WebSocket) - Account Endpoints ### Description Provides access to account-related data including balance, portfolio, profit table, statements, and real-time transaction notifications. ### Method POST (WebSocket) ### Endpoint `wss://ws.derivws.com/websockets/v3` ### Parameters #### Request Body - **balance** (object, required) - Request for account balance information. - **balance** (integer, required): Must be 1. - **subscribe** (integer, optional): 1 to subscribe to balance updates. - **req_id** (integer, optional): Request identifier. - **portfolio** (object, required) - Request for account portfolio (open positions). - **portfolio** (integer, required): Must be 1. - **req_id** (integer, optional): Request identifier. - **profit_table** (object, required) - Request for profit and loss summary of completed trades. - **profit_table** (integer, required): Must be 1. - **description** (integer, optional): Include descriptions in the response. - **limit** (integer, optional): Maximum number of records to return. - **offset** (integer, optional): Number of records to skip. - **req_id** (integer, optional): Request identifier. - **statement** (object, required) - Request for account statement (transaction history). - **statement** (integer, required): Must be 1. - **description** (integer, optional): Include descriptions in the response. - **limit** (integer, optional): Maximum number of records to return. - **req_id** (integer, optional): Request identifier. - **transaction** (object, required) - Request for real-time transaction notifications. - **transaction** (integer, required): Must be 1. - **subscribe** (integer, optional): 1 to subscribe to transaction updates. - **req_id** (integer, optional): Request identifier. ### Request Example ```json { "balance": 1, "subscribe": 1, "req_id": 3 } ``` ### Response #### Success Response (200) - **balance** (object) - Contains account balance details. - **balance** (number) - Current account balance. - **currency** (string) - Account currency. - **id** (string) - Unique identifier for the balance entry. - **loginid** (string) - The user's login ID. - **portfolio** (object) - Contains details of open contracts. - **contracts** (array of objects) - List of open contracts. - **contract_id** (integer) - Unique identifier for the contract. - **contract_type** (string) - Type of contract (e.g., "CALL"). - **currency** (string) - Contract currency. - **buy_price** (number) - The price at which the contract was bought. - **payout** (number) - The potential payout of the contract. - **profit_table** (object) - Contains profit and loss summary (details omitted for brevity). - **statement** (object) - Contains account statement details (details omitted for brevity). - **transaction** (object) - Contains transaction notification details (details omitted for brevity). - **msg_type** (string) - Type of message received. - **req_id** (integer) - Request identifier. #### Response Example ```json { "balance": { "balance": 10092.59, "currency": "USD", "id": "5b1f28c2-003d-0044-cc08-8b4d0a7df538", "loginid": "VRTC965733" }, "msg_type": "balance", "req_id": 3 } ``` ```json { "portfolio": { "contracts": [ { "contract_id": 12345678, "contract_type": "CALL", "currency": "USD", "buy_price": 10.00, "payout": 19.50 } ] }, "msg_type": "portfolio", "req_id": 4 } ``` **Authentication:** Required ``` -------------------------------- ### Update Contract Settings (JSON) Source: https://context7_llms Updates settings for an open contract, such as stop loss or take profit levels. Requires the contract ID and the desired limit order settings. Authentication is required. ```json { "contract_update": 1, "contract_id": 12345678, "limit_order": { "stop_loss": 5.00, "take_profit": 15.00 }, "req_id": 5 } ``` -------------------------------- ### contracts_for Source: https://context7_llms Retrieves available contract types for a given underlying symbol. This is useful for understanding which contracts can be traded for a specific asset. ```APIDOC ## contracts_for ### Description Get available contract types for a specific underlying symbol. ### Method POST ### Endpoint /contracts_for ### Parameters #### Request Body - **contracts_for** (string, required): The underlying symbol - **currency** (string, optional): Currency for pricing - **landing_company** (string, optional): Landing company - **product_type** (string, optional): Product type filter ### Request Example ```json { "contracts_for": "1HZ100V", "currency": "USD", "landing_company": "svg", "product_type": "basic", "req_id": 2 } ``` ### Response #### Success Response (200) *Response structure not explicitly defined in the provided text, but would typically include a list of available contract types.* #### Response Example ```json { "contracts_for": [ "CALL", "PUT", "EXPIRYRANGE" ], "echo_req": { "contracts_for": "1HZ100V", "currency": "USD", "landing_company": "svg", "product_type": "basic", "req_id": 2 }, "req_id": 2 } ``` ``` -------------------------------- ### Data Endpoints Source: https://context7_llms Endpoints for retrieving market data, including active symbols and price streams. ```APIDOC ## POST /websockets/v3 (WebSocket) - Data Endpoints ### Description Provides access to market data, including lists of active trading symbols and their details. ### Method POST (WebSocket) ### Endpoint `wss://ws.derivws.com/websockets/v3` ### Parameters #### Request Body - **active_symbols** (object, required) - Request for a list of active trading symbols. - **active_symbols** (string, required): "brief" for minimal data, "full" for complete data. - **product_type** (string, optional): Filter by product type (e.g., "basic"). - **req_id** (integer, optional): Request identifier. ### Request Example ```json { "active_symbols": "brief", "product_type": "basic", "req_id": 1 } ``` ### Response #### Success Response (200) - **active_symbols** (array of objects) - List of active symbols. - **display_name** (string) - Human-readable name of the symbol. - **market** (string) - The market category the symbol belongs to. - **market_display_name** (string) - Human-readable name of the market. - **symbol** (string) - The trading symbol (e.g., "1HZ100V"). - **symbol_type** (string) - The type of the symbol (e.g., "stockindex"). - **pip** (number) - The value of one pip for the symbol. - **is_trading_suspended** (integer) - Indicates if trading is suspended (1) or not (0). - **msg_type** (string) - Type of message received (e.g., "active_symbols"). #### Response Example ```json { "active_symbols": [ { "display_name": "Volatility 100 Index", "market": "synthetic_index", "market_display_name": "Synthetic Indices", "symbol": "1HZ100V", "symbol_type": "stockindex", "pip": 0.01, "is_trading_suspended": 0 } ], "msg_type": "active_symbols" } ``` **Authentication:** Not required ``` -------------------------------- ### contract_update Source: https://context7_llms Updates settings for an open contract, such as stop loss or take profit levels. This allows for dynamic risk management. ```APIDOC ## contract_update ### Description Update settings for an open contract (e.g., stop loss, take profit). ### Method POST ### Endpoint /contract_update ### Parameters #### Request Body - **contract_update** (integer, required): Must be 1 - **contract_id** (integer, required): The ID of the contract to update - **limit_order** (object, optional): Object containing stop loss and/or take profit levels - **stop_loss** (number, optional): The stop loss level - **take_profit** (number, optional): The take profit level ### Request Example ```json { "contract_update": 1, "contract_id": 12345678, "limit_order": { "stop_loss": 5.00, "take_profit": 15.00 }, "req_id": 5 } ``` ### Response #### Success Response (200) *Response structure not explicitly defined in the provided text, but would typically indicate success or failure of the update.* #### Response Example ```json { "contract_update": { "contract_id": 12345678, "limit_order": { "stop_loss": 5.00, "take_profit": 15.00 } }, "echo_req": { "contract_id": 12345678, "contract_update": 1, "limit_order": { "stop_loss": 5.00, "take_profit": 15.00 }, "req_id": 5 }, "req_id": 5 } ``` ``` -------------------------------- ### Subscribe to Real-Time Ticks (JSON) Source: https://context7_llms Subscribes to a real-time stream of tick data for a specified symbol. Requires the symbol and a subscription flag. The response is a stream of tick data objects. No authentication is needed. ```json { "ticks": "1HZ100V", "subscribe": 1, "req_id": 3 } ``` -------------------------------- ### Unsubscribe from All Subscriptions of a Type Source: https://context7_llms Unsubscribes from all subscriptions of a specified type. Supports canceling multiple types at once. Authentication is not required. ```json { "forget_all": ["ticks", "proposal"], "req_id": 2 } ``` -------------------------------- ### ticks_history Source: https://context7_llms Retrieves historical tick data for a given symbol. Allows fetching past price points within a specified time range. ```APIDOC ## ticks_history ### Description Get historical tick data for a symbol. ### Method POST ### Endpoint /ticks_history ### Parameters #### Request Body - **ticks_history** (string, required): Symbol - **end** (string/integer, required): End time epoch or "latest" - **start** (integer, required): Start time epoch (1 for oldest) - **count** (integer, optional): Number of ticks to return - **style** (string, optional): "ticks" or "candles" - **granularity** (integer, optional): Candle granularity in seconds (60, 120, 180, etc.) ### Request Example ```json { "ticks_history": "1HZ100V", "end": "latest", "start": 1, "count": 100, "style": "ticks", "req_id": 4 } ``` ### Response #### Success Response (200) *Response structure not explicitly defined in the provided text, but would typically include a list of historical ticks.* #### Response Example ```json { "history": { "candles": [], "delimiter": ".", "pip_size": 2, "prices": [ 100.10, 100.11, 100.12 ], "symbol": "1HZ100V", "times": [ 1678886400, 1678886460, 1678886520 ] }, "echo_req": { "count": 100, "end": "latest", "start": 1, "style": "ticks", "ticks_history": "1HZ100V", "req_id": 4 }, "req_id": 4 } ``` ``` -------------------------------- ### Contract Update History API Source: https://context7_llms Retrieves the history of updates made to a specific contract. ```APIDOC ## POST /contract_update_history ### Description Get the history of updates made to a contract. ### Method POST ### Endpoint /contract_update_history ### Parameters #### Request Body - **contract_update_history** (integer) - Required - Identifier for fetching update history. - **contract_id** (integer) - Required - The ID of the contract. - **req_id** (integer) - Required - Unique request identifier. ### Request Example ```json { "contract_update_history": 1, "contract_id": 12345678, "req_id": 6 } ``` ### Response #### Success Response (200) - **msg_type** (string) - Indicates the message type, e.g., 'contract_update_history'. - **contract_update_history** (object) - Contains the history of contract updates. - **req_id** (integer) - Unique request identifier. #### Response Example ```json { "msg_type": "contract_update_history", "contract_update_history": { "history": [ { "update_timestamp": 1678886400, "field": "amount", "old_value": "10.00", "new_value": "20.00" } ] }, "req_id": 6 } ``` ``` -------------------------------- ### Deriv API v2: Subscribe to Transactions Source: https://context7_llms Subscribes to real-time notifications for account transactions. Requires 'transaction' and 'subscribe' parameters set to 1. Authentication is required. ```json { "transaction": 1, "subscribe": 1, "req_id": 7 } ```