Пример #1
0
 public void onAutoPledgeCalculated(AutoPledgeEventArgs e)
 {
     if (AutoPledgeCalculated != null)
     {
         AutoPledgeCalculated(this, e);
     }
 }
Пример #2
0
        private void Calculate()
        {
            double dblreq = 0;
            int    req    = 0;

            if (!double.TryParse(textBlockRequirement.Text, out dblreq))
            {
                MessageBox.Show("Requirement could not be understood as a number");
                return;
            }
            else
            {
                try
                {
                    req = Convert.ToInt32(dblreq);
                }
                catch (Exception e)
                {
                    MessageBox.Show("There was an issue converting the requirement to an integer");
                    throw;
                }
            }

            if (HCRVItem == null)
            {
                if (!string.IsNullOrEmpty(textBlockRequirement.Text))
                {
                    hedgecashrequirementView_AlanPledger HCItem = new hedgecashrequirementView_AlanPledger();
                    double dreq = 0;
                    if (double.TryParse(textBlockRequirement.Text, out dreq))
                    {
                        HCItem.Requirement = dreq;
                        //HCRDA.Update(HCItem);
                    }
                }
            }


            LoadAnim();

            BackgroundWorker BW = new BackgroundWorker();

            BW.DoWork += (s, e) =>
            {
                spAlanGetRealTimePositions_Pledger_ResultDA DDA = new spAlanGetRealTimePositions_Pledger_ResultDA();
                RealTimePos.Clear();
                DDA.Load(RealTimePos, "0269");

                //Check business rule...Todays net >=0 but we may not have any of that stock Used in getting pledgeable stock
                //var tst = RealTimePos.Where(x => x.TodaysNet > 0 && x.unpledgedquantity <= 0).ToList();

                stocksToUnpledge = CalculateWhatToUnpledge();

                //alandias testing
                //stocksToUnpledge = stocksToUnpledge.Where(x => x.SharesToUnpledge == 1).Take(1).ToList();


                stocksToPledge = CalculateWhatToPledge(stocksToUnpledge, req);

                //alandias testing
                //stocksToPledge = stocksToPledge.Where(x => x.QuantityToPledge == stocksToPledge.Min(y => y.QuantityToPledge)).ToList();
            };

            BW.RunWorkerCompleted += (s, e) =>
            {
                UnloadAnim();
                AutoPledgeEventArgs ae = new AutoPledgeEventArgs();

                ae.StockBalance = RealTimePos.Where(x => x.Price != null).Sum(x => x.pledgedquantity.Value * Convert.ToDouble(x.Price.Value) * StockBalanceFactor);
                ae.TotalPledged = RealTimePos.Where(x => x.Price != null).Sum(x => x.pledgedquantity * x.Price).Value;
                onAutoPledgeCalculated(ae);

                dgvStocksToUnpledge.ItemsSource = (from i in stocksToUnpledge select new DGStocksToUnpledge()
                {
                    CUSIP = i.RealTimePosition.cusip, SharesToUnpledge = i.SharesToUnpledge, TodaysNet = i.RealTimePosition.TodaysNet
                }).ToList();

                dgvStocksToPledge.ItemsSource = (from i in stocksToPledge select new DGStocksToPledge()
                {
                    cusip = i.RealTimePosition.cusip, QuantityToPledge = i.QuantityToPledge, Price = i.RealTimePosition.Price
                }).ToList();
            };

            BW.RunWorkerAsync();
        }