Contract update
TradingAuth RequiredUpdate a contract's take profit and stop loss. 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 whose contract to update when you authorised several accounts. The New API does not accept it.
Required change: Remove loginid from your contract_update requests. Your token selects the account.
Request structure
Legacy APIrequest example
{
"contract_update": 1,
"contract_id": 123456789,
"limit_order": {
"stop_loss": 15,
"take_profit": 25
},
"loginid": "CR123456",
"req_id": 1
}New APIrequest example
{
"contract_update": 1,
"contract_id": 123456789,
"limit_order": {
"stop_loss": 15,
"take_profit": 25
},
"req_id": 1
}Response structure
Legacy APIresponse example
{
"contract_update": {
"stop_loss": {
"display_name": "Stop loss",
"order_amount": -15,
"order_date": 1760000000,
"value": "1234.56"
},
"take_profit": {
"display_name": "Take profit",
"order_amount": 25,
"order_date": 1760000000,
"value": "1256.78"
}
},
"echo_req": {
"contract_update": 1,
"contract_id": 123456789,
"limit_order": {
"stop_loss": 15,
"take_profit": 25
},
"req_id": 1
},
"msg_type": "contract_update",
"req_id": 1
}New APIresponse example
{
"contract_update": {
"stop_loss": {
"display_name": "Stop loss",
"order_amount": -15,
"order_date": 1760000000,
"value": "1234.56"
},
"take_profit": {
"display_name": "Take profit",
"order_amount": 25,
"order_date": 1760000000,
"value": "1256.78"
}
},
"echo_req": {
"contract_update": 1,
"contract_id": 123456789,
"limit_order": {
"stop_loss": 15,
"take_profit": 25
},
"req_id": 1
},
"msg_type": "contract_update",
"req_id": 1
}Code examples
function updateContract(contractId, loginId) {
const request = {
contract_update: 1,
contract_id: contractId,
limit_order: { stop_loss: 15, take_profit: 25 },
req_id: 1
};
// Needed only when you authorised several accounts
if (loginId) request.loginid = loginId;
ws.send(JSON.stringify(request));
ws.onmessage = (event) => {
const response = JSON.parse(event.data);
if (response.msg_type !== "contract_update") return;
if (response.error) {
console.error(response.error.message);
return;
}
if (response.contract_update) {
const { stop_loss, take_profit } = response.contract_update;
console.log("Stop loss:", stop_loss?.order_amount);
console.log("Take profit:", take_profit?.order_amount);
}
};
}Any other questions? Get in touch