Account History
Overview
The FCLite API allows you to access the account history of your trading activities, such as orders, positions, trades, and balance changes. You can use the account history to analyze your performance, calculate your profits and losses, and generate reports.
To access the account history, you can use one of the following classes:
1. core.entity.closedpositions
This class provides access to the list of closed positions for an account. A closed position is a trade that has been settled by an opposite trade or by an order being triggered.
To use this class, you need to create an instance of it by passing the account ID as a parameter. For example:
// Import the FCLite API module
const fclite = require('fclite');
// Create an instance of the closedpositions class for account 123456
let cp = new fclite.core.entity.closedpositions(123456);
Then, you can use the getClosedPositions method of this class to retrieve the account history as an array of core.entity.closedposition objects, each representing a closed position with its details. For example:
// Get the account history as an array of closedposition objects
let history = cp.getClosedPositions();
// Loop through the array and print the details of each closed position
for (let item of history) {
console.log("Type:", item.type); // The type of the closed position, either BUY or SELL
console.log("Instrument:", item.instrument); // The instrument of the closed position, such as EUR/USD, AAPL, or BTC/USD
console.log("Open Time:", item.openTime); // The time when the position was opened, in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
console.log("Close Time:", item.closeTime); // The time when the position was closed, in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
console.log("Open Price:", item.openPrice); // The price at which the position was opened, in units of the quote currency
console.log("Close Price:", item.closePrice); // The price at which the position was closed, in units of the quote currency
console.log("Amount:", item.amount); // The amount of the position, in units of the instrument
console.log("Profit:", item.profit); // The profit or loss of the position, in units of the account currency
console.log("Balance:", item.balance); // The balance of the account after the position was closed, in units of the account currency
console.log();
}
2. core.entity.messages.data.terminals
This class provides access to the list of terminals for an account. A terminal is a device or a platform that connects to the FCLite API and executes trading operations.
To use this class, you need to create an instance of it by passing the account ID as a parameter. For example:
// Import the FCLite API module
const fclite = require('fclite');
// Create an instance of the terminals class for account 123456
let terminals = new fclite.core.entity.messages.data.terminals(123456);
Then, you can use the getTerminals method of this class to retrieve the account history as an array of core.entity.message.data.terminal objects, each representing a terminal with its details.
For example:
// Get the account history as an array of terminal objects
let history = terminals.getTerminals();
// Loop through the array and print the details of each terminal
for (let item of history) {
console.log("ID:", item.id); // The ID of the terminal, unique within the account
console.log("Name:", item.name); // The name of the terminal, such as MT4, MT5, or WebTrader
console.log("Type:", item.type); // The type of the terminal, such as DESKTOP, MOBILE, or WEB
console.log("Status:", item.status); // The status of the terminal, either ONLINE or OFFLINE
console.log("Last Login:", item.lastLogin); // The last time the terminal logged in to the FCLite API, in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
console.log("Last Logout:", item.lastLogout); // The last time the terminal logged out from the FCLite API, in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)
console.log("Orders:", item.orders); // The number of orders executed by the terminal
console.log("Trades:", item.trades); // The number of trades executed by the terminal
console.log("Volume:", item.volume); // The total volume of trades executed by the terminal, in units of the instrument
console.log("Profit:", item.profit); // The total profit or loss of trades executed by the terminal, in units of the account currency
console.log();
}
| Table of Contents | |
|---|---|
| Accounts API Commands used to get account history information |
|
| Get All Accounts The article teaches how to get a list of all accounts. |
|
| Refresh Account Profile Data The article teaches how to refresh an accounts profile data. |