Cancel
TradingAuth RequiredCancel an active contract by providing the contract ID. The loginid parameter is removed; the response is unchanged.
1 Breaking Change
The
loginid parameter is removed. The response is the same in the Legacy API and the New API.Quick comparison
Breaking changes
1. loginid parameter removed
In the Legacy API, loginid selected the account to cancel the contract from when you authorised several accounts. The New API does not accept it.
Required change: Remove loginid from your cancel requests. Your token selects the account.
Request structure
Legacy APIrequest example
{
"cancel": 11542203588,
"loginid": "CR123456",
"passthrough": {
"user_action": "manual_cancel"
},
"req_id": 1
}New APIrequest example
{
"cancel": 11542203588,
"passthrough": {
"user_action": "manual_cancel"
},
"req_id": 1
}Response structure
Legacy APIresponse example
{
"cancel": {
"balance_after": 10450.5,
"contract_id": 11542203588,
"reference_id": 11542203587,
"sold_for": 23.45,
"transaction_id": 11542203589
},
"echo_req": {
"cancel": 11542203588,
"passthrough": {
"user_action": "manual_cancel"
},
"req_id": 1
},
"msg_type": "cancel",
"req_id": 1
}New APIresponse example
{
"cancel": {
"balance_after": 10450.5,
"contract_id": 11542203588,
"reference_id": 11542203587,
"sold_for": 23.45,
"transaction_id": 11542203589
},
"echo_req": {
"cancel": 11542203588,
"passthrough": {
"user_action": "manual_cancel"
},
"req_id": 1
},
"msg_type": "cancel",
"req_id": 1
}Code examples
function cancelContract(contractId, loginId) {
const request = { cancel: contractId, req_id: 1 };
// Needed only when you authorised several accounts
if (loginId) request.loginid = loginId;
ws.send(JSON.stringify(request));
ws.onmessage = (message) => {
const response = JSON.parse(message.data);
if (response.msg_type !== "cancel") return;
if (response.error) {
console.error(response.error.message);
return;
}
if (response.cancel) {
console.log("Sold for: " + response.cancel.sold_for);
console.log("New balance: " + response.cancel.balance_after);
}
};
}Any other questions? Get in touch