Ejemplo n.º 1
0
        private List <SecurityDomain> GetSecuritiesInPageFromSSE(int pageIndex, int pageSize)
        {
            HttpWebClient client = new HttpWebClient();

            client.URL = "http://query.sse.com.cn/security/stock/getStockListData2.do";
            client.Headers.Add("Accept", "*/*");
            client.Headers.Add("Accept-Encoding", "gzip, deflate");
            client.Headers.Add("Accept-Language", "zh-CN,q=0.9;");
            client.Headers.Add("Connection", "keep-alive");
            client.Headers.Add("Host", "query.sse.com.cn");
            client.Headers.Add("Referer", "http://www.sse.com.cn/");
            client.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66");
            Random random = new Random();

            client.Data = string.Format("&jsonCallBack=jsonpCallback{0}&isPagination=true&stockCode=&csrcCode=&areaName=&stockType=1&pageHelp.cacheSize=1&pageHelp.beginPage={1}&pageHelp.pageSize={2}&pageHelp.pageNo={1}&_={3}",
                                        random.Next(100000), pageIndex, pageSize, DateTime.Now.Subtract(new DateTime(1970, 1, 1, 8, 0, 0)).Ticks);
            string result = client.SendGetRequest();
            Match  match  = Regex.Match(result, "\"result\":\\[([\\S\\s]*)\\]");
            List <SecurityDomain> values = new List <SecurityDomain>();

            if (match.Success)
            {
                List <SecurityDomain> lst = JsonConvert.DeserializeObject <List <SecurityDomain> >(string.Format("[{0}]", match.Groups[1].Value));
                foreach (SecurityDomain security in lst)
                {
                    security.ExchangeMarket = "SSE";
                }
                values.AddRange(lst);
            }
            return(values);
        }
Ejemplo n.º 2
0
        public List <RealTimeStockTransaction> GetList(string stockCodes)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            HttpWebClient client = new HttpWebClient();

            client.URL = string.Format("http://hq.sinajs.cn/list={0}", stockCodes);
            string result = client.SendGetRequest();

            string[] arrResult = result.Split(';');
            int      count     = arrResult.Length - 1;

            string[] arrStockCode = stockCodes.Split(',');
            List <RealTimeStockTransaction> lst = new List <RealTimeStockTransaction>();
            RealTimeStockTransaction        realTimeStockTransaction;

            for (int i = 0; i < count; i++)
            {
                int      startIndex = arrResult[i].IndexOf("\"");
                int      endIndex   = arrResult[i].LastIndexOf("\"");
                string   temp       = arrResult[i].Substring(startIndex, endIndex - startIndex);
                string[] arr        = temp.Split(',');
                realTimeStockTransaction                = new RealTimeStockTransaction();
                realTimeStockTransaction.StockName      = arr[0];
                realTimeStockTransaction.StockCode      = arrStockCode[i];
                realTimeStockTransaction.OpenPrice      = Convert.ToDouble(arr[1]);
                realTimeStockTransaction.LastClosePrice = Convert.ToDouble(arr[2]);
                realTimeStockTransaction.CurrentPrice   = Convert.ToDouble(arr[3]);
                realTimeStockTransaction.HightPrice     = Convert.ToDouble(arr[4]);
                realTimeStockTransaction.LowPrice       = Convert.ToDouble(arr[5]);
                realTimeStockTransaction.Volume         = Convert.ToDouble(arr[8]);
                realTimeStockTransaction.Turnover       = Convert.ToDouble(arr[9]);
                realTimeStockTransaction.Ask1Volume     = Convert.ToDouble(arr[10]);
                realTimeStockTransaction.Ask1           = Convert.ToDouble(arr[11]);
                realTimeStockTransaction.Ask2Volume     = Convert.ToDouble(arr[12]);
                realTimeStockTransaction.Ask2           = Convert.ToDouble(arr[13]);
                realTimeStockTransaction.Ask3Volume     = Convert.ToDouble(arr[14]);
                realTimeStockTransaction.Ask3           = Convert.ToDouble(arr[15]);
                realTimeStockTransaction.Ask4Volume     = Convert.ToDouble(arr[16]);
                realTimeStockTransaction.Ask4           = Convert.ToDouble(arr[17]);
                realTimeStockTransaction.Ask5Volume     = Convert.ToDouble(arr[18]);
                realTimeStockTransaction.Ask5           = Convert.ToDouble(arr[19]);
                realTimeStockTransaction.Bid1Volume     = Convert.ToDouble(arr[20]);
                realTimeStockTransaction.Bid1           = Convert.ToDouble(arr[21]);
                realTimeStockTransaction.Bid2Volume     = Convert.ToDouble(arr[22]);
                realTimeStockTransaction.Bid2           = Convert.ToDouble(arr[23]);
                realTimeStockTransaction.Bid3Volume     = Convert.ToDouble(arr[24]);
                realTimeStockTransaction.Bid3           = Convert.ToDouble(arr[25]);
                realTimeStockTransaction.Bid4Volume     = Convert.ToDouble(arr[26]);
                realTimeStockTransaction.Bid4           = Convert.ToDouble(arr[27]);
                realTimeStockTransaction.Bid5Volume     = Convert.ToDouble(arr[28]);
                realTimeStockTransaction.Bid5           = Convert.ToDouble(arr[29]);
                realTimeStockTransaction.Date           = Convert.ToDateTime(arr[30]);
                realTimeStockTransaction.Time           = Convert.ToDateTime(arr[30] + " " + arr[31]);
                lst.Add(realTimeStockTransaction);
            }
            return(lst);
        }
        public List <SecurityDayQuotationDomain> GetSSEDayQuotationFromWangYi(string securityCode, DateTime startDate, DateTime endDate)
        {
            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
            HttpWebClient client = new HttpWebClient();

            client.Encoding = System.Text.Encoding.GetEncoding("GB2312");
            //http://quotes.money.163.com/service/chddata.html?code=0601857&start=20200101&end=20200224&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP
            client.URL  = "http://quotes.money.163.com/service/chddata.html";
            client.Data = string.Format("code=0{0}&start={1}&end={2}&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP"
                                        , securityCode, startDate.ToString("yyyyMMdd"), endDate.ToString("yyyyMMdd"));
            string result = client.SendGetRequest();

            result = result.Replace("'", "");
            string[] arrSecurities = result.Split(new string[] { "\r\n" }, StringSplitOptions.None);
            string[] arrTemp;
            List <SecurityDayQuotationDomain> values = new List <SecurityDayQuotationDomain>();
            SecurityDayQuotationDomain        value;
            int count = arrSecurities.Length;

            for (int i = 1; i < arrSecurities.Length - 1; i++)
            {
                arrTemp              = arrSecurities[i].Split(',');
                value                = new SecurityDayQuotationDomain();
                value.TxDate         = Convert.ToDateTime(arrTemp[0]);
                value.SecurityCode   = arrTemp[1];
                value.SecurityAbbr   = arrTemp[2];
                value.ClosePrice     = Convert.ToDouble(arrTemp[3]);
                value.HighPrice      = Convert.ToDouble(arrTemp[4]);
                value.LowPrice       = Convert.ToDouble(arrTemp[5]);
                value.OpenPrice      = Convert.ToDouble(arrTemp[6]);
                value.LastClosePrice = Convert.ToDouble(arrTemp[7]);
                value.PriceChange    = arrTemp[8] == "None" ? -10000 : Convert.ToDouble(arrTemp[8]);
                value.Change         = arrTemp[9] == "None" ? -10000: Convert.ToDouble(arrTemp[9]);
                value.TurnOver       = arrTemp[10] == "None" ? -10000: Convert.ToDouble(arrTemp[10]);
                value.VolumeTurnOver = Convert.ToDouble(arrTemp[11]);
                value.PriceTurnOver  = Convert.ToDouble(arrTemp[12]);
                value.MarketValue    = Math.Round(Convert.ToDouble(arrTemp[13]) / 100000000, 4);
                value.NegoValue      = Math.Round(Convert.ToDouble(arrTemp[14]) / 100000000, 4);
                values.Add(value);
            }
            return(values);
        }