Contract update history
TradingAuth RequiredGet the update history of a contract, such as changes to its stop loss and take profit. 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 history to read when you authorised several accounts. The New API does not accept it.
Required change: Remove loginid from your contract_update_history requests. Your token selects the account.
Request structure
Legacy APIrequest example
{
"contract_update_history": 1,
"contract_id": 123456789,
"limit": 10,
"loginid": "CR123456",
"req_id": 1
}New APIrequest example
{
"contract_update_history": 1,
"contract_id": 123456789,
"limit": 10,
"req_id": 1
}Response structure
Legacy APIresponse example
{
"contract_update_history": [
{
"display_name": "Take profit",
"order_amount": "25.00",
"order_date": 1760000000,
"order_type": "take_profit",
"value": "1256.78"
},
{
"display_name": "Stop loss",
"order_amount": "-15.00",
"order_date": 1759990000,
"order_type": "stop_loss",
"value": null
}
],
"echo_req": {
"contract_update_history": 1,
"contract_id": 123456789,
"limit": 10,
"req_id": 1
},
"msg_type": "contract_update_history",
"req_id": 1
}New APIresponse example
{
"contract_update_history": [
{
"display_name": "Take profit",
"order_amount": "25.00",
"order_date": 1760000000,
"order_type": "take_profit",
"value": "1256.78"
},
{
"display_name": "Stop loss",
"order_amount": "-15.00",
"order_date": 1759990000,
"order_type": "stop_loss",
"value": null
}
],
"echo_req": {
"contract_update_history": 1,
"contract_id": 123456789,
"limit": 10,
"req_id": 1
},
"msg_type": "contract_update_history",
"req_id": 1
}Code examples
function getUpdateHistory(contractId, loginId) {
const request = { contract_update_history: 1, contract_id: contractId, limit: 10, 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_history") return;
if (response.error) {
console.error(response.error.message);
return;
}
response.contract_update_history?.forEach((update) => {
console.log(update.display_name, update.order_amount, update.order_date);
});
};
}Any other questions? Get in touch