Skip to content

Price Details

Overview

This page provides more information about the price data that is available for the instruments that are supported by the FCLite API. You can learn about the different types of prices, such as the bid, ask, mid, and close prices, and how they are calculated and updated by the FXCM trading platform. You can also learn about the factors that affect the price movements of the instruments, such as the market events, news, supply and demand, and technical analysis.

To show all the details for a price using JavaScript, you can use the following example code:

Step 1

Create a status change listener and a login callback. You need to do this to monitor the connection status and handle the login response. You also need to subscribe the listener and the callback to the session object.

// Create a status change listener
class ConnectionStatusChangeListener extends FXConnectLite.IConnectionStatusChangeListener {
    onConnectionStatusChange(status) {
        console.log("Connection status changed. " + this.getStatusString(status));
    }

    getStatusString(status) {
        return (status.isConnected() ? "Connected" : "") +
            (status.isConnecting() ? "Connecting" : "") +
            (status.isReconnecting() ? "Reconnecting" : "") +
            (status.isDisconnected() ? "Disconnected" : "");
    }
}

// Create a login callback
class LoginCallback extends FXConnectLite.ILoginCallback {
    onLoginResponse(session, error) {
        if (error) {
            console.log("Login failed: " + error.message);
        } else {
            console.log("Login succeeded");
        }
    }
}

// Subscribe the listener and the callback to the session object
session.subscribeConnectionStatusChange(new ConnectionStatusChangeListener());
session.login(user, password, tradingSystemUrl, connectionName, new LoginCallback());

Step 2

Create a price update listener and a price update callback. You need to do this to receive real-time price updates for an instrument. You also need to subscribe the listener and the callback to the session object.

// Create a price update listener
class PriceUpdateListener extends FXConnectLite.IPriceUpdateListener {
    onPriceUpdate(session, instrument, bid, ask, spread, volume, timestamp) {
        console.log("Price update for " + instrument + ":");
        console.log("Bid: " + bid);
        console.log("Ask: " + ask);
        console.log("Spread: " + spread);
        console.log("Volume: " + volume);
        console.log("Timestamp: " + timestamp);
    }
}

// Create a price update callback
class PriceUpdateCallback extends FXConnectLite.IPriceUpdateCallback {
    onPriceUpdateResponse(session, instrument, error) {
        if (error) {
            console.log("Price update failed for " + instrument + ": " + error.message);
        } else {
            console.log("Price update succeeded for " + instrument);
        }
    }
}

// Subscribe the listener and the callback to the session object
session.subscribePriceUpdate(new PriceUpdateListener());

Step 3

Use the getPriceUpdate method to subscribe to price updates for an instrument. You need to do this to get the latest bid and ask prices, the spread, the volume, and the timestamp of each update. You also need to provide the instrument name as a parameter.

// Use the getPriceUpdate method to subscribe to price updates for an instrument
let instrument = "EUR/USD"; // The instrument name
session.getPriceUpdate(instrument, new PriceUpdateCallback());

Step 4

Use the unsubscribePriceUpdate method to stop receiving price updates for an instrument. You need to do this when you no longer need the price updates. You also need to provide the instrument name as a parameter.

// Use the unsubscribePriceUpdate method to stop receiving price updates for an instrument
let instrument = "EUR/USD"; // The instrument name
session.unsubscribePriceUpdate(instrument, new PriceUpdateCallback());

Note

The bid price is the highest price that a buyer is willing to pay for an instrument at a given time.

The ask price is the lowest price that a seller is willing to accept for an instrument at a given time.

The bid and ask prices are determined by the supply and demand of the instrument in the market, as well as the liquidity and volatility of the instrument.

The bid and ask prices are updated in real-time by the FXCM trading platform, which aggregates the prices from multiple liquidity providers, such as banks, hedge funds, and other brokers.

The bid and ask prices may vary depending on the type and size of the order, the account type, and the trading session.

Conclusion

The price details page provides more information about the price data that is available for the instruments that are supported by the FCLite API. It explains the different types of prices, such as the bid, ask, mid, and close prices, and how they are calculated and updated by the FXCM trading platform. It also discusses the factors that affect the price movements of the instruments, such as the market events, news, supply and demand, and technical analysis. The price details page is a useful resource for traders who want to understand the dynamics of the financial markets and make informed trading decisions using the FCLite API.

Table of Contents
Get Price Updates for an Instrument
The article teaches how to receive price updates for an instrument.
Get Historical Prices for an Instrument
The article teaches how to receive historical prices for an instrument.