Deriv buy
Buys a contract: either the one a proposal priced, by the id that proposal returned, or one described in full in parameters. price is the most you accept to pay.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
This is a message of the Deriv WebSocket API, not an HTTP endpoint. It has no method and no path: it is sent as JSON over an open WebSocket connection.
This places a trade on the account the connection belongs to. A connection opened on the demo address trades the demo account.
The message
- Name
- buy
- Direction
- Request, sent by the client
- Carried by
- WebSocket. Deriv's page marks this call as needing a login with the trade scope, so it is sent on the connection of one account. The demo and real addresses are not opened as printed: POST /trading/v1/options/accounts/{accountId}/otp returns the address for one account with a one time password already in it.
- Demo account
- wss://api.derivws.com/trading/v1/options/ws/demo
- Real account
- wss://api.derivws.com/trading/v1/options/ws/real
Fields
| Name | Type | Description |
|---|---|---|
| buyrequired | string | The id from a proposal answer, or the string 1 where the contract is described in parameters instead. |
| parameters | object | The contract to buy, where buy is 1. It holds the same fields as a proposal request: contract_type, currency and underlying_symbol are required, and amount, basis, duration, duration_unit, date_expiry, barrier, barrier2, multiplier, growth_rate, limit_order, cancellation, payout_per_point, selected_tick and app_markup_percentage are optional. |
| pricerequired | number | The highest price at which the contract may be bought. |
| subscribe | integer | 1 starts a stream for the contract bought. The only value allowed is 1. |
| passthrough | object | Anything you want carried through the call. It comes back unchanged inside echo_req. |
| req_id | integer | A number of your own that is returned on the answer, so answers can be matched to requests. |
What arrives
buy: The receipt for the purchase.
| Name | Type | Description |
|---|---|---|
| buy.balance_afterrequired | number | The account balance once the purchase is done. |
| buy.buy_pricerequired | number | The price actually paid. |
| buy.contract_idrequired | integer | The id of the contract. sell, cancel, contract_update and proposal_open_contract take it. |
| buy.longcoderequired | string | The contract described in a sentence. |
| buy.payoutrequired | number | What the contract pays out. |
| buy.purchase_timerequired | integer | When the purchase was made, as Unix time in seconds. |
| buy.shortcoderequired | string | The contract described in a compact code. |
| buy.start_timerequired | integer | When the contract is expected to start, as Unix time in seconds. |
| buy.transaction_idrequired | integer | The id of the purchase transaction. |
| subscription.idrequired | string | The id of the stream on this connection. Sent with forget to stop it. The subscription object is present only where the request asked for a stream. |
| echo_reqrequired | object | A copy of the request that was sent. |
| msg_typerequired | string | Names the kind of answer. Here it is buy. |
| req_id | integer | The number the request carried. Present only where the request had one. |
Sample
Written by this site from the fields recorded on this page. It has not been run against a terminal, a server or an account, and the values in it are placeholders. No credential is typed into it: where a field holds one, the placeholder says where it comes from. Nothing is entered on this site.
{
"buy": "<the id from a proposal answer>",
"price": 100
}Limits that apply at Deriv
| Limit | Value | Scope | Source |
|---|---|---|---|
| Headline limit | 80/min per logged in user (REST)Sources conflict developers.deriv.com states 60, checked . Deriv's API overview in the text form it publishes for AI tools gives REST 60 requests a minute per token, where its Limits page gives 80 a minute per logged in user. The same overview also gives 100 WebSocket requests a second per connection, 100 active subscriptions per connection and 5 concurrent WebSocket connections per user, none of which the Limits page mentions. Deriv's own pages disagree; the conflict is labelled, not resolved. Pace against 60. | user, REST | developers.deriv.comchecked |