示例#1
0
 private static List <LonghuDTO> GetLonghuDetail(LonghuDTO longhu)
 {
     try
     {
         var url = string.Format(longhuDetailUrl, longhu.StockCode
                                 , longhu.InDate.Value.ToString("yyyy-MM-dd")
                                 , longhu.TypeCode);
         var jsonstart = "details=((";
         var client    = new RestClient();
         var html      = client.GetString(url);
         if (html.Length > 100)
         {
             var index = html.IndexOf(jsonstart);
             html = html.Substring(index + jsonstart.Length);
             html = html.Substring(0, html.Length - 2);
             var detail = SerializeHelper.JsvDeserialize <longhuDetail>(html);
             var list   = new List <LonghuDTO>(10);
             list.AddRange(detail.buy.Select(item => item.ToLonghu(longhu)));
             list.AddRange(detail.sell.Select(item => item.ToLonghu(longhu)));
             return(list);
         }
     }
     catch
     {
     }
     return(new List <LonghuDTO>());
 }
示例#2
0
 public bool IsEqual(LonghuDTO lh)
 {
     if (this == lh)
     {
         return(true);
     }
     return(this.StockCode.IsEqual(lh.StockCode) &&
            this.ComName.IsEqual(lh.ComName) &&
            this.BuyAmount == lh.BuyAmount &&
            this.SellAmount == lh.SellAmount);
 }
示例#3
0
 public LonghuDTO ToLonghu(LonghuDTO longhu)
 {
     return(new LonghuDTO
     {
         StockCode = longhu.StockCode,
         InDate = longhu.InDate,
         StockName = longhu.StockName,
         ComName = comName,
         SellAmount = sellAmount,
         BuyAmount = buyAmount,
         TypeCode = longhu.TypeCode,
         TypeName = longhu.TypeName
     });
 }
示例#4
0
        public static List <LonghuDTO> GetLonghuList(DateTime date)
        {
            string     url     = string.Format(longhuListUrl, date.ToString("yyyy-MM-dd"));
            RestClient client  = new RestClient();
            var        html    = client.GetString(url);
            var        trnodes = XmlHelper.ToXml(html)
                                 .GetNodes("table", "id", "dataTable")
                                 .SelectMany(node => node.GetNodes("tr", "class", "head"));
            var typeName = string.Empty;
            var list     = new List <LonghuDTO>(100);

            foreach (var tr in trnodes)
            {
                var tdnodes = tr.GetNodes("td");
                if (tdnodes.Count == 1)
                {
                    typeName = tdnodes.First().InnerText
                               .Replace(Environment.NewLine, "")
                               .Trim();
                    continue;
                }
                else if (tdnodes.Count == 8)
                {
                    if (tdnodes.First().InnerText.IsEqual("序号"))
                    {
                        continue;
                    }
                    var detail = tdnodes[7].InnerXml;
                    var match  = detailRegex.Match(detail);
                    if (match.Success)
                    {
                        var longhu = new LonghuDTO
                        {
                            StockCode = tdnodes[1].InnerText,
                            StockName = tdnodes[2].InnerText,
                            TypeName  = typeName,
                            TypeCode  = match.Groups[1].Value,
                            InDate    = DateTime.Parse(match.Groups[3].Value)
                        };
                        list.Add(longhu);
                    }
                }
            }
            return(list.SelectMany(lh => GetLonghuDetail(lh))
                   .ToList());
        }