Exemplo n.º 1
0
        private MinuteSummary GetMinuteSummary(string code, int? count)
        {
            var result = new MinuteSummary();
            result.Code = code;

            var prefix = code.StartsWith("60") ? "sh" : "sz";
            if (code == "999999")
            {
                prefix = "sh";
                code = "000001";
            }
            var url = "http://data.gtimg.cn/flashdata/hushen/minute/" + prefix + code + ".js?" + new Random().NextDouble().ToString();
            var data = HttpGet(url);
            var rr = data.Split(new string[] { @"\n" }, StringSplitOptions.RemoveEmptyEntries);
            result.Code = code;
            result.Details = new List<MinuteDetail>();
            for (int i = 2; i < rr.Length - 1; i++)
            {
                var items = rr[i].Split(' ');

                var detail = new MinuteDetail
                {
                    Price = float.Parse(items[1]),
                    VolumeValue = int.Parse(items[2])
                };
                result.Details.Add(detail);
            }

            if (count.HasValue)
            {
                result.Details = result.Details.Take(count.Value).ToList();
            }

            result.AverageVolumeValue = (int)(result.Details.Last().VolumeValue / result.Details.Count);

            for (int i = result.Details.Count - 1; i > 0; i--)
            {
                result.Details[i].VolumeValue = result.Details[i].VolumeValue - result.Details[i - 1].VolumeValue;
                result.Details[i].IsPositive = result.Details[i].Price > result.Details[i - 1].Price;
            }
            result.Details[0].IsPositive = true;

            var volumeValues = result.Details.Select(i => i.VolumeValue).Distinct().OrderByDescending(i => i).ToList();
            foreach (var item in result.Details)
            {
                item.VolumeIndex = volumeValues.IndexOf(item.VolumeValue);
            }

            result.MaxVolumeValue = volumeValues.FirstOrDefault();

            if (result.Details.Any())
            {
                result.Close = result.Open = result.Details.First().Price;
                var prices = result.Details.Select(i => i.Price).Distinct().OrderBy(i => i).ToList();
                result.High = prices.Last();
                result.Low = prices.First();
            }
            return result;
        }
Exemplo n.º 2
0
        private MinuteSummary GetMinuteSummary(string code, int?count)
        {
            var result = new MinuteSummary();

            result.Code = code;

            var prefix = code.StartsWith("60") ? "sh" : "sz";

            if (code == "999999")
            {
                prefix = "sh";
                code   = "000001";
            }
            var url  = "http://data.gtimg.cn/flashdata/hushen/minute/" + prefix + code + ".js?" + new Random().NextDouble().ToString();
            var data = HttpGet(url);
            var rr   = data.Split(new string[] { @"\n" }, StringSplitOptions.RemoveEmptyEntries);

            result.Code    = code;
            result.Details = new List <MinuteDetail>();
            for (int i = 2; i < rr.Length - 1; i++)
            {
                var items = rr[i].Split(' ');

                var detail = new MinuteDetail
                {
                    Price       = float.Parse(items[1]),
                    VolumeValue = int.Parse(items[2])
                };
                result.Details.Add(detail);
            }

            if (count.HasValue)
            {
                result.Details = result.Details.Take(count.Value).ToList();
            }

            result.AverageVolumeValue = (int)(result.Details.Last().VolumeValue / result.Details.Count);

            for (int i = result.Details.Count - 1; i > 0; i--)
            {
                result.Details[i].VolumeValue = result.Details[i].VolumeValue - result.Details[i - 1].VolumeValue;
                result.Details[i].IsPositive  = result.Details[i].Price > result.Details[i - 1].Price;
            }
            result.Details[0].IsPositive = true;

            var volumeValues = result.Details.Select(i => i.VolumeValue).Distinct().OrderByDescending(i => i).ToList();

            foreach (var item in result.Details)
            {
                item.VolumeIndex = volumeValues.IndexOf(item.VolumeValue);
            }

            result.MaxVolumeValue = volumeValues.FirstOrDefault();

            if (result.Details.Any())
            {
                result.Close = result.Open = result.Details.First().Price;
                var prices = result.Details.Select(i => i.Price).Distinct().OrderBy(i => i).ToList();
                result.High = prices.Last();
                result.Low  = prices.First();
            }
            return(result);
        }