1.4Asynchronous operation

Most operations in the framework are asynchronous. The most obvious example is placing a trade: you send a trading request and you provide a callback function (or "completion handler", or whatever term you prefer) which the framework later calls when the action completes. For example:

Framework.SendOrder(orderDefinition, function(MsgResult) {

// Function called asynchronously by the framework when the order succeeds or fails

});

Another example would be asking the user a question by displaying the framework's standard Ask() dialog:

Framework.Ask("Are you sure?", function (Msg) {

// Called asynchronously by the framework

});

This example is in fact slightly more complicated than it looks. Your asynchronous callback from Ask() gets called twice, not once. The second call is the result; the user's response. The first call is an update which gives you the ID of the dialog, giving you the ability to cancel the dialog yourself - for example, if the user takes too long to decide.

And some types of asynchronous callback can get called multiple times. For example, if you issue a request for candle data then - unless you specifically say that you don't want streaming - your callback function will get called multiple times: with an initial batch of candles, and then with each update as the price changes and the current candle is modified or a new candle is formed. For example:

Framework.RequestCandles(candleDef, function(Msg) {

// Called repeatedly, until you terminate it with TerminateCandleRequest()

});