コード例 #1
0
        public int DiluteOneSecurityPerMinute(string symbol, DateTime startDate, DateTime endDate)
        {
            var securities = _session.Query <SecurityData>()
                             .Where(securityData =>
                                    securityData.LastUpdate >= startDate &&
                                    securityData.LastUpdate < endDate);


            var unlList = securities.Where(sd => sd.SecurityContract.Symbol.Equals(symbol) &&
                                           sd.Account.Equals(AllConfigurations.AllConfigurationsObject.Application
                                                             .MainAccount))
                          .OrderBy(securityData => securityData.LastUpdate).ToList();

            if (unlList.Count == 0)
            {
                return(0);
            }
            var lastTimeItems = new TimeItems(unlList[0].LastUpdate);
            int counter       = 0;

            for (var index = 1; index < unlList.Count; index++)
            {
                var securityData    = unlList[index];
                var currenTimeItems = new TimeItems(securityData.LastUpdate);

                if (lastTimeItems.IsNewMinute(currenTimeItems))
                {
                    lastTimeItems = currenTimeItems;
                }
                else
                {
                    //delete row
                    _session.Delete(securityData);
                    counter++;
                }
            }
            _session.Flush();
            Logger.InfoFormat($"DBDiluter Diluted {counter} securities from {symbol}, between dates:{startDate} :: {endDate}");
            return(counter);
        }
コード例 #2
0
        public int DiluteOneOptionPerMinute(string symbol, DateTime startDate, DateTime endDate)
        {
            //endDate = new DateTime(2017, 11, 1, 0, 1, 0);
            //startDate = new  DateTime(2017,10,31,0,1, 0);
            startDate = startDate.Date;
            DateTime          dueDate = startDate;
            int               counter = 0;
            List <OptionData> unlList = null;

            //Do it in step of 1 day to illuminate the huge possible records!

            while (dueDate < endDate)
            {
                try
                {
                    //var dueDate = startDate;
                    var theDate = dueDate;
                    var options = _session.Query <OptionData>()
                                  .Where(optionData =>
                                         optionData.OptionContract.Symbol.Equals(symbol) &&
                                         optionData.LastUpdate >= theDate &&
                                         optionData.LastUpdate < theDate.AddHours(4)) /*.Take(100000)*/.ToList();// &&
                    //optionData.Account.Equals(AllConfigurations.AllConfigurationsObject
                    //    .Application.MainAccount)).ToList() /*.Take(100000)*/;


                    //var list = options.Where(od => od.OptionContract.Symbol.Equals(symbol)).ToList();
                    unlList = options.OrderBy(optionData => optionData.LastUpdate).ToList();
                    if (unlList.Count == 0)
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        var toString = ex.InnerException.ToString();
                        if (toString.Contains("canceling statement due to statement timeout"))
                        {
                            Logger.Error(ex.Message, ex);
                            throw new Exception("Canceling task due to Timeout!!!!");
                        }
                    }
                }
                finally
                {
                    dueDate = dueDate.AddHours(4);
                }
                if (unlList != null)
                {
                    var lastTimeItems = new TimeItems(unlList[0].LastUpdate);

                    for (var index = 1; index < unlList.Count; index++)
                    {
                        var optionData      = unlList[index];
                        var currenTimeItems = new TimeItems(optionData.LastUpdate);

                        if (lastTimeItems.IsNewMinute(currenTimeItems))
                        {
                            lastTimeItems = currenTimeItems;
                        }
                        else
                        {
                            //delete row
                            _session.Delete(optionData);
                            counter++;
                        }
                    }
                }
                _session.Flush();
            }
            Logger.InfoFormat($"DBDiluter Diluted {counter} options from {symbol}, between dates:{startDate} :: {endDate}");
            return(counter);
        }