void Instance_handleStockPriceUpdated(object sender, StockPriceUpdateEventArgs e)
        {
            try
            {
                new Thread((ThreadStart) delegate()
                {
                    this.BeginInvoke((ThreadStart) delegate()
                    {
                        try
                        {
                            //find the stock price in the list
                            int i = AllRealTimePositions.Find("Cusip", e.StockPrice.Cusip);

                            if (i != -1)
                            {
                                //update the stock
                                AllRealTimePositions[i].Price = e.StockPrice.Price;
                            }

                            dgvRealTimePosition.Refresh();
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex, TraceEnum.LoggedError);
                        }
                    });
                }).Start();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, TraceEnum.LoggedError);
            }
        }
Esempio n. 2
0
        public void Find()
        {
            var coll = new SortableBindingList <KeyValuePair <int, string> > {
                new KeyValuePair <int, string>(1, "1"), new KeyValuePair <int, string>(2, "2")
            };

            coll.ApplySort(nameof(KeyValuePair <_, _> .Key), ListSortDirection.Ascending);

            Throws <ArgumentException>(() => coll.Find("X", null), "No property descriptor found for property name 'X' in type 'System.Collections.Generic.KeyValuePair`2[System.Int32,System.String]'.");
            Assert.IsTrue(coll.Find(nameof(KeyValuePair <_, _> .Key), 0) < 0);
            Assert.AreEqual(0, coll.Find(nameof(KeyValuePair <_, _> .Key), 1));

            coll.ApplySort(nameof(KeyValuePair <_, _> .Key), ListSortDirection.Descending);
            Assert.AreEqual(1, coll.Find(nameof(KeyValuePair <_, _> .Key), 1));
        }
Esempio n. 3
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;
                    }
                }
            }
        }
        void Instance_handleDtcMessageReceived(object sender, IncomingDtcMessageEventArgs e)
        {
            IncomingDeliveryOrderObject d;

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

            /*AlanDias New way to multithread
             * new Thread(() => {
             *  this.BeginInvoke(new Action(() => { }));
             * }).Start();
             */


            new Thread((ThreadStart) delegate()
            {
                this.BeginInvoke((ThreadStart) delegate()
                {
                    try
                    {
                        if (d.Receiver == "00000888" && d.Deliverer == Settings.Account.Padded())
                        {
                            int i = ProjectedNeeds.Find("Cusip", d.Cusip);

                            if (i != -1 && ProjectedNeeds[i].NeedType == "ProjectedNeed")
                            {
                                ProjectedNeeds[i].DeliveredToCns += d.ShareQuantity.Value;
                                CalcSummary();
                                ProjectedNeeds.Sort("OpenNeed", ListSortDirection.Descending);
                            }
                        }

                        if (d.Deliverer == "00000888" && d.Receiver == Settings.Account.Padded())
                        {
                            int i = ProjectedNeeds.Find("Cusip", d.Cusip);

                            if (i != -1 && ProjectedNeeds[i].NeedType == "ProjectedNeed")
                            {
                                ProjectedNeeds[i].Received += d.ShareQuantity.Value;
                                CalcSummary();
                                ProjectedNeeds.Sort("OpenNeed", ListSortDirection.Descending);
                            }
                        }


                        //Reason Code 620 is for Balance Orders
                        if (d.ReasonCode == "620" && d.Deliverer == Settings.Account.Padded())
                        {
                            int i = ProjectedNeeds.Find("Cusip", d.Cusip);

                            if (i != -1 && (ProjectedNeeds[i].NeedType == "BalanceOrder" || ProjectedNeeds[i].NeedType == "ProjectedNeed"))
                            {
                                ProjectedNeeds[i].DeliveredToCns += d.ShareQuantity.Value;
                                CalcSummary();
                                ProjectedNeeds.Sort("OpenNeed", ListSortDirection.Descending);
                            }
                        }

                        if (d.ReasonCode == "620" && d.Receiver == Settings.Account.Padded())
                        {
                            int i = ProjectedNeeds.Find("Cusip", d.Cusip);

                            if (i != -1 && (ProjectedNeeds[i].NeedType == "BalanceOrder" || ProjectedNeeds[i].NeedType == "ProjectedNeed"))
                            {
                                ProjectedNeeds[i].Received += d.ShareQuantity.Value;
                                CalcSummary();
                                ProjectedNeeds.Sort("OpenNeed", ListSortDirection.Descending);
                            }
                        }

                        /*
                         * //ALANDIAS added for NSCCMISC
                         * if (d.ReasonCode == "620" && d.Deliverer == Settings.Account.Padded())
                         * {
                         *  int i = ProjectedNeeds.Find("Cusip", d.Cusip);
                         *
                         *  if (i != -1 && ProjectedNeeds[i].NeedType == "MiscellaneousFile")
                         *  {
                         *      ProjectedNeeds[i].DeliveredToCns += d.ShareQuantity.Value;
                         *      CalcSummary();
                         *      ProjectedNeeds.Sort("OpenNeed", ListSortDirection.Descending);
                         *  }
                         * }
                         */
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex, TraceEnum.LoggedError);
                    }
                });
            }).Start();
        }