Sell
TradingAuth RequiredSell an active contract before expiry to realize profit or minimize loss. The loginid parameter removed, price validation added, and response fields now guaranteed.
4 Breaking Changes
loginid parameter has been removed, the price parameter now requires minimum value of 0, and the sell object and its fields are now required in response.Quick comparison
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
{
"sell": 11542203588,
"price": 500,
"loginid": "CR123456"
}{
"sell": 11542203588,
"price": 500
}Response structure
{
"sell": {
"balance_after": 10500.50,
"contract_id": 11542203588,
"sold_for": 750.25
},
"msg_type": "sell"
}{
"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);
}
}
};
}Any other questions? Get in touch