Skip to content

Get Position Details

Overview

This page teaches you how to retrieve information about a specific position in your trading account. You can use this to monitor the performance of your position, such as the current market value, the unrealized profit or loss, the margin requirement, and the interest rate. You can also modify or close your position, or to create a new order based on the existing position. To access the Get Position Details, you need to provide the position ID, which is a unique identifier assigned by the FCLite API to each position. You can find the position ID in the response of the Create Order or the Get Positions requests. Alternatively, you can use the Search Positions page to find the position ID by specifying the instrument, the account ID, or the order ID.

Below is a JavaScript snippet that demonstrates how to retrieve position summary information:

Step 1

The subscribeToPositionsSummaryChange function sets up a listener for position summary changes. Whenever the summary data changes, the provided callback function (positionsSummaryChangeListener) will be called.

Step 2

The refreshPositionsSummary function triggers a refresh of the position summary data. You can call this when needed (e.g., after login or when you want to update the data).

Step 3

The unsubscribeFromPositionsSummaryChange function unsubscribes from position summary changes. Make sure to pass the same listener function used during subscription.

// Assume you have a session object and a positionsSummaryManager object.

// Subscribe to position summary changes
function subscribeToPositionsSummaryChange(manager) {
    const positionsSummaryChangeListener = (summary) => {
        // Handle position summary changes here
        console.log("Position summary changed:", summary);
    };

    manager.subscribePositionsSummaryChange(positionsSummaryChangeListener);
}

// Refresh position summary data 
function refreshPositionsSummary(manager) {
    manager.refresh();
}

// Unsubscribe from position summary changes
function unsubscribeFromPositionsSummaryChange(manager) {
    // Make sure to pass the same listener function used during subscription
    manager.unsubscribePositionsSummaryChange(positionsSummaryChangeListener);
}

// Example usage:
// Assuming you have a valid session and positionsSummaryManager
const session = /* ... */;
const positionsSummaryManager = /* ... */;

// Subscribe to position summary changes
subscribeToPositionsSummaryChange(positionsSummaryManager);

// Refresh position summary data
refreshPositionsSummary(positionsSummaryManager);

// Wait for some time (optional, for demonstration purposes)
setTimeout(() => {
    // Unsubscribe from position summary changes
    unsubscribeFromPositionsSummaryChange(positionsSummaryManager);
}, 5000); // Wait for 5 seconds

Conclusion

In this article, you learned how to use the FCLite API to get the details of an open position. You learned about the PositionsSummary class, which provides summary information about all open positions in one instrument. You also learned how to use the public methods of the PositionsSummary class to access various information about an open position, such as the profit/loss, the margin, the rollover interest, and the price. Finally, you learned how to refer to the API Reference for more information about the PositionsSummary class and its methods. By using the FCLite API, you can easily monitor and manage your open positions in the market.

Table of Contents
Get Open Positions
The article teaches how to get a list of open positions.
Get Closed Positions
The article teaches how to get a list of closed positions.
Get Position Details
API Command used to get the details of a position
Close a Position
API Command used to close a position
Close All Open Positions
API Command used to close all open positions