Beispiel #1
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])
            });
            //}
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }