Exemple #1
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                SecuritiesDIM security = _priceService.GetSecurityInfo(_sysSecurityPricesVM.SelectedSecurity.Symbol, _sysSecurityPricesVM.SelectedSecurity.AssetClass.Name);
                var           results  = await _priceService.AddDailyPrices(security);

                if (results > 0)
                {
                    MessageBox.Show($"{results} prices have been saved for {_sysSecurityPricesVM.SelectedSecurity.SecurityName}", "Information");
                    await _sysSecurityPricesVM.Load();
                }
                else
                {
                    MessageBox.Show($"No new prices found for {_sysSecurityPricesVM.SelectedSecurity.SecurityName}", "Information");
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Your API Key might not be valid. Please investigate", "Error");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                Dictionary <DateTime, SecurityPriceStore> dbPrices = _priceService.GetSecurityPrices(_sysSecurityPricesVM.SelectedSecurity.Symbol, _sysSecurityPricesVM.SelectedSecurity.AssetClass.Name)
                                                                     .ToDictionary(g => g.Date);
                int secId = _sysSecurityPricesVM.SelectedSecurity.SecurityId;
                List <SecurityPriceStore> pricesToUpdate = new List <SecurityPriceStore>();
                List <SecurityPriceStore> newPrices      = new List <SecurityPriceStore>();
                foreach (PriceContainer priceContainer in _sysSecurityPricesVM.dgSecurityPrices)
                {
                    if (dbPrices.ContainsKey(priceContainer.Date))
                    {
                        if (dbPrices[priceContainer.Date].ClosePrice != priceContainer.ClosePrice)
                        {
                            dbPrices[priceContainer.Date].ClosePrice  = priceContainer.ClosePrice;
                            dbPrices[priceContainer.Date].PriceSource = "Manual";
                            pricesToUpdate.Add(dbPrices[priceContainer.Date]);
                        }
                    }
                    else
                    {
                        SecurityPriceStore newManualPrice = new SecurityPriceStore
                        {
                            Date        = priceContainer.Date,
                            ClosePrice  = priceContainer.ClosePrice,
                            PriceSource = "Manual",
                            SecurityId  = secId
                        };
                        newPrices.Add(newManualPrice);
                    }
                }
                await _priceService.AddManualPrices(newPrices);

                await _priceService.UpdateManualPrices(pricesToUpdate);

                MessageBox.Show($"{newPrices.Count} prices inserted.\n{pricesToUpdate.Count} prices updated.", "Information");
                await _sysSecurityPricesVM.Load();
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }