Skip to content

Rollover Interest

Overview

The rollover is the amount of funds earned or paid for holding an opened position overnight, through the end of the trading day.

If you hold your positions open past the end of trading day, you will either pay or earn rollover interest. This is the difference between the interest rates of the two currencies being traded.

If you purchase a currency with a higher interest rate than the one you have borrowed from a dealer, you will earn the difference between the interest rates. If you purchase a currency with a lower interest rate than the one you have borrowed from a dealer, you will have to pay the difference between the interest rates.

The interest rates of currencies constantly change. So one day a rollover may result in interest rate being added to your account, another day it may result in interest rate being subtracted from your account.

In this article we will be showing you how you can determine the about of rollover that you are due or due to pay.

Follow the following steps to retreive your rollover:

  1. Login (see the tutorial here)

  2. Create an instance of the instruments manager.

  3. Get a list of instrument descriptors.

  4. Get rollover interest for your instruments.

  1. Login (see the tutorial here)

  2. Create an instance of the instruments manager.

  3. Get a list of instrument descriptors.

  4. Get rollover interest for your instruments.

  1. Login (see the tutorial here)

  2. Create an instance of the instruments manager.

  3. Get a list of instrument descriptors.

  4. Get rollover interest for your instruments.

  5. Adding Event Listeners.

  6. Printing the results in a readable format.

  7. Updating the html to include our new JavaScript files.

  8. The main JavaScript file.

Step 1: Login

Follow the steps in the login tutorial here

Step 2: Create an instance of the instruments manager

const session: FXConnectLite.IFXConnectLiteSession = sessionFactory.create("LoginSample"); //LoginSample - any name;
let manager = session.getInstrumentsManager();
const instrument: FXConnectLite.Instrument = manager.getInstrumentBySymbol("USD/JPY");
const account: FXConnectLite.Account = this.getAccount(session);
const session = sessionFactory.create("LoginSample"); //LoginSample - any name;
let manager = session.getInstrumentsManager();
const instrument =  manager.getInstrumentBySymbol("USD/JPY");
const account = this.getAccount(session);

Step 3: Get a list of instrument descriptors

To get the correct rollover values after executing the command to subscribe to a new instrument, you must refresh the rollover value using the command rolloverProfilesManager.refresh().

const rolloverProfilesManager = session.getRolloverProfilesManager();
const rolloverProfilesManager = session.getRolloverProfilesManager();

Step 4: Get rollover interest for your instruments

To get rollover interest for your instrument, do the follow:

const rolloverBuy = rolloverProfilesManager.getRolloverBuy(instrument, account);
const rolloverSell = rolloverProfilesManager.getRolloverSell(instrument, account);
const rolloverBuy = rolloverProfilesManager.getRolloverBuy(instrument, account);
const rolloverSell = rolloverProfilesManager.getRolloverSell(instrument, account);

Here we have a worker class rollovers\rollover-worker.js that is responsible for passing our results to the printing classes.

class RolloverWorker {
    constructor(rolloverProfilesManager) {
        this.rolloverProfilesManager = rolloverProfilesManager;

        this.builder = new RolloverTableBuilder();
    }

    showRollover(instrument, account) {
        let rolloverBuy = this.rolloverProfilesManager.getRolloverBuy(instrument, account);
        let rolloverSell = this.rolloverProfilesManager.getRolloverSell(instrument, account);

        this.builder.renderRolloverTable(instrument, rolloverBuy, rolloverSell);

        console.log(message);
    }
}

Step 5: Adding Event Listeners

Event listeners in JavaScript provide a mechanism to detect and respond to user interactions or system events in web applications. By registering functions to specific events, such as clicks, key presses, or mouse movements, developers can create dynamic and interactive user experiences. This documentation outlines how to use event listeners, the types of events available, and their integration with the Document Object Model (DOM) for effective web development. accounts\get-accounts-snapshot-callback.js
class GetAccountsSnapshotCallback {
    constructor(instrumentsManager, rolloverProfilesManager) {
        this.instrumentsManager = instrumentsManager;
        this.rolloverProfilesManager = rolloverProfilesManager;
        }

    #getInstrument(instrumentName) {
        let instrument = this.instrumentsManager.getInstrumentBySymbol(instrumentName);
        if (instrument !== null) 
            return instrument;

        let descriptor = this.instrumentsManager.getInstrumentDescriptorBySymbol(instrumentName);
        if (descriptor !== null && descriptor.getSubscriptionStatus() === 'D') {
            console.log(`Instrument '${instrumentName}' is not subscribed. Subscribe it now.`);

            let subscribeInstrumentsCallback = new SubscribeInstrumentsCallback(instrumentName, this.instrumentsManager, this.rolloverProfilesManager);
            this.instrumentsManager.subscribeInstrumentsAndStoreOnServer([instrumentName], subscribeInstrumentsCallback);

            return null;
        }

        console.log(`Instrument '${instrumentName}' not found.`);
        return null;
    }

    onAccountsReceived(accounts) {
        let account = accounts[0];

        let instrumentName = 'AUD/CAD';
        let instrument = this.#getInstrument(instrumentName);
        if (instrument === null)
            return;

        let rolloverWorker = new RolloverWorker(this.rolloverProfilesManager);
        rolloverWorker.showRollover(instrument, account);
    }
}
instruments\instrument-state-listener.js
class InstrumentStateListener {
    constructor(rolloverProfilesManager) {
        this.rolloverProfilesManager = rolloverProfilesManager;
    }

    onStateChange(state) {
        if (state.isLoaded()) 
            this.rolloverProfilesManager.refresh();
    }
}
instruments\subscribe-instruments-callback.js
class SubscribeInstrumentsCallback {
    constructor(instrumentName, instrumentsManager, rolloverProfilesManager) {
        this.instrumentName = instrumentName;
        this.instrumentsManager = instrumentsManager;
        this.rolloverProfilesManager = rolloverProfilesManager;
    }

    onSuccess() {
        this.instrumentsManager.getInstrumentBySymbol(this.instrumentName);
        this.rolloverProfilesManager.refresh();
    }

    onError(error) {
        let message = `Instrument '${this.instrumentName}' subscription error: '${error}'.`;
        showErrorAlert(message);
    }
}
rollovers\rollover-profile-callback.js
class rolloverProfileCallback {
    constructor(accountsManager, getAccountsSnapshotCallback) {
        this.accountsManager = accountsManager;
        this.getAccountsSnapshotCallback = getAccountsSnapshotCallback;
    }

    onStateChange(state) {
        if (!state.isLoaded())
            return;

        this.accountsManager.getAccountsSnapshot(this.getAccountsSnapshotCallback);
    }
}

Step 6: Printing the results in a readable format

For printing the results of the command, we have first created a file which will contain our TableBuilder class. Follow the instruction in the Table Builder tutorial here.

Next we will create the file rollovers\rollover-table-builder.js which will use the previous Table Builder class and will populate all of the values in the table.

class RolloverTableBuilder {
    constructor() {
        this.builder = new TableBuilder();
    }

    #renderRolloverTableHeader() {
        let columns = [
            { className: 'col-sm-3', value: 'Offer ID' },
            { className: 'col-sm-3', value: 'Symbol' },
            { className: 'col-sm-3', value: 'Rollover Sell' },
            { className: 'col-sm-3', value: 'Rollover Buy' }
        ];

        this.builder.createHeaderTableRow(columns);
    }

    #renderDataTableRow(instrument, rolloverBuy, getRolloverSell) {
        let columns = [
            { className: 'col-sm-3', value: instrument.getOfferId() },
            { className: 'col-sm-3', value: instrument.getSymbol() },
            { className: 'col-sm-3', value: rolloverBuy },
            { className: 'col-sm-3', value: getRolloverSell }
        ];

        this.builder.createDataTableRow(columns);
    }

    renderRolloverTable(instrument, rolloverBuy, getRolloverSell) {
        this.#renderRolloverTableHeader();
        this.#renderDataTableRow(instrument, rolloverBuy, getRolloverSell);

        this.builder.showContainer();
    }
}

Step 7: Updating the html to include our new JavaScript files

<script src="connection_management/connection-status-change-listener.js"></script>
<script src="accounts/get-accounts-snapshot-callback.js"></script>
<script src="instruments/instrument-state-listener.js"></script>
<script src="instruments/subscribe-instruments-callback.js"></script>
<script src="rollovers/rollover-profile-callback.js"></script>
<script src="rollovers/rollover-table-builder.js"></script>
<script src="rollovers/rollover-worker.js"></script>
<script src="common/table-builder.js"></script>
<script src="index.js"></script>

Step 8: The main JavaScript file

index.js

const sessionFactory = FXConnectLite.FXConnectLiteSessionFactory;
const LoggerFactory = FXConnectLite.LoggerFactory;

document.addEventListener('DOMContentLoaded', () => {
    let session = sessionFactory.create('GetRolloverSample');
    session.setLogger(LoggerFactory.createLogger(LoggerFactory.LEVEL_DEBUG));

    let instrumentsManager = session.getInstrumentsManager();
    session.subscribeConnectionStatusChange(new ConnectionStatusChangeListener(session, instrumentsManager));

    let rolloverProfilesManager = session.getRolloverProfilesManager();
    instrumentsManager.subscribeStateChange(new InstrumentStateListener(rolloverProfilesManager));

    let accountsManager = session.getAccountsManager();
    let getAccountsSnapshotCallback = new GetAccountsSnapshotCallback(instrumentsManager, rolloverProfilesManager);
    rolloverProfilesManager.subscribeStateChange(new rolloverProfileCallback(accountsManager, getAccountsSnapshotCallback));

    bindConnectionRelatedEvents(session);
    bindConnectionRelatedEvents(session, () => instrumentsManager.refresh());
});

See also Instrument Subscriptions.

Conclusion

In this article, we learned what a rollover interest is and how to get the correct rollover values after executing the command to subscribe to a new instrument.

Download the sample Node TypeScript, Node JavaScript, Java.