public void ActivateExchange(int quantity, double price)
        {
            long revenue = (int)(price * quantity);
            DateTime now = DateTime.Now;

            if (CurrentDay == null || now.Day != CurrentDay.Day)
            {
                CurrentDay = new ExchangeDay(now.Day, price, quantity, revenue);
                ExchangeDayList.Add(CurrentDay);

                if (ExchangeDayList.Count > 20)
                {
                    bool hdq = false;
                    bool lp = false;
                    bool hp = false;
                    ExchangeDay oldday = ExchangeDayList[0];

                    TotalQuantity -= oldday.TotalQuantity;
                    TotalRevenue -= oldday.TotalRevenue;

                    if (oldday.TotalQuantity == HighestDayQuantity)
                    {
                        hdq = true;
                        HighestDayQuantity = 0;
                    }

                    if (oldday.HighestPrice == HighestDayPrice)
                    {
                        hp = true;
                        HighestDayPrice = 0;
                    }

                    if (oldday.LowestPrice == LowestPrice)
                    {
                        lp = true;
                        LowestPrice = double.MaxValue;
                    }

                    ExchangeDayList.RemoveAt(0);

                    foreach (ExchangeDay ed in ExchangeDayList)
                    {
                        if (hdq)
                            HighestDayQuantity = Math.Max(HighestDayQuantity, ed.TotalQuantity);
                        if (hp)
                            HighestPrice = Math.Max(HighestPrice, ed.HighestPrice);
                        if (lp)
                            LowestPrice = Math.Min(LowestPrice, ed.LowestPrice);
                    }
                }
            }
            else
                CurrentDay.AddExchange(price, quantity, revenue);

            LastPrice = price;
            LastQuantity = quantity;
            LastExchangeTime = now;

            TotalQuantity += quantity;
            TotalRevenue += revenue;
            HighestPrice = Math.Max(HighestPrice, price);
            LowestPrice = Math.Min(LowestPrice, price);
            AveragePrice = Math.Round((double)TotalRevenue / TotalQuantity,2);

            HighestDayPrice = 0;
            LowestDayPrice = double.MaxValue;
            foreach (ExchangeDay ed in ExchangeDayList)
            {
                HighestDayPrice = Math.Max(HighestDayPrice, ed.Average);
                LowestDayPrice = Math.Min(LowestDayPrice, ed.Average);
            }

            HighestDayQuantity = Math.Max(HighestDayQuantity, CurrentDay.TotalQuantity);

            m_SalesInfo1 = new string[]
                {
                    "Last:", "",
                    "Last-P:",LastPrice.ToString(),
                    "Last-Q:", LastQuantity.ToString()
                };

            m_SalesInfo2 = new string[]
                {
                    "Highest-P:", HighestPrice.ToString(),
                    "Lowest-P:", LowestPrice.ToString(),
                    "Average-P:", AveragePrice.ToString(),
                    "Total-Q:", TotalQuantity.ToString(),
                    "Total-R:", TotalRevenue.ToString()
                };
        }
        public void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();

            //Category set by the collections this belongs to
            LastExchangeTime = reader.ReadDateTime();
            LastPrice = reader.ReadDouble();
            LastQuantity = reader.ReadInt();

            AveragePrice = reader.ReadDouble();

            HighestDayQuantity = reader.ReadLong();
            HighestDayPrice = reader.ReadDouble();
            LowestDayPrice = reader.ReadDouble();

            HighestPrice = reader.ReadDouble();
            LowestPrice = reader.ReadDouble();
            TotalQuantity = reader.ReadLong();

            int count = reader.ReadInt();
            for (int i = 0; i < count; i++)
            {
                ExchangeDay ed = new ExchangeDay(reader);
                ExchangeDayList.Add(ed);

                if (i == count - 1)
                    CurrentDay = ed;
            }

            count = reader.ReadInt();
            for (int i = 0; i < count; i++)
            {
                BuyInfo bi = new BuyInfo(reader);
                BuyInfoList.Add(bi);
                bi.Info = this;
            }

            count = reader.ReadInt();
            for (int i = 0; i < count; i++)
            {
                SellInfo si= new SellInfo(reader);
                SellInfoList.Add(si);
                si.Info = this;
            }

            m_SalesInfo1 = CustomSaving.DeserializeStringArray(reader);
            m_SalesInfo2 = CustomSaving.DeserializeStringArray(reader);
        }