Get All Orders

Brief

The article teaches how to get a list of all orders.

Details

How to Obtain a List of all Orders

This article teaches how to get a list of all orders using the order manager. Orders are instructions to buy or sell an instrument at a specified price, volume, and time.
You can get a list of all orders, or filter them by instrument, status, or type.

Before you can get a list of all orders, you need to:

Step 1: Create an Order Manager and Subscribe to the State Change Event

The state change event is an event that occurs when the order manager's state changes. The state can change due to new orders, modified orders, cancelled orders, or executed orders. To subscribe to the state change event, you need to create a listener function that implements the IStateChangeListener interface.

The listener function has one method: onStateChanged. The method is called when the state change event occurs.

Below, you can see some example code to subscribe to the state change event:

Subscribe to the state change event Hide

typescriptjavascriptjava
session.getOrdersManager().subscribeStateChange(completeHandler); //get orders manager session.getOrdersManager().refresh();

See also subscribeStateChange, refresh()

Step 2: Getting a List of all Orders.

To get a list of all orders, you can use the order manager's getOrdersSnapshot method.
This method returns a list of all orders that are currently in the order manager's state.
You can use the order printer to print the details of each order.

Below, you can see some example code for getOrdersSnapshot :

To get orders snapshot Hide

typescriptjavascriptjava
let ordersManager = session.getOrdersManager(); OrderPrinter.printAll(ordersManager.getOrdersSnapshot()); // get orders snapshot

To use the listener function, you need to subscribe it to the order manager using the subscribeStateChange method.
You also need to call the refresh method to initialize the order manager's state.

See also IOrdersManager, getOrdersSnapshot

Step 3: Creating an order printer.

An order printer is a function that takes an order as an argument and prints its base properties.

The base properties are:

Below, you can see some example code for the order printer :

The order printer Hide

typescriptjavascriptjava
class OrderPrinter { public static print(order: FXConnectLite.Order): void { Printer.print(`OrderId = ${order.getOrderId()} AccountId = ${order.getAccountId()} OfferId = ${order.getOfferId()} Amount = ${order.getAmount()} Rate = ${order.getRate()} Type = ${order.getType()} Status = ${order.getStatus()} BuySell = ${order.getBuySell()}`) } public static printAll(orders: FXConnectLite.Order[]): void { Printer.print(`Current orders snapshot:`); Printer.print(`Number of orders is ${orders.length}`); orders.forEach(order => { OrderPrinter.print(order); }); } }

See also Order

Conclusion:

You have learned how to get a list of all orders using the order manager. Orders are instructions to buy or sell an instrument at a specified price, volume, and time. Before you can get a list of all orders, you need to create an order manager, subscribe to the state change event, and create an order printer. The state change event is an event that occurs when the order manager's state changes due to new orders, modified orders, cancelled orders, or executed orders. You can subscribe to the state change event by creating a listener function that implements the IStateChangeListener interface and subscribing it to the order manager using the subscribeStateChange method. You can also get a list of all orders by using the order manager's getOrdersSnapshot method. You can now use this knowledge to manage your orders on the platform.

Download the sample TypeScript, JavaScript.

back