Example #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            /*
             * //subscribe to the types you are interested in
             * DtcChannel.User.Subscriptions.Add(new SubscriptionType(DtcMessageDirectionEnum.FromDtc, DtcMessageSideEnum.Deliverer, DtcMessageTypeEnum.DeliveryOrder), 0);
             * DtcChannel.User.Subscriptions.Add(new SubscriptionType(DtcMessageDirectionEnum.FromDtc, DtcMessageSideEnum.Receiver, DtcMessageTypeEnum.DeliveryOrder), 0);
             *
             *
             * //subscribe to the feed
             * DtcChannel.Instance.JoinFeed(calc.DtcActivity[calc.DtcActivity.Count - 1].Id);
             */


            IncomingDeliveryOrderObject d = new IncomingDeliveryOrderObject();

            d.Id = 147293;
            d.DateAndTimeStamp = DateTime.Parse("5/29/2008 13:03");
            d.Cusip            = "05545E209";

            d.DtcStatusIndicator = " ";

            d.Receiver  = "00005239";
            d.Deliverer = "00000773";
            d.DelivererReceiverIndicator = "R";

            d.ActionCode   = "1";
            d.ActivityCode = "027";
            d.ReasonCode   = "020";

            d.MoneyValue    = 200;
            d.ShareQuantity = 100;

            DtcChannel.Instance.DtcMessageReceived(d);
        }
Example #2
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();
        }
Example #3
0
        private void RemoveCorrespondingPendingIfIncomingOrderIsAMadeAterPending(IncomingDeliveryOrderObject d)
        {
            if (cbPendingFilter.Checked)
            {
                DisplayWOUnecessaryPendings.Add(d);

                if (d.Status == DtcMessageStatusEnum.MadeAfterPend)
                {
                    var Pendings = DisplayWOUnecessaryPendings.Where(x => x.Status == DtcMessageStatusEnum.Pending).ToList();

                    foreach (var P in Pendings)
                    {
                        if (P.Cusip == d.Cusip && P.CounterParty == d.CounterParty && P.ShareQuantity == d.ShareQuantity && P.DelivererAccountNum == d.DelivererAccountNum)
                        {
                            DisplayWOUnecessaryPendings.Remove(P);
                            break;
                        }
                    }
                }
            }
        }
Example #4
0
 public PositionSummaryObject(IncomingDeliveryOrderObject d)
 {
     /*
      * Cusip = p.Cusip;
      * Symbol = p.Symbol;
      * ClearingNo = p.ClearingNo;
      *
      * if (p.BorrowLoan == "B")
      * {
      *  StartingBorrowQty = p.Quantity.Value;
      *  StartingBorrowValue = p.ContractValue.Value;
      * }
      *
      * if (p.BorrowLoan == "L")
      * {
      *  StartingLoanQty = p.Quantity.Value;
      *  StartingLoanValue = p.ContractValue.Value;
      * }
      * LoanQty = 0;
      * BorrowQty = 0;
      */
 }
        private void ProcessOrders(IncomingDeliveryOrderObject d)
        {
            try
            {
                /*
                 * if (calc.StockPrices.ContainsKey(d.Cusip))
                 * {
                 *  StockPriceViewObject s = null;
                 *  calc.StockPrices.TryGetValue(d.Cusip, out s);
                 *
                 *  if (s != null)
                 *  {
                 *      d.Price = (double)s.Price;
                 *  }
                 *
                 * }
                 */
                if ((d.DtcStatusIndicator == " " || d.DtcStatusIndicator == "X") &&
                    (d.ReasonCode == "260" || d.ReasonCode == "261" || d.ReasonCode == "270" || d.ReasonCode == "271")
                    )
                {
                    if (d.MessageSide == DtcMessageSideEnum.Receiver)
                    {
                        IncomingOrders.Add(d);
                    }

                    if (d.MessageSide == DtcMessageSideEnum.Deliverer)
                    {
                        OutgoingOrders.Add(d);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #6
0
        private void ColorRows()
        {
            foreach (DataGridViewRow row in dgvDeliveryOrders.Rows)
            {
                IncomingDeliveryOrderObject i = (IncomingDeliveryOrderObject)row.DataBoundItem;

                if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Borrow)
                {
                    if (i.Status == DtcMessageStatusEnum.Made || i.Status == DtcMessageStatusEnum.MadeAfterPend)
                    {
                        row.DefaultCellStyle.BackColor = txtMadeBorrow.BackColor;
                    }

                    else if (i.Status == DtcMessageStatusEnum.Pending)
                    {
                        row.DefaultCellStyle.BackColor = txtPendingBorrow.BackColor;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                    }
                }
                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.BorrowReclaimed)
                {
                    row.DefaultCellStyle.BackColor = txtReclaimedBorrows.BackColor;
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Loan)
                {
                    if (i.Status == DtcMessageStatusEnum.Made || i.Status == DtcMessageStatusEnum.MadeAfterPend)
                    {
                        row.DefaultCellStyle.BackColor = txtMadeLoan.BackColor;
                    }

                    else if (i.Status == DtcMessageStatusEnum.Pending)
                    {
                        row.DefaultCellStyle.BackColor = txtPendingLoan.BackColor;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                    }
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.LoanReclaimed)
                {
                    row.DefaultCellStyle.BackColor = txtReclaimedLoans.BackColor;
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.ReturnIn)
                {
                    if (i.Status == DtcMessageStatusEnum.Made || i.Status == DtcMessageStatusEnum.MadeAfterPend)
                    {
                        row.DefaultCellStyle.BackColor = txtMadeRetunIn.BackColor;
                    }

                    else if (i.Status == DtcMessageStatusEnum.Pending)
                    {
                        row.DefaultCellStyle.BackColor = txtPendingReturnIn.BackColor;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                    }
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.ReturnInReclaimed)
                {
                    row.DefaultCellStyle.BackColor = txtReclaimedReturnsIn.BackColor;
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.ReturnOut)
                {
                    if (i.Status == DtcMessageStatusEnum.Made || i.Status == DtcMessageStatusEnum.MadeAfterPend)
                    {
                        row.DefaultCellStyle.BackColor = txtMadeReturnOut.BackColor;
                    }

                    else if (i.Status == DtcMessageStatusEnum.Pending)
                    {
                        row.DefaultCellStyle.BackColor = txtPendingReturnOut.BackColor;
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.Red;
                    }
                }

                else if (i.DeliveryOrderDirection == DeliveryOrderDirectionEnum.ReturnOutReclaimed)
                {
                    row.DefaultCellStyle.BackColor = txtReclaimedReturnsOut.BackColor;
                }

                else
                {
                    row.DefaultCellStyle.BackColor = Color.Red;
                }
            }
        }
        //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);
        }
Example #8
0
        private void CalcSummary(IncomingDeliveryOrderObject ido, string account, SortableBindingList <PositionSummaryObject> pos)
        {
            //new loan
            if (ido.ReasonCode == "260")
            {
                //we borrowed stock
                if (ido.Receiver == account)
                {
                    //check to see if we have a position
                    int i = pos.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].BorrowQty   += ido.ShareQuantity.Value;
                        pos[i].BorrowValue += ido.MoneyValue.Value;
                    }
                    //TODO: WE DONT HAVE A POSITION SO ADD IT
                    else
                    {
                        //                        PositionSummaryObject p = new PositionSummaryObject();
                        //                        p.Cu
                        //                        p.BorrowQty = ido.ShareQuantity.Value;

                        pos.Add(new PositionSummaryObject(ido));
                    }
                }
                //we delivered stock
                if (ido.Deliverer == account)
                {
                    //check to see if we have a position
                    int i = pos.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].LoanQty   += ido.ShareQuantity.Value;
                        pos[i].LoanValue += ido.MoneyValue.Value;
                    }
                }
            }
            //loan reclaim
            if (ido.ReasonCode == "261")
            {
                if (ido.Receiver == account)
                {
                    //check to see if we have a position
                    int i = positions5239.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].LoanQty   -= ido.ShareQuantity.Value;
                        pos[i].LoanValue -= ido.MoneyValue.Value;
                    }
                }
                //we delivered stock
                if (ido.Deliverer == account)
                {
                    //check to see if we have a position
                    int i = positions5239.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].BorrowQty   -= ido.ShareQuantity.Value;
                        pos[i].BorrowValue -= ido.MoneyValue.Value;
                    }
                }
            }
            //new return
            if (ido.ReasonCode == "270")
            {
                if (ido.Receiver == account)
                {
                    //check to see if we have a position
                    int i = positions5239.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].LoanQty   += ido.ShareQuantity.Value;
                        pos[i].LoanValue += ido.MoneyValue.Value;
                    }
                }
                //we delivered stock
                if (ido.Deliverer == account)
                {
                    //check to see if we have a position
                    int i = pos.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].BorrowQty   += ido.ShareQuantity.Value;
                        pos[i].BorrowValue += ido.MoneyValue.Value;
                    }
                }
            }
            //new return dk
            if (ido.ReasonCode == "271")
            {
                //we borrowed stock
                if (ido.Receiver == account)
                {
                    //check to see if we have a position
                    int i = pos.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].BorrowQty   -= ido.ShareQuantity.Value;
                        pos[i].BorrowValue -= ido.MoneyValue.Value;
                    }
                }
                //we delivered stock
                if (ido.Deliverer == account)
                {
                    //check to see if we have a position
                    int i = pos.Find("Cusip", ido.Cusip);

                    if (i != -1)
                    {
                        pos[i].LoanQty   -= ido.ShareQuantity.Value;
                        pos[i].LoanValue -= ido.MoneyValue.Value;
                    }
                }
            }
        }
        private void ProcessOrders(IncomingDeliveryOrderObject d)
        {
            try
            {
                /*if (d.Cusip == "493267108")
                 * {
                 *  int c = 2;
                 * }*/


                this.Text = "Price Control - " + DateTime.Now.ToString();

                PriceControlDeliveryOrder d2 = new PriceControlDeliveryOrder(d);

                if (calc.StockPrices.ContainsKey(d2.Cusip))
                {
                    StockPriceViewObject s = null;
                    calc.StockPrices.TryGetValue(d2.Cusip, out s);

                    if (s != null)
                    {
                        d2.Price = (double)s.Price;
                    }
                }

                double priceDiff = Math.Abs(d.MoneyValue.Value - (d2.Price * d.ShareQuantity.Value));

                if ((d.DtcStatusIndicator == " " || d.DtcStatusIndicator == "X") &&
                    (d.OriginalInputSource != "CNS") &&
                    (d2.Price > 0) &&
                    ((d.MoneyValue / d.ShareQuantity) > d2.MaxPrice || (d.MoneyValue / d.ShareQuantity) < d2.MinPrice) &&
                    (d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Borrow || d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Loan ||
                     d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.BorrowReclaimed || d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.LoanReclaimed) &&
                    (d.Receiver == Settings.Account.Padded() || d.Deliverer == Settings.Account.Padded())
                    )
                {
                    d2.PriceDiff = priceDiff;
                    ProblemOrders.Add(d2);
                }

                if ((d.DtcStatusIndicator == " " || d.DtcStatusIndicator == "X") &&
                    (d.OriginalInputSource != "CNS") &&
                    (d2.Price > 0) &&
                    (d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Borrow || d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.Loan ||
                     d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.BorrowReclaimed || d.DeliveryOrderDirection == DeliveryOrderDirectionEnum.LoanReclaimed) &&
                    (d.Receiver == Settings.Account.Padded() || d.Deliverer == Settings.Account.Padded())
                    )
                {
                    if (!Orders.ContainsKey(d2.Cusip))
                    {
                        List <PriceControlDeliveryOrder> p = new List <PriceControlDeliveryOrder>();
                        p.Add(d2);
                        Orders.Add(d2.Cusip, p);
                    }
                    else
                    {
                        //check to see if an order for a different price had come in
                        List <PriceControlDeliveryOrder> p = Orders[d2.Cusip];

                        int i = p.Count(x =>
                                        (x.MoneyValue / x.ShareQuantity) != (d2.MoneyValue / d2.ShareQuantity) &&
                                        (x.Deliverer == d2.Deliverer || x.Deliverer == d2.Receiver));

                        if (i != 0)
                        {
                            DifferentPricedOrders.Add(d2);
                        }

                        //add to list of orders
                        Orders[d2.Cusip].Add(d2);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
            public PriceControlDeliveryOrder(IncomingDeliveryOrderObject i)
            {
                base.DateReceived               = i.DateReceived;
                base.ProcessDate                = i.ProcessDate;
                base.RawMessageId               = i.RawMessageId;
                base.QueueName                  = i.QueueName;
                base.OriginCode                 = i.OriginCode;
                base.Deliverer                  = i.Deliverer;
                base.CopyIndicator              = i.CopyIndicator;
                base.VersionControl             = i.VersionControl;
                base.Cusip                      = i.Cusip;
                base.CmoFactor                  = i.CmoFactor;
                base.ReasonForPendingIndicator  = i.ReasonForPendingIndicator;
                base.MdhTime_                   = i.MdhTime_;
                base.MdhTime                    = i.MdhTime;
                base.AccountType                = i.AccountType;
                base.ActionCode                 = i.ActionCode;
                base.ActivityCode               = i.ActivityCode;
                base.Receiver                   = i.Receiver;
                base.PendingTranIndicator       = i.PendingTranIndicator;
                base.ForeignSharesIndicator     = i.ForeignSharesIndicator;
                base.OriginalInputSource        = i.OriginalInputSource;
                base.MaturityDate               = i.MaturityDate;
                base.SubActivityCode            = i.SubActivityCode;
                base.MoneyValue_                = i.MoneyValue_;
                base.MoneyValue                 = i.MoneyValue;
                base.DelivererReceiverIndicator = i.DelivererReceiverIndicator;
                base.RadIndicator               = i.RadIndicator;
                base.JournalCode                = i.JournalCode;
                base.BatchVarCon                = i.BatchVarCon;
                base.DelivererAccountNum        = i.DelivererAccountNum;
                base.ReceiverAccountNum         = i.ReceiverAccountNum;
                base.SubordinateBankNum         = i.SubordinateBankNum;
                base.SettleDate_                = i.SettleDate_;
                base.SettleDate                 = i.SettleDate;
                base.ReasonCode                 = i.ReasonCode;
                base.ConditionalDoIdIndicator   = i.ConditionalDoIdIndicator;
                base.ThirdPartyIdentifier       = i.ThirdPartyIdentifier;
                base.DueBillIndicator           = i.DueBillIndicator;
                base.DtcStatusIndicator         = i.DtcStatusIndicator;
                base.DayNightIndicator          = i.DayNightIndicator;
                base.DateStamp                  = i.DateStamp;
                base.TimeStamp                  = i.TimeStamp;
                base.DateAndTimeStamp           = i.DateAndTimeStamp;
                base.CusipDescription           = i.CusipDescription;
                base.Comments                   = i.Comments;
                base.MuniBond                   = i.MuniBond;
                base.FastIndicator              = i.FastIndicator;
                base.SdfsIndicator              = i.SdfsIndicator;
                base.TransactionSequenceNum     = i.TransactionSequenceNum;
                base.CurrentRecordNum           = i.CurrentRecordNum;
                base.RependedIndicator          = i.RependedIndicator;
                base.ShareQuantity_             = i.ShareQuantity_;
                base.ShareQuantity              = i.ShareQuantity;
                base.PendDropReason             = i.PendDropReason;
                base.DropCode                   = i.DropCode;
                base.SubIssueType               = i.SubIssueType;
                base.CnsSubAccount              = i.CnsSubAccount;
                base.PendingPosition_           = i.PendingPosition_;
                base.PendingPosition            = i.PendingPosition;
                base.DatedDate                  = i.DatedDate;
                base.IpoCustomerAccount         = i.IpoCustomerAccount;
                base.IpoBank                    = i.IpoBank;
                base.IpoTradeDate               = i.IpoTradeDate;
                base.IpoBroker                  = i.IpoBroker;
                base.IpoCorrespondent           = i.IpoCorrespondent;
                base.IpoBuySell                 = i.IpoBuySell;
                base.Filler1                    = i.Filler1;
                base.DtcOriginalRecordNum       = i.DtcOriginalRecordNum;
                base.ReclaimDate                = i.ReclaimDate;
                base.DepositoryTransNum         = i.DepositoryTransNum;
                base.Filler2                    = i.Filler2;

                base.SetFields();
            }