New Async Methods
New Async Methods
29 Nov 2013, 08:01
After the new update I've been playing around a little. But I can't seem to pass the "callback" as a parameter. Code below shows an example of what I want.
protected override void OnStart() { OpenBuyLimitAsync("EURUSD", 10000, Symbol.Ask - 20 * Symbol.PipSize, "test1", null, null, null, "test", SendSMS); OpenBuyLimitAsync("EURUSD", 10000, Symbol.Ask - 20 * Symbol.PipSize, "test1", null, null, null, "test", PrintMsg); Stop(); } public void OpenBuyLimitAsync(string argSymbol, int argVolume, double argTargetPrice, string argLabel, double? argStoplossInPips, double? argTakeprofitInPips, DateTime? argExpiration, string argComment, Action argCallback) { Symbol XXXYYY = MarketData.GetSymbol(argSymbol); PlaceLimitOrderAsync(TradeType.Buy, XXXYYY, argVolume, argTargetPrice, argLabel, argStoplossInPips, argTakeprofitInPips, argExpiration, argComment, argCallback); } private void SendSMS(TradeResult result) { if (result.IsSuccessful) { Notifications.SendEmail(FromAddress, ToAddress, "Buy Limit", "Buy limit was successful."); } } private void PrintMsg(TradeResult result) { if (result.IsSuccessful) { Print("Buy limit was successful."); } }
I'm not exactly sure how to pass the callback as an argument. Help would be appreciated! Thanks :)
Replies
Hyperloop
29 Nov 2013, 20:36
RE:
Spotware said:
The Stop() method will be triggered before the callback is. Therefore, the robot will stop before the callback is triggered.
When using asynchronous methods, the callback is used to control execution when the result is received from the server.In asynchronous operation, when a request is send to the server, the program continues to execute the next statements, without waiting for the response from the server. The statements that follow the trade operation request cannot assume anything about the result of those requests.
You also need to change the type of the callback in your method to Actionprotected override void OnStart() { OpenBuyLimitAsync("EURUSD", 10000, Symbol.Ask - 20 * Symbol.PipSize, "test1", null, null, null, "test", SendSMS); OpenBuyLimitAsync("EURUSD", 10000, Symbol.Ask - 20 * Symbol.PipSize, "test1", null, null, null, "test", PrintMsg); // Stop(); } public void OpenBuyLimitAsync(string argSymbol, int argVolume, double argTargetPrice, string argLabel, double? argStoplossInPips, double? argTakeprofitInPips, DateTime? argExpiration, string argComment, Action argCallback) { Symbol XXXYYY = MarketData.GetSymbol(argSymbol); PlaceLimitOrderAsync(TradeType.Buy, XXXYYY, argVolume, argTargetPrice, argLabel, argStoplossInPips, argTakeprofitInPips, argExpiration, argComment, argCallback); }
Perfect thank you. I tried that last night, but couldn't get it working but re-entered and it compiled fine. Thanks again :)
@Hyperloop
Spotware
29 Nov 2013, 11:17
The Stop() method will be triggered before the callback is. Therefore, the robot will stop before the callback is triggered.
When using asynchronous methods, the callback is used to control execution when the result is received from the server.
In asynchronous operation, when a request is send to the server, the program continues to execute the next statements, without waiting for the response from the server. The statements that follow the trade operation request cannot assume anything about the result of those requests.
You also need to change the type of the callback in your method to Action<TradeResult>
@Spotware