public void GenAggrPrice(List <CDealClass> sourceLst, List <CDealClass> destLst)
        {
            int i = -1;

            while (i < sourceLst.Count - 1)
            {
                //on first iteration first element,on next =  last processed
                if (i == -1)
                {
                    dtBegin = sourceLst[0].DtTm;
                }
                else
                {
                    dtBegin = dtEnd;
                }

                dtEnd = dtBegin.AddMilliseconds(_parPeriod);

                CDealClass      CDCCurr     = null;
                CAggrDealStruct AggrStrBuy  = null;
                CAggrDealStruct AggrStrSell = null;


                //internal loop
                //list finshed            //   less than interval end
                while (i < sourceLst.Count - 1 && sourceLst[i + 1].DtTm <= dtEnd)
                {
                    i++;
                    CDCCurr = sourceLst[i];
                    if (EnmDealDir.Buy == CDCCurr.DirDeal)
                    {
                        OnIterUpdate(CDCCurr, ref AggrStrBuy);
                    }
                    else
                    if (EnmDealDir.Sell == CDCCurr.DirDeal)
                    {
                        OnIterUpdate(CDCCurr, ref AggrStrSell);
                    }
                }

                //after inrernal loop finished calculate aggr data
                if (AggrStrBuy != null)
                {
                    OnCloseUpdate(AggrStrBuy);
                    destLst.Add(AggrStrBuy.DealClass);
                }
                if (AggrStrSell != null)
                {
                    OnCloseUpdate(AggrStrSell);
                    destLst.Add(AggrStrSell.DealClass);
                }
            }
        }
        private void OnIterUpdate(CDealClass curr, ref CAggrDealStruct upd)
        {
            if (upd == null)
            {
                upd = new CAggrDealStruct();
            }

            upd.DealClass.DirDeal = curr.DirDeal;
            upd.DealClass.Amount += curr.Amount;
            upd.NumDeals++;
            upd.Sum += curr.Amount * curr.Price;

            UpdateMinMax(curr, ref upd);
            //upd.Price += curr.Price; //for averaging on close
        }
        private void UpdateMinMax(CDealClass curr, ref CAggrDealStruct upd)
        {
            if (upd.MinPrice == 0)
            {
                upd.MinPrice = curr.Price;
            }
            if (upd.MaxPrice == 0)
            {
                upd.MaxPrice = curr.Price;
            }

            if (upd.MinPrice < curr.Price)
            {
                upd.MinPrice = curr.Price;
            }
            if (upd.MaxPrice > curr.Price)
            {
                upd.MaxPrice = curr.Price;
            }
        }
Example #4
0
 public void TestDealStruct(CDealClass dc, int amount, EnmDealDir dirDeal, decimal price)
 {
     Assert.AreEqual(amount, dc.Amount);
     Assert.AreEqual(dirDeal, dc.DirDeal);
     Assert.AreEqual(price, dc.Price);
 }