Exemple #1
0
        public ResearchResult CheckFundResponse(FundResponce par)
        {
            if (par.DayValues.Count < 2)
            {
                return new ResearchResult
                       {
                           periodChange = +888,
                       }
            }
            ;
            int index = 0; float[] deltas = new float[CheckPeriod_Days];

            for (int i = par.DayValues.Count - 1; i > 0 && index < CheckPeriod_Days; i--, index++)
            {
                deltas[index] = AverValue(par.DayValues, i) - AverValue(par.DayValues, i - 1);
            }
            float periodChange = deltas.Sum();

            return(new ResearchResult
            {
                fundResponce = par,
                FundId = par.FundId,
                periodChange = deltas.Sum(),
                // lastChange = deltas[0],
                lastChange = par.DayValues[par.DayValues.Count - 1].Percent - par.DayValues[par.DayValues.Count - 2].Percent,
            });
        }
Exemple #2
0
        private void InitialReceives()
        {
            Receive <FundRequest>(job =>
            {
                try
                {
                    Log.Information("Downloader #" + _index.ToString() + " Start download job");

                    FundResponce responce = new FundResponce
                    {
                        FundId    = job.FundId,
                        Tag       = job.Tag,
                        From      = job.From,
                        To        = job.To,
                        DayValues = new List <DayValue>()
                    };
                    using (WebClient client = new WebClient())
                    {
                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                        client.Headers["User-Agent"] = Tase.UserAgent;
                        string url = string.Format(Tase.RequestFormat,
                                                   job.FundId.ToString(Tase.FundIdFormat), job.From.ToString(Tase.RequestDateFormat),
                                                   job.To.ToString(Tase.RequestDateFormat));
                        // Program.Log.Logging(Program.OP, url);
                        responce.WebResponce = client.DownloadString(url);
                        Log.Information("Downloader #" + _index.ToString() + " Received chars:" + responce.WebResponce.Length.ToString());
                        Sender.Tell(responce);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Downloader:FundRequest Downloader #" + _index.ToString() + ex.Message);
                    Sender.Tell(new FailedFun {
                        FundId = job.FundId
                    });
                }
            });

            /*
             *          Receive<Stop>(job =>
             *          {
             *              try
             *              {
             *                  // D.Tell(new PoisonPill());
             *                  BusinesLogic.Log.Logging(BusinesLogic.OP, "Downloader #" + m_Index.ToString() + " - STOP");
             *              }
             *              catch (Exception ex)
             *              {
             *              }
             *          });
             */
        }
Exemple #3
0
        public FundResponce CreateBeforeBuyResonce(int BuyDateIndex)
        {
            FundResponce res = new FundResponce
            {
                FundId    = this.FundId,
                DotStyle  = true,
                Color     = this.Color,
                DayValues = new List <DayValue>(),
            };

            for (int i = 0; i < BuyDateIndex; i++)
            {
                res.DayValues.Add(this.DayValues[0]);
                this.DayValues.RemoveAt(0);
            }
            res.DayValues.Add(this.DayValues[0]);
            return(res);
        }
Exemple #4
0
        private void CalculateAverageSerie(ref List <FundResponce> responces)
        {
            // System.Globalization.NumberFormatInfo myInv = System.Globalization.NumberFormatInfo.InvariantInfo;
            List <string> res      = new List <string>();
            FundResponce  AverData = new FundResponce
            {
                Color     = "'#000000'",
                DotStyle  = false,
                DayValues = new List <DayValue>(),
                FundId    = -1,
            };

            List <DateTime> dates = (from fr in responces
                                     from dv in fr.DayValues
                                     select dv.Date)
                                    .Distinct().OrderBy(x => x).ToList();

            for (int d = 0; d < dates.Count; d++)
            {
                float PercentValue = 0; int ValuesCount = 0;
                for (int f = 0; f < responces.Count; f++)
                {
                    DayValue dv = responces[f].DayValues.FirstOrDefault(x => x.Date == dates[d]);
                    if (dv != null)
                    {
                        if (!responces[f].DotStyle)
                        {
                            PercentValue += dv.Percent;
                            ValuesCount++;
                        }
                    }
                }
                float Percent = ValuesCount > 0 ? PercentValue / ValuesCount : 0;
                AverData.DayValues.Add(new DayValue {
                    Date = dates[d], Index = d, Percent = Percent
                });
            }
            responces.Add(AverData);
        }