Deriv API
Documentation

Sell

TradingAuth Required

Sell an active contract before expiry to realize profit or minimize loss. The loginid parameter removed, price validation added, and response fields now guaranteed.

Quick comparison

AspectLegacy APINew APIAction
EndpointsellsellNone
Auth RequiredYesYesNone
loginid ParameterOptionalRemovedRemove from requests
price ValidationNo minimumminimum: 0Ensure non-negative
Response sell ObjectOptionalRequiredRemove null checks

Breaking changes

1. Removed loginid parameter

The loginid parameter that was used for multi-account scenarios has been removed in v4. Account context must now be established through the authorization flow.

2. price parameter validation added

The price parameter now has a minimum: 0 validation constraint. Negative values will be rejected.

Required change: Ensure you always pass a non-negative value for price. Use 0 for selling at market.

3. sell object now required in response

In legacy, the sell object was optional in the response. In v4, it is always present for successful sell operations.

4. All sell object fields now required

All 5 fields inside the sell object are now guaranteed to be present: balance_after, contract_id, reference_id, sold_for, and transaction_id.

Request structure

Legacy APIrequest example
{
  "sell": 11542203588,
  "price": 500,
  "loginid": "CR123456"
}
New APIrequest example
{
  "sell": 11542203588,
  "price": 500
}

Response structure

Legacy APIresponse example
{
  "sell": {
    "balance_after": 10500.50,
    "contract_id": 11542203588,
    "sold_for": 750.25
  },
  "msg_type": "sell"
}
New APIresponse example
{
  "sell": {
    "balance_after": 10500.50,
    "contract_id": 11542203588,
    "reference_id": 11542203587,
    "sold_for": 750.25,
    "transaction_id": 98765432
  },
  "msg_type": "sell"
}

Code examples

async function sellContract(contractId, minimumPrice, loginId) {
  const request = {
    sell: contractId,
    price: minimumPrice,
    loginid: loginId
  };
  
  ws.send(JSON.stringify(request));
  
  ws.onmessage = (msg) => {
    const response = JSON.parse(msg.data);
    if (response.msg_type === "sell") {
      if (response.sell) {
        const soldFor = response.sell.sold_for ?? 0;
        console.log("Sold for: " + soldFor);
      }
    }
  };
}
Click to open live chat support. Get instant help from our support team.