0

我正在使用 Web.DownloadString(); 从雅虎股票下载数据。该站点将拥有多个用户,因此我需要让客户端而不是服务器发送下载请求,以避免从服务器 IP 地址发送过多请求而被阻止。我找不到在客户端运行它的方法,并且正在寻求帮助,使其从客户端而不是服务器运行。

下面是一个格式不正确的函数,我打算清理我现在正在使用的函数

我计划只使用让数据运行客户端所需的部分,其余运行服务器我还没有清理我的代码。

 Public void DownloadData() 
 {
        string csvData = null;
        string month1 = Convert.ToString(DropDownList1.SelectedIndex);
        string month2 = Convert.ToString(DropDownList2.SelectedIndex);
        string Temp = "http://ichart.finance.yahoo.com/table.csv?s=" + SymbolName.Text + "&d=" + month2 + "&e=" + TextBox3.Text + "&f=" + TextBox4.Text + "&g=d&a=" + month1 + "&b=" + TextBox1.Text + "&c=" + TextBox2.Text + "&ignore=.csv";
        string FileRead;
        List<string> Remove1 = new List<string>();
        string path = System.AppDomain.CurrentDomain.BaseDirectory;
        using (WebClient web = new WebClient())
        {
            try
            {
                csvData = web.DownloadString(Temp);
            }

            catch
            {

            }
        }
        if (csvData != null && csvData != "")
        {
          File.WriteAllText(path + "\\MyTest.txt", csvData);
        }

       System.IO.StreamReader file = new System.IO.StreamReader(path + "\\MyTest.txt");
          while ((FileRead = file.ReadLine()) != null) //reads from file
        {
            Remove1.Add(FileRead);
        }
        file.Close();

        csvData = csvData.Replace("Date,Open,High,Low,Close,Volume,Adj Close", "");



        List<stock> prices = YahooFinance.Parse(csvData);
        double Lowest = 0;
        foreach (stock price in prices) // finds lowest value to addjust priceing 
        {
            if (Lowest == 0)
            {
                Lowest = Convert.ToDouble(price.low);
            }
            if (Lowest > Convert.ToDouble(price.low))
            {
                Lowest = Convert.ToDouble(price.low);
            }
        }
        //  new double[] { Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close) }
        Chart1.ChartAreas[0].AxisX.Interval = 2;
        Chart2.ChartAreas[0].AxisX.Interval = 2;
        Chart1.ChartAreas[0].AxisX.Maximum = prices.Count + 20;
        Chart1.ChartAreas[0].AxisY.Minimum = Lowest - 3;
        foreach (stock price in prices)
        {
            Chart1.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close));
            Chart2.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.Volume));
        }


    }

`

4

0 回答 0