Documentation

Buy

TradingAuth Required

Purchase a contract. The loginid parameter is removed, and several fields in parameters changed.

Quick comparison

AspectLegacy APINew APIAction
EndpointbuybuyNone
Auth RequiredYesYesNone
loginid parameterOptionalRemovedRemove from requests
parameters.symbolRequiredRenamed to underlying_symbolRename in requests
Five parameters fieldsAcceptedRemovedRemove from requests
contract_type valuesIncludes spread, lookback and snow typesAdds HIGHER and LOWERReview contract types

Breaking changes

1. loginid parameter removed

The loginid parameter has been removed in New. This parameter was previously used for multi-account authentication.

Required change: Remove the loginid field from your buy requests. Account selection is now handled through the authorization token.

2. parameters.symbol renamed to parameters.underlying_symbol

The symbol field inside parameters is now underlying_symbol. The New API lists underlying_symbol as required in parameters, so a request that still sends parameters.symbol fails.

Required change: Rename parameters.symbol to parameters.underlying_symbol in your buy requests.

3. Fields removed from parameters

These fields are removed from parameters in the New API: barrier_range, date_start, product_type, trade_risk_profile and trading_period_start.

Required change: Remove these fields from the parameters object in your buy requests.

4. contract_type values changed

The parameters.contract_type list no longer includes CALLSPREAD, PUTSPREAD, LBFLOATCALL, LBFLOATPUT, LBHIGHLOW, SNOWUP or SNOWDOWN. It adds HIGHER and LOWER.

Required change: Stop sending the removed contract types. Use one of the values the New API lists instead.

Request structure

Legacy APIrequest example
{
  "buy": "uw2mk7no3oktoRVVsB4Dz7TQnFfABuFDgO95dlxfMxRuPUsz",
  "price": 10.50,
  "loginid": "CR123456"
}
New APIrequest example
{
  "buy": "uw2mk7no3oktoRVVsB4Dz7TQnFfABuFDgO95dlxfMxRuPUsz",
  "price": 10.50
}

Response structure

Legacy APIresponse example
{
  "buy": {
    "balance_after": 9989.50,
    "buy_price": 10.50,
    "contract_id": 123456789,
    "longcode": "Win payout if Volatility 100 Index is strictly higher than entry spot at 5 minutes after contract start time.",
    "payout": 20.00,
    "purchase_time": 1234567890,
    "shortcode": "CALL_R_100_20_1234567890_1234568190_S0P_0",
    "start_time": 1234567890,
    "transaction_id": 987654321
  },
  "echo_req": { "buy": "uw2mk7no3oktoRVVsB4Dz7TQnFfABuFDgO95dlxfMxRuPUsz", "price": 10.50 },
  "msg_type": "buy"
}
New APIresponse example
{
  "buy": {
    "balance_after": 9989.50,
    "buy_price": 10.50,
    "contract_id": 123456789,
    "longcode": "Win payout if Volatility 100 Index is strictly higher than entry spot at 5 minutes after contract start time.",
    "payout": 20.00,
    "purchase_time": 1234567890,
    "shortcode": "CALL_R_100_20_1234567890_1234568190_S0P_0",
    "start_time": 1234567890,
    "transaction_id": 987654321
  },
  "echo_req": { "buy": "uw2mk7no3oktoRVVsB4Dz7TQnFfABuFDgO95dlxfMxRuPUsz", "price": 10.50 },
  "msg_type": "buy"
}

Code examples

async function buyContract(proposalId, price, loginid) {
  const request = {
    buy: proposalId,
    price: price,
    // loginid used for multi-account support
    loginid: loginid
  };

  ws.send(JSON.stringify(request));

  ws.onmessage = (event) => {
    const response = JSON.parse(event.data);
    if (response.msg_type === "buy") {
      // buy object may be missing in some cases
      if (response.buy) {
        console.log("Contract ID:", response.buy.contract_id);
      }
    }
  };
}
Click to open live chat support. Get instant help from our support team.