为什么我无法通过此链接获取数据?

时间:2019-05-24 08:31:35

标签: quandl

我不明白为什么此链接不起作用:“ https://www.quandl.com/api/v3/datasets/WIKI/IBM.csv?&collapse=daily&transformation=none&sort_order=asc&start_date=2018-05-24&end_date=2019-05-23”;

using System;
using QuandlCS.Requests;
using QuandlCS.Types;
using System.Net;
using System.Data;
using System.IO;

namespace QuantBook.Models.DataModel.Quandl
{
    public static class QuandlHelper
    {
        private const string quandlKey = "gp_z7rn26KEP3uJFuuiw";

        public static DataTable GetQuandlData(string ticker, string dataSource, DateTime startDate, DateTime endDate)
        {
            System.Net.ServicePointManager.SecurityProtocol =
            SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            QuandlDownloadRequest request = new QuandlDownloadRequest();
            request.APIKey = quandlKey;
            request.Datacode = new Datacode(dataSource, ticker);
            request.Format = FileFormats.CSV;
            request.Frequency = Frequencies.Daily;
            request.StartDate = startDate;
            request.EndDate = endDate;
            request.Sort = SortOrders.Ascending;

            string ss = request.ToRequestString().Replace("/v1/", "/v3/");
            string a = "https://www.quandl.com/api/v3/datasets/WIKI/IBM.csv?&collapse=daily&transformation=none&sort_order=asc&start_date=2018-05-24&end_date=2019-05-23";


            DataTable dt = new DataTable();
            using (WebClient client = new WebClient())
            {
                    client.DownloadFile(a, "my.csv");
                    dt = ModelHelper.CsvToDatatable("my.csv");

            }
            return dt;
        }
    }
}

0 个答案:

没有答案