/// <summary>
        /// Processing deal queue.
        /// </summary>
        private void ProcessOnlineDeals()
        {
            while (true)
            {
                CDeal deal = _queue.GetElementBlocking();

                //Wait till GUI  frees resources.
                WaitTillRecalcEnabled();



                DisablePaintClusters = true;

                //Call update deals
                OnUpdateDeals(deal);


                DisablePaintClusters = false;

                //Start parallel save if need
                if (IsNeedToSaveData())
                {
                    TriggerSave();
                }
            }
        }
        private void ProcessAggrDeals()
        {
            //process deals
            lock (_dataReciever.OutpListAggrDeals)
            {
                lock (_dataReciever.OutpListAggrDeals[_tickerName])
                {
                    //get data from deal queue
                    while (_dataReciever.OutpListAggrDeals[_tickerName].Count != 0)
                    {
                        {
                            CDeal deal = new CDeal();

                            deal.Amount = (int)_dataReciever.OutpListAggrDeals[_tickerName][0].Amount;
                            deal.Price  = Math.Round((double)_dataReciever.OutpListAggrDeals[_tickerName][0].Price, this.Decimals);

                            deal.Direction = (EnmDealDirection)_dataReciever.OutpListAggrDeals[_tickerName][0].DirDeal;
                            deal.DateTime  = _dataReciever.OutpListAggrDeals[_tickerName][0].DtTm;

                            //TODO try to do with dependency property
                            //changed 2016_12_13

                            AddNewDeal(deal);
                        }

                        //note we remove it from queue after read
                        _dataReciever.OutpListAggrDeals[_tickerName].RemoveAt(0);
                    }
                }
            }
        }
예제 #3
0
 public void UpdateCluster(DateTime dt, CDeal deal)
 {
     lock (this)
     {
         CreateIfNotExists(deal.Price, dt);
         this[deal.Price][dt].Update(deal);
     }
 }
        private void UpdateClusterPriceM1(CDeal deal)
        {
            DateTime dtDeal = deal.DateTime;

            DateTime dt = dtDeal.Date.AddHours(dtDeal.Hour).AddMinutes(dtDeal.Minute);

            _clusterPriceM1.UpdateCluster(dt, deal);
        }
예제 #5
0
        public void Test1()
        {
            CClusterProcessor clusterProcessor = new CClusterProcessor("test_instrument1", "M5");

            while (!clusterProcessor.IsDataLoaded)
            {
                Thread.Sleep(10);
            }

            //List <CDeal> _lstDeals = new List<CDeal>();
            // _lstDeals.Add(new CDeal { Amount = 1, Price = 1000, Direction = EnmDealDirection.Sell, DateTime = new DateTime(2017, 01, 27, 10, 25, 0) });

            //System.Threading.Thread.Sleep(10000);


            const int _parSecTime1 = 60;//6 * 60;
            const int _parSleepSec = 1;



            DateTime dtBegin = DateTime.Now;

            int priceInc = 1;

            double minCyclePrice = 11500;
            double price         = minCyclePrice;
            double maxCyclePrice = 11700;


            while ((DateTime.Now - dtBegin).TotalSeconds < _parSecTime1)
            {
                price += priceInc;
                if (price > maxCyclePrice)
                {
                    price = minCyclePrice;
                }

                CDeal deal = new CDeal
                {
                    Amount    = 1,
                    DateTime  = DateTime.Now,
                    Direction = EnmDealDirection.Sell,
                    Price     = price
                }

                ;
                clusterProcessor.Update(deal);
                //Thread.Sleep(_parSleepSec);
            }

            //     clusterProcessor.ChangeTimeFrame(5);



            Thread.Sleep(1000000);
        }
        /// <summary>
        ///Call from:  OnUpdateDeals
        /// </summary>
        /// <param name="deal"></param>
        private void UpdateNewestClusters(CDeal deal)
        {
            DateTime dtLast = _lstTimes[0];

            lock (_lckClustersCurrent)
            {
                _clusterPriceCurrent.UpdateCluster(dtLast, deal);
                _clusterDateCurrent.UpdateCluster(dtLast, deal);
            }
        }
        /// <summary>
        /// Call from ProcessOnlineDeals
        /// </summary>
        /// <param name="deal"></param>
        private void OnUpdateDeals(CDeal deal)
        {
            _lstAllDeals.Add(deal);

            //note. we change stock data to local and use it in operations
            deal.DateTime = DateTime.Now;    //CUtilTime.MscToLocal(deal.DateTime);
            UpdateTimes();
            UpdateNewestClusters(deal);
            UpdateClusterPriceM1(deal);
        }
        private void AddNewDeal(CDeal deal)
        {
            const double parMaxSize = 1000;

            lock (_ticks)
            {
                _ticks.Add(deal);
                if (_ticks.Count > parMaxSize)
                {
                    _ticks.RemoveAt(0);
                }
            }


            RepaintDeals();
        }
예제 #9
0
        public List <CDeal> GetDealsList()
        {
            List <CDeal> lstDeals = new List <CDeal>();

            lock (this)
            {
                foreach (KeyValuePair <double, Dictionary <DateTime, CCluster> > kvp in this)
                {
                    double price = kvp.Key;

                    foreach (KeyValuePair <DateTime, CCluster> pair2 in kvp.Value)
                    {
                        CCluster cluster = pair2.Value;


                        if (cluster.AmountBuy > 0)
                        {
                            CDeal item = new CDeal
                            {
                                Price     = kvp.Key,
                                DateTime  = pair2.Key,
                                Direction = EnmDealDirection.Buy,
                                Amount    = cluster.AmountBuy,
                            };
                            lstDeals.Add(item);
                        }


                        if (cluster.AmountSell > 0)
                        {
                            CDeal item = new CDeal
                            {
                                Price     = kvp.Key,
                                DateTime  = pair2.Key,
                                Direction = EnmDealDirection.Sell,
                                Amount    = cluster.AmountSell,
                            };
                            lstDeals.Add(item);
                        }
                    }
                }
            }

            return(lstDeals);
        }
예제 #10
0
        public void Update(CDeal deal)
        {
            AmountTotal += deal.Amount;

            if (deal.Direction == EnmDealDirection.Buy)
            {
                AmountBuy += deal.Amount;
            }
            else
            {
                AmountSell += deal.Amount;
            }


            if (AmountSell > AmountBuy)
            {
                TotalDir = EnmDealDirection.Sell;
            }
            else
            {
                TotalDir = EnmDealDirection.Buy;
            }
        }
예제 #11
0
        private void ProcessRowDeals()
        {
            lock (_dataReciever.OutpListRawDeals)
            {
                lock (_dataReciever.OutpListRawDeals[_tickerName])
                {
                    while (_dataReciever.OutpListRawDeals[_tickerName].Count != 0)
                    {
                        CDeal tk = new CDeal();

                        tk.Amount = (int)_dataReciever.OutpListRawDeals[_tickerName][0].Amount;
                        tk.Price  = Math.Round((double)_dataReciever.OutpListRawDeals[_tickerName][0].Price, this.Decimals);

                        tk.Direction = (EnmDealDirection)_dataReciever.OutpListRawDeals[_tickerName][0].DirDeal;
                        tk.DateTime  = _dataReciever.OutpListRawDeals[_tickerName][0].DtTm;

                        //TODO try to do with dependency property
                        //_controlMarket.ControlClustersInstance.Ticks = tk;
                        _dataReciever.OutpListRawDeals[_tickerName].RemoveAt(0);
                        _clusterProcessor.Update(tk);
                    }
                }
            }
        }
 public void Update(CDeal deal)
 {
     _queue.Add(deal);
 }
예제 #13
0
        /// <summary>
        /// Call from CClusterProcessor.UpdateNewestClusters
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="deal"></param>
        public void UpdateCluster(DateTime dt, CDeal deal)
        {
            CreateIfNotExists(dt);

            this[dt].Update(deal);
        }