Get up to 1000 open positions
URL: https://www.trade-copier.com/webservice/v4/position/getOpenPositions.php
The request may specify an optional filter object containing parameters to only retrieve positions between 2 dates, an account id or type, to include orders from inactive accounts, or a start position to search from. You can also limit the number of rows in the result.
Response: JSON object list
| Field Name | Field Type | Field Description |
|---|---|---|
| account_id | string | Unique identifier of the "Slave" account |
| master_id | string | Unique identifier of the "Master" account |
| master_name | string | Name of the "Master" account |
| ticket | string | Trade identifier (is not globally unique, but it is unique per account_id) |
| masterTicket | string | Master trade identifier. If equal to the ticket, it is a manual trade |
| openTime | string | Trade open time |
| side | string | Can be Buy, Sell, BuyLimit, SellLimit, BuyStop and SellStop |
| symbol | string | Instrument name |
| openPrice | float | |
| stopPrice | float | |
| limitPrice | float | |
| stopLoss | float | |
| takeProfit | float | |
| amountLot | float | Amount expressed in lot, can vary from one broker/technology to another |
| quantityCcy | float | Quantity expressed in the account currency |
| swapCcy | float | Swap expressed in the account currency |
| commissionBrokerCcy | float | The broker's commission expressed in the account currency |
| notional_USD | float | Amount equivalent in USD |
| ccy | string | Account currency |
| comment | string | Comment for the position |
Optional Parameters:
Parameter - Type - Description
fromDate - string - Start date (YYYY-MM-DD or ISO 8601). Max 4-week range with toDate.
toDate - string - Optional end date (defaults to today).
historyDays - int - Alternative to date range. Number of weeks in the past (1–4).
length - int - Max number of rows to return. Default/max: 10,000.
PHP example
<?php
echo "<link rel='stylesheet' type='text/css' href='https://www.trade-copier.com/webservice/example.css'>";
$url="https://www.trade-copier.com/webservice/v4/position/getOpenPositions.php";
$headers = array(
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Bearer [[TOKEN]]',
);
// Open connection
$ch = curl_init();
// Setting the options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Filter can specify a mix of fields, they are all optional
$filter = ['start' => 10, 'length' => 50];
//$filter = ['show_off' => true]; //include inactive accounts positions
//$filter = ['account_type' => '1']; //0 = master, 1 = slave
//$filter = ['fromDate' => "2022-04-01 00:00:00.00", 'toDate' => "2022-04-30 22:59:59.999", 'account_type' => '1'];
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($filter));
// Execute request
$json = json_decode(curl_exec($ch));
// Close connection
curl_close($ch);
//We access the order(s) list
if(array_key_exists('data', $json)) {
echo '<table id="api_data">';
foreach($json->data as $row) {
foreach($row as $key => $val) {
echo '<th>'.$key.'</th>';
}
break;
}
foreach($json->data as $position) {
echo '<tr>';
foreach($position as $key => $val) {
echo '<td>'.$val.'</td>';
}
echo '</tr>';
}
echo '</table>';
} else {
//This is an error message that can be access like this:
//echo $json->code." ".$json->error;
echo json_encode($json);
}
?>