Ejemplo n.º 1
0
        public AllStockPackage FetchDataAll(MARKET market, int page)
        {
            if (market == MARKET.none)
            {
                return(null);
            }
            if (page <= 0)
            {
                return(null);
            }

            AllStockPackage data = null;

            var url        = string.Format(URL_ALL, market.ToString());
            var parameters = new Dictionary <string, string>();

            parameters.Add("key", AppKey);
            parameters.Add("page", page.ToString());
            var script = WebRequestor.Send(url, parameters, WebRequestor.RequestMethod.get, Encoding.UTF8);

            if (!string.IsNullOrWhiteSpace(script))
            {
                data = JsonConvert.DeserializeObject <AllStockPackage>(script);
            }

            return(data);
        }
Ejemplo n.º 2
0
        private List <TengxunIndexInfoEntity> GetIndexData(List <string> codes)
        {
            var separator = Convert.ToChar(10);
            var list      = new List <TengxunIndexInfoEntity>();
            var container = new List <string>();

            if (codes != null || codes.Count > 0)
            {
                codes.ForEach(cd =>
                {
                    var code = cd.Trim().ToLower();
                    if (!container.Contains(code))
                    {
                        container.Add(code);
                    }
                });
                var scodes = string.Join(",", container);

                //var sb = new StringBuilder();
                //container.ForEach(cd =>
                //{
                //    var market = TengxunIndexInfoEntity.TellMarket(cd);
                //    if (market == MARKET.none) return;
                //    var ncode = market.ToString() + cd;
                //    if (sb.Length > 0) sb.Append(",");
                //    sb.Append(ncode);
                //});

                var parameters = new Dictionary <string, string>();
                parameters.Add("q", scodes);
                var script = WebRequestor.Send(url, parameters, WebRequestor.RequestMethod.get, Encoding.GetEncoding("GB2312"));

                var scripts = (!string.IsNullOrWhiteSpace(script)) ? new List <string>(script.Split(new char[] { separator })) : new List <string>();
                scripts.ForEach(scrpt =>
                {
                    TengxunIndexInfoEntity info = null;
                    TryParse(scrpt, out info);
                    if (info != null)
                    {
                        list.Add(info);
                    }
                });
            }
            return(list);
        }
        public T FetchData <T>(string code) where T : BasicInfoEntity
        {
            var market = StockInfoEntity.TellMarket(code);

            if (market == MARKET.none)
            {
                return(null);
            }
            var ncode = market.ToString() + code;

            var parameters = new Dictionary <string, string>();

            parameters.Add("list", ncode);
            var             script = WebRequestor.Send(url, parameters, WebRequestor.RequestMethod.get, Encoding.GetEncoding("GB2312"));
            StockInfoEntity info   = null;

            TryParse(script, out info);

            object result = info;

            return((T)result);
        }