The article teaches how to create an entry order.
How to create an entry order
In this article you will learn how to create an entry order, which is a type of order that is executed when the market price reaches a specified level.
You can use entry orders to enter a trade at a favorable price or to set a stop-loss or take-profit for an existing trade.
Step 1: Create an EntryOrderFactory object. You need to create an EntryOrderFactory object, which is a helper class that helps you set up the order parameters, such as the instrument, the direction, the amount, the price, and the expiration date.
You can use the following code to create an EntryOrderFactory object:
Create the class Hide
typescriptjavascriptclass EntryOrderFactory { static create(manager, offersManager, accountId, offerId, amount) { let offer = offersManager.getOfferById(offerId); return manager.getRequestFactory().createEntryOrderRequestBuilder() .setAccountId(accountId) .setAmount(amount) .setOfferId(offerId) .setBuySell('B') .setTimeInForce('GTC') .setCustomId('custom-id-open') .setLimitRate(offer.getAsk() + offer.getAsk() / 90) .setStopRate(offer.getAsk() - offer.getAsk() / 100) .setRate(offer.getAsk() + offer.getAsk() / 100) .setRateRange(10) .enableTrailingStop(FXConnectLite.TrailingStopType.Fixed, 10) .build(); } }
See also IOrdersManager, getRequestFactory,IOrdersRequestBuilderFactory, EntryOrderRequestBuilder
Step 2: Create an Entry Order Request.
Now, use the EntryOrderFactory object to create an entry order request, which is an object that contains all the information needed to place the order.
You can use the following code to create an entry order request:
Create an entry order Hide
typescriptjavascriptlet offerId = instrument.getOfferId(); const 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 const account = accountsManager.getAccountById(accountsManager.getAccountsInfo()[0].getId()); //create request using our custom order factory let request = EntryOrderFactory.create(manager, offersManager, account.getAccountId(), offerId, amount); //create entry order manager.createEntryOrder(request);
See also createEntryOrder
Conclusion:
In this article, you learned how to create an entry order using the FCLite API. An entry order is a type of order that is executed when the market price reaches a specified level. You learned how to create an EntryOrderFactory object, which is a helper class that helps you set up the order parameters. You also learned how to create an entry 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 entry orders to enter a trade at a favorable price or to set a stop-loss or take-profit for an existing trade. You can also modify or cancel your entry 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.