The article teaches how to create a market order.
How to create a market order
In this article you will learn how to create a market order, which is a type of order that is executed immediately at the current market price. You can use market orders to open a new trade or close an existing trade.
To create a market order, you need to follow these steps:
Step 1: Create an OpenOrderFactory object.
You need to create an OpenOrderFactory object, which is a helper class that helps you set up the order parameters, such as the instrument, the direction, the amount, and the slippage.
OpenOrderFactory Hide
typescriptjavascriptlet OpenOrderFactory = /** @class */ (function () { function OpenOrderFactory() { } OpenOrderFactory.create = function (manager, offersManager, accountId, offerId, amount) { return manager.getRequestFactory().createMarketOrderRequestBuilder() .setAccountId(accountId) .setAmount(amount) .setOfferId(offerId) .setBuySell('B') .setTimeInForce('IOC') .build(); }; return OpenOrderFactory; }());
See also IOrdersManager, getRequestFactory, MarketOrderRequestBuilder
Step 2: Create a Market Order Request
You can use the OpenOrderFactory object to create a market order request, which is an object that contains all the information needed to place the order.
Create a market order. Hide
typescriptjavascriptlet instrument = instrumentsManager.getInstrumentBySymbol("EUR/GBP"); //getting offer Id let offerId = instrument.getOfferId(); let amount = 100; //any integer //create ordersManager let manager = session.getOrdersManager(); //create offersManager let offersManager = session.getOffersManager(); //create accountManager let accountsManager = session.getAccountsManager(); //get first account let account = accountsManager.getAccountById(accountsManager.getAccountsInfo()[0].getId());// a user can have multiple accounts. //create using order factory let request = OpenOrderFactory.create(manager, offersManager, account.getAccountId(), offerId, amount); //create market order manager.createOpenMarketOrder(request);
See also createOpenMarketOrder
Conclusion:
In this article, you learned how to create a market order using the FCLite API. A market order is a type of order that is executed immediately at the current market price. You learned how to create an OpenOrderFactory object, which is a helper class that helps you set up the order parameters. You also learned how to create a market order request, which is an object that contains all the information needed to place the order. Finally, you learned how to use the ordersManager object to send the request to the FCLite server. You can use market orders to open a new trade or to close an existing trade quickly and easily. You can also modify or cancel your market orders using similar methods. To learn more about the FCLite API and its features, you can refer to this official documentation.
Download the sample TypeScript, JavaScript.