private void MarkRecall(RealTimePositionObject r, bool firstLoad)
        {
            if (firstLoad)
            {
                RecalledStockViewObject rs = new RecalledStockViewObject();
                rs.Cusip = r.Cusip;

                if (RecalledStocks.ContainsKey(rs))
                {
                    r.OnRecall = "On Recall";
                }
                else
                {
                    r.OnRecall = "";
                }
            }

            else
            {
                bool ret = rsf.Exists(r.Cusip);

                if (ret)
                {
                    r.OnRecall = "On Recall";
                }

                else
                {
                    r.OnRecall = "";
                }
            }
        }
 public RealTimeOccPositionObject(RealTimePositionObject rtPos)
     : this()
 {
     DateOfData                 = rtPos.DateOfData;
     ParticipantId              = rtPos.ParticipantId;
     Ticker                     = rtPos.Ticker;
     Cusip                      = rtPos.Cusip;
     Company                    = rtPos.Company;
     BodShareQuantity           = rtPos.BodShareQuantity;
     LoanValue                  = rtPos.LoanValue;
     LastActivityDate           = rtPos.LastActivityDate;
     Price                      = rtPos.Price;
     HistoricalBorrowRate       = rtPos.HistoricalBorrowRate;
     HistoricalLoanRate         = rtPos.HistoricalLoanRate;
     DtcNpbActivityQuantity     = rtPos.DtcNpbActivityQuantity;
     DtcNpbActivityLoanValue    = rtPos.DtcNpbActivityLoanValue;
     DtcNonNpbActivityQuantity  = rtPos.DtcNonNpbActivityQuantity;
     DtcNonNpbActivityLoanValue = rtPos.DtcNonNpbActivityLoanValue;
     G1BodNpbQuantity           = rtPos.G1BodNpbQuantity;
     G1BodNpbLoanValue          = rtPos.G1BodNpbLoanValue;
     G1BodNonNpbQuantity        = rtPos.G1BodNonNpbQuantity;
     G1BodNonNpbLoanValue       = rtPos.G1BodNonNpbLoanValue;
     OnRecall                   = rtPos.OnRecall;
     Notes                      = rtPos.Notes;
 }
Пример #3
0
        private void bwt_DoWork(object sender, DoWorkEventArgs e)
        {
            IncomingDeliveryOrderObject d = (IncomingDeliveryOrderObject)e.Argument;

            new Thread((ThreadStart) delegate()
            {
                this.BeginInvoke((ThreadStart) delegate()
                {
                    try
                    {
                        RealTimePositionObject pos = calc.CalculatePosition(d);
                        UpdatePositions(pos);

                        //if they are looking at the held up returns, update those positions
                        if (rbHeldUp.Checked)
                        {
                            LoadHeldUp();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex, TraceEnum.LoggedError);
                    }
                });
            }).Start();
        }
Пример #4
0
        public UpdateForm(RealTimePositionObject p, string mode)
        {
            InitializeComponent();

            rt = p;

            txtCusip.Text       = p.Cusip;
            txtTicker.Text      = p.Ticker;
            txtDescription.Text = p.Company;
            txtPrice.Text       = p.Price.ToString();

            Mode = mode;

            if (mode == "Price")
            {
                txtCusip.Enabled       = false;
                txtTicker.Enabled      = false;
                txtDescription.Enabled = false;

                txtPrice.Focus();
            }
            else if (mode == "Ticker")
            {
                txtCusip.Enabled = false;
                txtPrice.Enabled = false;

                txtTicker.Focus();
            }
        }
        private void UpdatePositions(RealTimePositionObject pos)
        {
            try
            {
                if (pos != null)
                {
                    //find the position
                    int i = AllRealTimePositions.Find("Cusip", pos.Cusip);

                    if (i != -1)
                    {
                        //position already exists, remove it and add new one
                        pos.Notes = AllRealTimePositions[i].Notes;

                        AllRealTimePositions.RemoveAt(i);
                        RealTimeOccPositionObject r = new RealTimeOccPositionObject(pos);
                        AllRealTimePositions.Add(r);
                    }
                    else
                    {
                        //new position. add it
                        RealTimeOccPositionObject r = new RealTimeOccPositionObject(pos);
                        AllRealTimePositions.Add(r);
                    }
                    AllRealTimePositions.Sort("SortField", ListSortDirection.Descending);
                    ColorRows();

                    dgvRealTimePosition.Refresh();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #6
0
        private void btnPledge_Click(object sender, EventArgs e)
        {
            List <RealTimePositionObject> RTObjToPledge = new List <RealTimePositionObject>();

            foreach (DataGridViewRow d in dgvRealTimePosition.SelectedRows)
            {
                RealTimePositionObject r = d.DataBoundItem as RealTimePositionObject;
                if (r != null)
                {
                    RTObjToPledge.Add(r);
                }
            }
        }
Пример #7
0
        private void investigateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                RealTimePositionObject rt = (RealTimePositionObject)dgvRealTimePosition.CurrentRow.DataBoundItem;

                InvestigateForm i = new InvestigateForm(rt);
                i.ShowDialog();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
            }
        }
Пример #8
0
        private void updateTickerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                RealTimePositionObject rt = (RealTimePositionObject)dgvRealTimePosition.CurrentRow.DataBoundItem;

                UpdateForm uf = new UpdateForm(rt, "Ticker");
                uf.ShowDialog();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
            }
        }
Пример #9
0
        private void ColorRows()
        {
            try
            {
                foreach (DataGridViewRow row in dgvRealTimePosition.Rows)
                {
                    RealTimePositionObject r = (RealTimePositionObject)row.DataBoundItem;

                    if (r.Cusip == selectedCusip)
                    {
                        row.DefaultCellStyle.BackColor = selectedColor;
                    }

                    else
                    {
                        if (r.OnRecall == "On Recall")
                        {
                            row.DefaultCellStyle.BackColor = txtOnRecall.BackColor;
                        }

                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }


                        if (r.Price == 0)
                        {
                            row.Cells["Exposure"].Style.BackColor = txtMissingPrice.BackColor;
                        }

                        else if (r.NumBorrows == 0)
                        {
                            row.Cells["Exposure"].Style.BackColor = txtMissingBorrows.BackColor;
                        }

                        else
                        {
                            row.Cells["Exposure"].Style.BackColor = row.Cells["RealTimePosition"].Style.BackColor;
                        }
                    }
                }
//                dgvRealTimePosition.Refresh();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
            }
        }
        public InvestigateForm(RealTimePositionObject rt)
        {
            InitializeComponent();

            rtPos = rt;

            position.Add(rtPos);

            dgvActivity.DataSource = rtPos.DtcActivity;
            dgvPosition.DataSource = position;

            helper.Add(new DgvHelper(dgvActivity, this.Name, true));
            helper.Add(new DgvHelper(dgvPosition, this.Name, true));

            helper.handleCellSelected += new CellSelectEventHandler(h_handleCellSelected);
        }
        private void UpdateStockPrice(RealTimePositionObject r)
        {
            if (StockPrices.ContainsKey(r.Cusip))
            {
                StockPriceViewObject s = null;
                StockPrices.TryGetValue(r.Cusip, out s);

                if (s != null)
                {
                    r.Price = (double)s.StockloanPrice;
                }
                else
                {
                    r.Price = 0;
                }
            }
        }
        private void UpdateStockInfo(RealTimePositionObject r)
        {
            if (Stocks.ContainsKey(r.Cusip))
            {
                StockViewObject s = null;
                Stocks.TryGetValue(r.Cusip, out s);

                if (s != null)
                {
                    r.Ticker  = s.Ticker;
                    r.Company = s.Name;
                }
                else
                {
                    r.Ticker = "zzzzUNKNOWN";
                }
            }
        }
        private void updateTickerToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            try
            {
                ProjectedNeedsSummaryObject ps = (ProjectedNeedsSummaryObject)dgvRealTimePosition.CurrentRow.DataBoundItem;

                RealTimePositionObject rt = new RealTimePositionObject();
                rt.Cusip   = ps.Cusip;
                rt.Ticker  = ps.Ticker;
                rt.Company = "";
                rt.Price   = 0;

                UpdateForm uf = new UpdateForm(rt, "Ticker");
                uf.ShowDialog();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
            }
        }
Пример #14
0
        private void dgvRealTimePosition_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex != -1)
                {
                    RealTimePositionObject d = (RealTimePositionObject)dgvRealTimePosition.Rows[e.RowIndex].DataBoundItem;
                    DtcChannel.Instance.CusipSelected(d.Cusip);

                    selectedCusip = d.Cusip;

                    //color rows
                    ColorRows();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
Пример #15
0
        void DtcMessageReceived(object sender, IncomingDtcMessageEventArgs e)
        {
            IncomingDeliveryOrderObject d;

            if (e.DtcMessage is IncomingDeliveryOrderObject)
            {
                d = (IncomingDeliveryOrderObject)e.DtcMessage;
            }
            else
            {
                return;
            }

            //bwt.RunWorkerAsync(d);


            new Thread((ThreadStart) delegate()
            {
                this.BeginInvoke((ThreadStart) delegate()
                {
                    try
                    {
                        RealTimePositionObject pos = calc.CalculatePosition(d);
                        UpdatePositions(pos);

                        //if they are looking at the held up returns, update those positions
                        if (rbHeldUp.Checked)
                        {
                            LoadHeldUp();
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex, TraceEnum.LoggedError);
                    }
                });
            }).Start();
        }
Пример #16
0
 public PositionUpdateEventArgs(RealTimePositionObject pos)
 {
     Position = pos;
 }
        private void UpdateOccInfo(RealTimePositionObject r)
        {
            r.ContainsHedge       = false;
            r.OccBodQuantity      = 0;
            r.OccQuantityLoaned   = 0;
            r.OccQuantityReturned = 0;
            r.OccQuantityBorrowed = 0;
            r.OccQuantityReceived = 0;

            //look up bod positions
            List <PositionObject> pos = OccBodPositions.FindAll(p => p.Cusip == r.Cusip);

            //calculate bod position
            foreach (PositionObject p in pos)
            {
                r.ContainsHedge = true;

                if (p.BorrowLoan == "B")
                {
                    r.OccBodQuantity += p.Quantity;
                }
                else if (p.BorrowLoan == "L")
                {
                    r.OccBodQuantity -= p.Quantity;
                }
            }

            //calculate occ info
            foreach (IncomingDeliveryOrderObject d in r.DtcActivity)
            {
                DeliveryOrderReasonCodeObject drc = null;

                DeliveryOrderLookups.ReasonCodes.TryGetValue(d.ReasonCode, out drc);

                //could not find reason code
                if (drc == null)
                {
                    //Trace.WriteLine("Could not find the reason code: " + d.ReasonCode, TraceEnum.LoggedError);
                }

                else
                {
                    //delivery
                    if (d.ActivityCode == "026" && IsHedge(d.ReasonCode))
                    {
                        if (drc.NewBorrowLoan)
                        {
                            //this is a new loan
                            r.OccQuantityLoaned += d.ShareQuantity.Value;
                        }
                        else
                        {
                            //this was a return
                            r.OccQuantityReturned += d.ShareQuantity.Value;
                        }
                        r.ContainsHedge = true;
                    }

                    //receive
                    else if (d.ActivityCode == "027" && IsHedge(d.ReasonCode))
                    {
                        if (drc.NewBorrowLoan)
                        {
                            r.OccQuantityBorrowed += d.ShareQuantity.Value;
                        }
                        else
                        {
                            r.OccQuantityReceived += d.ShareQuantity.Value;
                        }
                        r.ContainsHedge = true;
                    }

                    //could not find activity code
                    else
                    {
                    }
                }
            }
        }
        private void UpdateDtcInfo(RealTimePositionObject r)
        {
            r.DtcQuantityLoaned   = 0;
            r.DtcQuantityReturned = 0;
            r.DtcQuantityBorrowed = 0;
            r.DtcQuantityReceived = 0;

            foreach (IncomingDeliveryOrderObject d in r.DtcActivity)
            {
                DeliveryOrderReasonCodeObject drc = null;

                DeliveryOrderLookups.ReasonCodes.TryGetValue(d.ReasonCode, out drc);

                //could not find reason code
                if (drc == null)
                {
                    //Trace.WriteLine("Could not find the reason code: " + d.ReasonCode, TraceEnum.LoggedError);
                }

                else
                {
                    if ((d.Receiver != Settings.Account.Padded() && d.DelivererReceiverIndicator == "R") || (d.Deliverer != Settings.Account.Padded() && d.DelivererReceiverIndicator == "D"))
                    {
                    }
                    //delivery
                    if (d.ActivityCode == "026")
                    {
                        if (drc.NewBorrowLoan)
                        {
                            //this is a new loan
                            r.DtcQuantityLoaned += d.ShareQuantity.Value;
                        }
                        else
                        {
                            //this was a return
                            r.DtcQuantityReturned += d.ShareQuantity.Value;
                        }
                    }

                    //receive
                    else if (d.ActivityCode == "027")
                    {
                        if (drc.NewBorrowLoan)
                        {
                            r.DtcQuantityBorrowed += d.ShareQuantity.Value;
                        }
                        else
                        {
                            r.DtcQuantityReceived += d.ShareQuantity.Value;
                        }
                    }

                    //could not find activity code
                    else
                    {
                        //WE HAVE A PROBLEM
                        //Trace.WriteLine("Could not find the activity code: " + d.ActivityCode, TraceEnum.LoggedError);
                    }
                }
            }
        }
 private void UpdateConduitInfo(RealTimePositionObject r)
 {
     avf.GetConduitQuantities(r);
 }
        //TODO: Get a better name for this
        private void GetExtraData(RealTimePositionObject rtPos, bool firstLoad)
        {
            Dictionary <string, int> tradeCats = new Dictionary <string, int>();

            DateTime lastBDate = DateTime.MinValue;
            DateTime lastLDate = DateTime.MinValue;

            //Rates
            double bRate     = 0;
            double lRate     = 0;
            double bLastRate = 0;
            double lLastRate = 0;


            //Loan Values
            double bValue = 0;
            double lValue = 0;

            //ShareQty
            int bQty     = 1;
            int lQty     = 1;
            int bLastQty = 1;
            int lLastQty = 1;

            //Number of Deals
            int bCount = 0;
            int lCount = 0;

            List <StartingPositionObject> found = new List <StartingPositionObject>();

            //            List<G1PositionObject> found = G1NonNpbPositions.FindAll(delegate(G1PositionObject p)
            //            { return p.Cusip.ToUpper() == rtPos.Cusip.ToUpper(); });

            if (G1NonNpbPositions.ContainsKey(rtPos.Cusip.ToUpper()))
            {
                found = G1NonNpbPositions[rtPos.Cusip.ToUpper()];
            }

            if (found.Count > 0)
            {
                foreach (StartingPositionObject g in found)
                {
                    //get all the data you need
                    if (!tradeCats.ContainsKey(g.TradeCategory) && (rtPos.TradeCategory == null || !rtPos.TradeCategory.Contains(g.TradeCategory)))
                    {
                        tradeCats.Add(g.TradeCategory, 0);
                    }

                    if (g.BorrowLoanIndicator == "B")
                    {
                        bRate  += (double)g.Rate * (int)Math.Abs(g.Quantity.Value);
                        bQty   += (int)Math.Abs(g.Quantity.Value);
                        bValue += (double)Math.Abs(g.LoanValue.Value);
                        bCount++;
                        rtPos.NumBorrows++;

                        if (g.TradeDate.Value.Date >= lastBDate.Date && (int)Math.Abs(g.Quantity.Value) > 0)
                        {
                            if (g.TradeDate.Value.Date > lastBDate.Date)
                            {
                                bLastRate = 0;
                                bLastQty  = 1;
                            }

                            bLastRate += (double)g.Rate * (int)Math.Abs(g.Quantity.Value);
                            bLastQty  += (int)Math.Abs(g.Quantity.Value);
                            lastBDate  = g.TradeDate.Value;
                        }
                    }
                    else
                    {
                        lRate  += (double)g.Rate * (int)Math.Abs(g.Quantity.Value);
                        lQty   += (int)Math.Abs(g.Quantity.Value);
                        lValue += (double)Math.Abs(g.LoanValue.Value);
                        lCount++;

                        try
                        {
                            if (g.TradeDate.Value.Date >= lastLDate.Date && (int)Math.Abs(g.Quantity.Value) > 0)
                            {
                                if (g.TradeDate.Value.Date > lastLDate.Date)
                                {
                                    lLastRate = 0;
                                    lLastQty  = 1;
                                }

                                lLastRate += (double)g.Rate * (int)Math.Abs(g.Quantity.Value);
                                lLastQty  += (int)Math.Abs(g.Quantity.Value);
                                lastLDate  = g.TradeDate.Value;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw;
                        }
                    }
                }

                //figure out the trade category
                foreach (string s in tradeCats.Keys)
                {
                    rtPos.TradeCategory += s + " ";
                }

                rtPos.TradeCategory.Trim();

                try
                {
                    rtPos.HistoricalBorrowRate = bRate / bQty;
                    rtPos.HistoricalLoanRate   = lRate / lQty;

                    rtPos.BorrowRate = bLastRate / bLastQty;
                    rtPos.LoanRate   = lLastRate / lLastQty;
                }
                catch (Exception ex)
                {
                    //Trace.WriteLine(ex, TraceEnum.LoggedError);
                }
            }

            MarkRecall(rtPos, firstLoad);
            UpdateStockInfo(rtPos);
            UpdateStockPrice(rtPos);
            //UpdateConduitInfo(rtPos);
            UpdateDtcInfo(rtPos);
            UpdateOccInfo(rtPos);
        }
        //calculates Position based on start up data
        private void CalculatePosition()
        {
            RealTimePositions.Clear();

            //Build a position from todays activity
            foreach (IncomingDeliveryOrderObject d in DtcActivity)
            {
                RealTimePositionObject found = null;

                RealTimePositions.TryGetValue(d.Cusip, out found);


                //first activity for this cusip
                if (found == null)
                {
                    RealTimePositionObject newPosition = new RealTimePositionObject(d.DateAndTimeStamp.Value.Date, Settings.Account.ToInt(),
                                                                                    "", d.Cusip, d.CusipDescription, 0,
                                                                                    0, d.DateAndTimeStamp.Value,
                                                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "");

                    //DtcActivity has all NPB ripped out
                    newPosition.DtcNonNpbActivityQuantity  = d.ShareQuantity_Signed.Value;
                    newPosition.DtcNonNpbActivityLoanValue = d.MoneyValue_Signed.Value;
                    newPosition.Ticker = d.CusipDescription;
                    newPosition.DtcActivity.Add(d);

                    newPosition.LastActivityDate = d.DateAndTimeStamp.Value;

                    RealTimePositions.Add(newPosition.Cusip, newPosition);
                }
                //already got some activity for this cusip
                else
                {
                    found.DtcNonNpbActivityQuantity  += d.ShareQuantity_Signed.Value;
                    found.DtcNonNpbActivityLoanValue += d.MoneyValue_Signed.Value;
                    found.DtcActivity.Add(d);

                    if (d.DateAndTimeStamp > found.LastActivityDate)
                    {
                        found.LastActivityDate = d.DateAndTimeStamp.Value;
                    }
                }
            }

            //now add the morning position to the list
            foreach (DtcPositionViewObject pos in DtcBodPositions.Values)
            {
                RealTimePositionObject found = null;

                RealTimePositions.TryGetValue(pos.CUSIP, out found);

                //this cusip had no activity today
                if (found == null)
                {
                    RealTimePositions.Add(pos.CUSIP, new RealTimePositionObject(pos));
                }
                //already got some activity for this cusip, update its bod quantity
                else
                {
                    found.BodShareQuantity = pos.ShareQuantity;
                }
            }


            //now subtract NPB from DTC
            foreach (StartingPositionObject pos in G1NpbPositions)
            {
                RealTimePositionObject found = null;

                RealTimePositions.TryGetValue(pos.Cusip, out found);

                if (found != null)
                {
                    found.G1BodNpbQuantity  = (int)pos.Quantity.Value;
                    found.G1BodNpbLoanValue = pos.LoanValue.Value;
                }
            }

            /*
             * //sum up the npb data from todays DTC activity
             * foreach (IncomingDeliveryOrderObject npb in DtcNpbActivity)
             * {
             *  RealTimePositionObject found = RealTimePositions.Find(delegate(RealTimePositionObject p)
             *  { return p.Cusip == npb.Cusip; });
             *
             *  if (found != null)
             *  {
             *      found.DtcNpbActivityQuantity += (int)npb.ShareQuantity_Signed.Value;
             *      found.DtcNpbActivityLoanValue += npb.MoneyValue_Signed.Value;
             *  }
             * }
             */

            //Get extra data
            foreach (RealTimePositionObject rtPos in RealTimePositions.Values)
            {
                GetExtraData(rtPos, true);
            }

            UpdateConduitInfo(RealTimePositions.Values.ToList());


            // JP 10/16/12: add pending position with 0 qty
            // pending
            foreach (IncomingDeliveryOrderObject d in DtcPendingActivity)
            {
                if (!RealTimePositions.ContainsKey(d.Cusip))
                {
                    // no position for this cusip, but there is pending activity so add a 0 position entry
                    RealTimePositionObject newPosition = new RealTimePositionObject(d.DateAndTimeStamp.Value.Date, Settings.Account.ToInt(),
                                                                                    "", d.Cusip, d.CusipDescription, 0,
                                                                                    0, d.DateAndTimeStamp.Value,
                                                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "");

                    //DtcActivity has all NPB ripped out
                    newPosition.DtcNonNpbActivityQuantity  = 0; //d.ShareQuantity_Signed.Value;
                    newPosition.DtcNonNpbActivityLoanValue = 0; //d.MoneyValue_Signed.Value;
                    newPosition.Ticker = d.CusipDescription;
                    newPosition.DtcActivity.Add(d);

                    newPosition.LastActivityDate = d.DateAndTimeStamp.Value;

                    RealTimePositions.Add(newPosition.Cusip, newPosition);
                }
            }
        }
 private void UpdatePositions(RealTimePositionObject pos)
 {
 }
        //when a new order comes in, recalculate your Positions. There is no need
        //to reload g1 data or anything like that.
        public RealTimePositionObject CalculatePosition(IncomingDeliveryOrderObject d)
        {
            RealTimePositionObject pos = null;

            if (d.Id > MaxDtcId)
            {
                MaxDtcId = d.Id;
            }

            //we only care about real msgs now.
            if (d.DtcStatusIndicator == " " || d.DtcStatusIndicator == "X")
            {
                //Non 5239 activity
                if (d.Receiver != Settings.Account.Padded() && d.Deliverer != Settings.Account.Padded())
                {
                    return(null);
                }

                //Remove records with an actioncode of 0
                if (d.ActionCode == "0")
                {
                    return(null);
                }

                //Records that are receives but 5239 is not the receiver, same for deliver
                if ((d.Receiver != Settings.Account.Padded() && d.DelivererReceiverIndicator == "R") ||
                    (d.Deliverer != Settings.Account.Padded() && d.DelivererReceiverIndicator == "D"))
                {
                    return(null);
                }

                /* Dont care about NPB anymore
                 * //Remove the NPB activity
                 * if (d.Deliverer == "00000238" && d.Receiver == "00005239" && d.ReasonCode == "010")
                 *  return null;
                 *
                 * if (d.Deliverer == "00005239" && d.Receiver == "00000238" && d.ReasonCode == "020")
                 *  return null;
                 */

                //check to see if we already have activity for this cusip
                RealTimePositions.TryGetValue(d.Cusip, out pos);

                //first activity for this cusip
                if (pos == null)
                {
                    pos = new RealTimePositionObject(d.DateAndTimeStamp.Value.Date, Settings.Account.ToInt(),
                                                     "", d.Cusip, d.CusipDescription, 0, 0,
                                                     d.DateAndTimeStamp.Value,
                                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "");

                    //DtcActivity has all NPB ripped out
                    pos.DtcNonNpbActivityQuantity  = d.ShareQuantity_Signed.Value;
                    pos.DtcNonNpbActivityLoanValue = d.MoneyValue_Signed.Value;
                    pos.Ticker = d.CusipDescription;
                    pos.DtcActivity.Add(d);

                    pos.LastActivityDate = d.DateAndTimeStamp.Value;

                    //Add activity to dtcactivity so you do now apply it twice
                    DtcActivity.Add(d);

                    RealTimePositions.Add(pos.Cusip, pos);
                }
                //already got some activity for this cusip
                else
                {
                    pos.DtcNonNpbActivityQuantity  += d.ShareQuantity_Signed.Value;
                    pos.DtcNonNpbActivityLoanValue += d.MoneyValue_Signed.Value;
                    pos.DtcActivity.Add(d);

                    if (d.DateAndTimeStamp > pos.LastActivityDate)
                    {
                        pos.LastActivityDate = d.DateAndTimeStamp.Value;
                    }

                    //Add activity to dtcactivity so you do not apply it twice
                    DtcActivity.Add(d);
                }
                GetExtraData(pos, false);
            }
            else
            {
                // JP 10/16/12

                if (!RealTimePositions.ContainsKey(d.Cusip))
                {
                    // no position for this cusip, but there is pending activity so add a 0 position entry
                    RealTimePositionObject newPosition = new RealTimePositionObject(d.DateAndTimeStamp.Value.Date, Settings.Account.ToInt(),
                                                                                    "", d.Cusip, d.CusipDescription, 0,
                                                                                    0, d.DateAndTimeStamp.Value,
                                                                                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "");

                    //DtcActivity has all NPB ripped out
                    newPosition.DtcNonNpbActivityQuantity  = 0; //d.ShareQuantity_Signed.Value;
                    newPosition.DtcNonNpbActivityLoanValue = 0; //d.MoneyValue_Signed.Value;
                    newPosition.Ticker = d.CusipDescription;
                    newPosition.DtcActivity.Add(d);

                    newPosition.LastActivityDate = d.DateAndTimeStamp.Value;

                    RealTimePositions.Add(newPosition.Cusip, newPosition);
                }
            }

            return(pos);
        }
Пример #24
0
 public void PositionUpdated(RealTimePositionObject pos)
 {
     OnPositionUpdated(new PositionUpdateEventArgs(pos));
 }