//[Idempotent] -- TODO make this idempotent by checking for existing bots private async Task <bool> InitBots() { //if (account == null) { return false; } //account.StatusTextChanged += OnAccountStatusTextChanged; //StatusText = account.StatusText; //var symbols = new ObservableCollection<SymbolVM>(); //foreach (var s in account.SymbolsAvailable) //{ // var symbol = account.GetSymbol(s); // var vm = new SymbolVM(symbol, account); // symbols.Add(vm); //} //VM.Symbols = symbols; //if (Mode.HasFlag(BotMode.Live)) { await LoadBots(Template.LiveBots, ref liveBots, BotMode.Live); } //if (Mode.HasFlag(BotMode.Demo)) { await LoadBots(Template.DemoBots, ref demoBots, BotMode.Demo); } if (Mode.HasFlag(BotMode.Scanner)) { await LoadBots(Template.Bots, ref bots, BotMode.Scanner).ConfigureAwait(false); } //if (Mode.HasFlag(BotMode.Paper)) { await LoadBots(Template.PaperBots, ref paperBots, BotMode.Paper); } foreach (var bot in Bots.OfType <IInitializable>().ToArray()) { try { var result = await bot.Initialize().ConfigureAwait(false); if (!result) { Debug.WriteLine($"Bot failed to initialize: {bot}{Environment.NewLine}{(bot as AccountParticipant)?.FaultException?.ToString()}"); } } catch { // EMPTYCATCH - intended } //if (!result) //{ // throw new Exception($"Bot failed to initialize: {bot}"); //} } return(true); }