1.5.1Async functions and await syntax

The existence of Promises also means that it's possible to use Javascript await syntax, instead of the callback functions - or then() - which are used in this document, and generated by the Run Script widget.

Scripts are automatically run inside an async function. Therefore, it's possible to write code such as the following:

var result = await Framework.pSendOrder({"tradingAction": FXB.OrderTypes.FLATTEN});

Framework.EndScript();

It's not necessary to declare an async function and then pass execution into that:

async function MyAsyncFunction()

{

var result = await Framework.pSendOrder({"tradingAction": FXB.OrderTypes.FLATTEN});

Framework.EndScript();

}

MyAsyncFunction();