コード例 #1
0
        public void LoadManualPledgeViewData(object o)
        {
            //LoadAnim();
            RealTimePos.Clear();

            Task.Factory.StartNew(() =>
            {
                DDA.Load(RealTimePos, "0269");
            });
        }
コード例 #2
0
        private void PledgeItemsOnGrid()
        {
            try
            {
                DDA.Load(RealTimePos, "0269");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Pledge aborted: " + ex.InnerException.Message);
                return;
            }


            List <OCCStockPledge> StocksToPledge = new List <OCCStockPledge>();

            List <CSVDragObject> cs = dg1.ItemsSource as List <CSVDragObject>;

            if (DoesGridHaveErrors(cs))
            {
                return;
            }

            List <CSVDragObject> csrejects = new List <CSVDragObject>();

            foreach (CSVDragObject csitem in cs)
            {
                var r = RealTimePos.Find(x => x.cusip.ToUpper() == csitem.CUSIP.ToUpper());
                if (r != null)
                {
                    //testing alandias 20140617
                    if (r.Ticker == null)
                    {
                        csrejects.Add(csitem);
                    }
                    int qty = int.Parse(csitem.Qty);
                    StocksToPledge.Add(new OCCStockPledge(r, qty));
                }



                else
                {
                    csrejects.Add(csitem);
                }
            }

            string csrejects_string = string.Join("\n", csrejects.Select(x => x.CUSIP).ToArray());

            if (csrejects.Count > 0)
            {
                MessageBoxResult mbr_csrejects = MessageBox.Show("These items won't be pledged because we can't find the price for this CUSIP.  Pledge everything else? \n " + csrejects_string, "Confirm", MessageBoxButton.OKCancel);

                if (mbr_csrejects == MessageBoxResult.Cancel)
                {
                    return;
                }
            }


            new PledgeProcessor().PledgeListOfStocks(StocksToPledge, true, true);

            MessageBox.Show("Completed");
        }
コード例 #3
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();
        }