A webhook is a URL that allows one application to receive information from events happening on another application.
A webhook would allow you to receive trade data from TradeSync when the trade has happened.
You can create your own webhook by selecting 'Webhooks' on the dropdown with your username on the top right. This will show you a list of your current webhooks and their authentication type.
When you have selected the 'Add Webhook' button, you need to choose a type of authentication (see below) and you need to add the URL of your webhook.
There are four options for authentication:
If you run a php based server, here is a very basic example of how you could process your events.
$json = file_get_contents('php://input');
$users = getMyUsers();
foreach($users as $user){
$subject = "Hey " . $user['first_name'] . ", new trade event";
$msg = $json->event->type . " on account " . $json->event->account->number . "\r\n";
$msg .= print_r($json, TRUE);
// Send email to each user
mail($user['email_address'], $subject, $msg);
}
{
"event": {
"type": "trade_open",
"trade": {
"ticket": "230328976",
"open_time": "2017-06-12 17:52:22",
"symbol": "EURUSD",
"type": "buy",
"lots": "0.02",
"open_price": "1.12036",
"stop_loss": "0.00000",
"take_profit": "0.00000"
},
"account": {
"id": "1221",
"number": "2089228440",
"currency": "USD",
"balance": "49785.23",
"credit": "0.00",
"equity": "49932.77",
"free_margin": "49906.20",
"used_margin": "26.57"
}
}
}
{
"event": {
"type": "trade_close",
"trade": {
"ticket": "230328976",
"open_time": "2017-06-12 14:52:25",
"symbol": "EURUSD",
"type": "buy",
"lots": "0.02",
"open_price": null,
"stop_loss": "0.00000",
"take_profit": "0.00000",
"close_price": "1.12020",
"close_time": "2017-06-12 17:52:25",
"commission": "0.00",
"swap": "0.00",
"profit": "-0.32",
"total_profit": "-0.32"
},
"account": {
"id": "1221",
"number": "2089228440",
"currency": "USD",
"balance": "49784.91",
"credit": "0.00",
"equity": "49932.93",
"free_margin": "49910.84",
"used_margin": "22.09"
}
}
}
{
"event": {
"type": "trade_partial",
"trade": {
"ticket": "230328991",
"open_time": "2017-06-12 14:52:32",
"symbol": "EURUSD",
"type": "buy",
"lots": "0.01",
"open_price": null,
"stop_loss": "0.00000",
"take_profit": "0.00000",
"close_price": "1.12021",
"close_time": "2017-06-12 14:52:32",
"commission": "0.00",
"swap": "0.00",
"profit": "-0.17",
"total_profit": "-0.17"
},
"new_trade": {
"ticket": "230328992",
"lots": "0.01"
},
"account": {
"id": "1221",
"number": "2089228440",
"currency": "USD",
"balance": "49784.74",
"credit": "0.00",
"equity": "49932.69",
"free_margin": "49908.36",
"used_margin": "24.33"
}
}
}