Example #1
0
        public static List <StockEntity> HistoryTradeList(string stockCode, DateTime from, DateTime to)
        {
            var client = new RestClient();
            var csv    = client.GetString(String.Format(historydataUrl, StockHelper.WYCode(stockCode)
                                                        , from.ToString("yyyyMMdd")
                                                        , to.ToString("yyyyMMdd")));

            if (!string.IsNullOrWhiteSpace(csv))
            {
                csv = csv.Replace("日期,股票代码,名称,收盘价,最高价,最低价,开盘价,前收盘,涨跌幅,换手率,成交量,成交金额"
                                  , "InDate,StockCode,StockName,Close,High,Low,Open,LClose,Percent,Turnover,Volume,Amount");
                csv = csv.Replace("None", "0");
                var list = SerializeHelper.CsvDeserialize <List <StockEntity> >(csv);
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        item.StockCode = item.StockCode.Replace("'", string.Empty).Trim();
                    }
                    list = list.Where(item => item.Volume.GetValueOrDefault() > 0)
                           .OrderBy(item => item.InDate)
                           .ToList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i].DateSort = i;
                    }
                    return(list);
                }
            }
            return(new List <StockEntity>());
        }
Example #2
0
        public static StockEntity GetRealTime(List <string> stockCodeList)
        {
            string codes = stockCodeList.Select(str => StockHelper.GetLongCode(str))
                           .Join(",");
            string url         = "http://hq.sinajs.cn/list=" + codes;
            var    client      = new RestClient();
            var    dataStr     = client.GetString(url);
            var    stockStrAry = dataStr.Split(';');
            //var list

            //foreach (var stockStr in stockStrAry)
            //{
            var stockStr  = stockStrAry.First();
            var eqIndex   = stockStr.IndexOf("=");
            var stockData = stockStr.Substring(eqIndex + 2);

            stockData = stockData.Substring(0, stockData.Length - 1);
            var stockDatas = stockData.Split(',');

            return(new StockEntity
            {
                InDate = DateTime.Parse(stockDatas[30] + " " + stockDatas[31])
            });
            //}
        }
Example #3
0
        public static List <TradeTranDTO> GetTradeList(string code, DateTime from, DateTime?to = null)
        {
            to = to.GetValueOrDefault(DateTime.Now).Date;
            var shortCode = StockHelper.GetShortCode(code);

            code = StockHelper.GetLongCode(code);

            List <TradeTranDTO> list = new List <TradeTranDTO>(100);
            var curr = from.Date;

            while (curr <= to)
            {
                var client = new RestClient();
                var csv    = client.GetString(string.Format(tradeTranurl, curr.ToString("yyyy-MM-dd"), code));
                if (!csv.IsNullOrEmpty() &&
                    csv.Length > 1000)
                {
                    csv = csv.Replace("\t", ",");
                    csv = csv.Replace("--", "0");
                    csv = csv.Replace("成交时间,成交价,价格变动,成交量(手),成交额(元),性质", "Time,Price,PriceChange,Qty,Amount,Vector");
                    list.Add(new TradeTranDTO()
                    {
                        StockCode = shortCode, InDate = curr, Detail = csv
                    });
                }
                curr = curr.AddDays(1);
            }
            return(list);
        }
Example #4
0
        public static string GetZhubi(string code, DateTime date)
        {
            var    url  = string.Format(zhubiUrl, date.ToString("yyyy-MM-dd"), StockHelper.GetLongCode(code));
            string html = new RestClient().GetString(url);

            if (html.Contains("没有当天数据"))
            {
                return(string.Empty);
            }

            html = html.Replace("成交时间	成交价	价格变动	成交量(手)	成交额(元)	性质", "Time	Price	ChangePrice	Qty	Amount	Direct")
                   .Replace("--", "0").Replace("\t", ",");
            return(html);
        }
Example #5
0
        public static ZhubiDTO GetZhubiDTO(string code, DateTime date)
        {
            var dto = ZhubiDAL.GetZhubi(code, date);

            if (dto == null)
            {
                var xls = SinaBiz.GetZhubi(code, date);
                if (!string.IsNullOrEmpty(xls))
                {
                    dto = new ZhubiDTO
                    {
                        StockCode = StockHelper.GetShortCode(code)
                        ,
                        InDate = date.Date
                        ,
                        Xls = xls
                    };
                    ZhubiDAL.Insert(dto);
                }
            }
            return(dto);
        }
Example #6
0
        public static ZhubiDTO GetZhubi(string code, DateTime date)
        {
            var sql = @"SELECT StockCode,Indate, `Xls`
FROM `svc`.`zhubi`
where stockcode = @StockCode and InDate = @InDate ";

            return(SqlHelper.GetEntity <ZhubiDTO>(sql,
                                                  SqlHelper.CreateParameter("@StockCode", StockHelper.GetShortCode(code))
                                                  , SqlHelper.CreateParameter("@InDate", date.ToString("yyyy-MM-dd"))));
        }
Example #7
0
 public static List <StockFinanceEntity> DownloadFinance(StockEntity stock)
 {
     try
     {
         var    stockcode = stock.StockCode;
         string url       = string.Format("http://basic.10jqka.com.cn/{0}/xls/mainreport.xls", StockHelper.GetShortCode(stockcode));
         var    buffer    = new RestClient().GetData(url);
         if (buffer == null ||
             buffer.Length == 0)
         {
             return(null);
         }
         var path = "Finance\\" + stockcode + ".xls";
         if (File.Exists(path))
         {
             File.Delete(path);
         }
         Directory.CreateDirectory(Path.GetDirectoryName(path));
         File.WriteAllBytes(path, buffer);
         return(ReadFromExcel(stock, path));
     }
     catch (Exception ex)
     {
         ExceptionHelper.Handler(ex);
         return(null);
     }
 }