/// <summary> /// ImportContracts /// </summary> /// <param name="p"></param> private async Task CommandImportContractsAsync(object p) { if (String.IsNullOrWhiteSpace(ExchangeIbSelected)) { LogCurrent.Add($"ERROR! Exchange must be selected."); return; } LogCurrent = LogSymbols; LogCurrent.Clear(); BackgroundLog = Brushes.Gray; await Task.Run(() => { try { string[] companiesArray = null; int delay = 0; Dispatcher.Invoke(() => { delay = Convert.ToInt32(Configuration.Instance["DelayMathingSymbols"]); companiesArray = CompaniesForSymbolResolution.ToArray(); CompaniesList = companiesArray.ToList(); SymbolProcessed = new List <string>(); CompaniesProcessed = new List <string>(); }); foreach (var company in companiesArray) { CurrentCompany = company; IbClient.Instance.LookForSymbols(CurrentCompany); Thread.Sleep(delay); } } catch (Exception exception) { Dispatcher.Invoke(() => { LogCurrent.Add(exception.ToString()); }); } }); if (ConnectedToIb) { LogCurrent.Add($"OK! Import completed."); DataContext.Instance.SaveChanges(); LogCurrent.Add("OK! All contracts saved in database."); IbClient.Instance.Disonnect(); UpdateDbState(); InventoryText = GenerateInventoryText(); UpdateCompaniesForSymbolResolution(ExchangesFmpSelected); } else { LogCurrent.Add($"ERROR! Error while connection to IB server."); } }
/// <summary> /// ImportFundamentals /// </summary> /// <param name="p"></param> private async Task CommandImportFundamentalsAsync(object p) { LogCurrent = LogFundamentals; LogCurrent.Clear(); BackgroundLog = Brushes.Gray; await Task.Run(() => { try { List <Contract> contractsToProcess = new List <Contract>(); int delay = 0; Dispatcher.Invoke(() => { contractsToProcess = ContractsForIbFundamentalsQueries(); ContractList = new List <Contract>(contractsToProcess); ContractsProcessed = new List <Contract>(); delay = Convert.ToInt32(Configuration.Instance["DelayFundamentals"]); }); foreach (var contract in contractsToProcess) { CurrentContract = contract; IbClient.Instance.RequestFundamentals(contract); Thread.Sleep(delay); } } catch (Exception exception) { Dispatcher.Invoke(() => { LogCurrent.Add(exception.ToString()); }); } }); if (ConnectedToIb) { LogCurrent.Add($"OK! Import completed."); IbClient.Instance.Disonnect(); UpdateDbState(); InventoryText = GenerateInventoryText(); UpdateCompaniesForFundamenatals(SelectTop1000); } else { LogCurrent.Add($"ERROR! Error while connection to IB server."); } }