Exemplo n.º 1
0
        //YAHOO/AAPL
        public static string GetJsonData(string source, string codeQuandl, DateTime start, DateTime end){
            QuandlDownloadRequest request = new QuandlDownloadRequest();
            //request.APIKey = " _qjPeu6SzNYNJ42scYAi";
            request.APIKey = "1ztyfXyfPBTeqfshhBdE";

            if (codeQuandl == "EPA_SAN")
            {
                if (end.Year < 2014)
                {
                    request.Datacode = new Datacode("YAHOO", "PA_SAN");
                }
                else
                {
                    request.Datacode = new Datacode(source, codeQuandl);
                }
            }
            else
            {
                request.Datacode = new Datacode(source, codeQuandl);
            }
            request.Format = FileFormats.JSON;
            request.Frequency = Frequencies.Daily;
            request.Transformation = Transformations.None;
            request.StartDate = start;
            request.EndDate = end;

            //Console.WriteLine("The request string is : {0}", request.ToRequestString());
            IQuandlConnection connection = new QuandlConnection();
            return connection.Request(request);
            //JObject jObject = JObject.Parse(data);
            //JArray column_names = (JArray)jObject["column_names"];
        }
Exemplo n.º 2
0
    public void ToRequestString_InvalidDatacodeCode_ExceptionThrown()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", string.Empty)
      };

      request.ToRequestString();
    }
Exemplo n.º 3
0
    public void ToRequestString_CSVFormat_HeadersUsedInRequestString()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", "TEST"),
        Format = FileFormats.CSV
      };

      var requestString = request.ToRequestString();
      Assert.IsTrue(requestString.Contains("&exclude_headers="));
    }
Exemplo n.º 4
0
    public void ToRequestString_InvalidTruncation_ExceptionThrown()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", "TEST"),
        Truncation = 0
      };

      var requestString = request.ToRequestString();
      Assert.IsFalse(requestString.Contains("&rows=0"));
    }
Exemplo n.º 5
0
    public void ToRequestString_ZeroTruncation_NotUsedInRequestString()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", "TEST"),
        Truncation = 0
      };

      var requestString = request.ToRequestString();
      Assert.IsFalse(requestString.Contains("&rows=0"));
    }
Exemplo n.º 6
0
    public void ToRequestString_ValidTruncation_UsedInRequestString()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", "TEST"),
        Truncation = 1
      };

      var requestString = request.ToRequestString();
      Assert.IsTrue(requestString.Contains("&rows=1"));
    }
Exemplo n.º 7
0
        public static string GetJsonData(string source, string codeQuandl, DateTime start, DateTime end)
        {
            QuandlDownloadRequest request = new QuandlDownloadRequest();
            request.APIKey = "1ztyfXyfPBTeqfshhBdE";
            request.Datacode = new Datacode(source, codeQuandl);
            request.Format = FileFormats.JSON;
            request.Frequency = Frequencies.Daily;
            request.Transformation = Transformations.None;
            request.StartDate = start;
            request.EndDate = end;

            IQuandlConnection connection = new QuandlConnection();
            return connection.Request(request);

        }
Exemplo n.º 8
0
        public static ParsedData GrabData(string quandlDatabase, string datacodeParams, int datapointsNumber, string frequency)
        {
            //Quandl request
            QuandlDownloadRequest request = new QuandlDownloadRequest();
            request.APIKey = "xNA_rA8KzZepxFUeu9bA";

            request.Datacode = new Datacode(quandlDatabase, datacodeParams); // PRAGUESE is the source, PX is the datacode
            request.Format = FileFormats.JSON;

            switch (frequency)
            {
                case "d":
                    request.Frequency = Frequencies.Daily;
                    break;
                case "w":
                    request.Frequency = Frequencies.Weekly;
                    break;
                case "m":
                    request.Frequency = Frequencies.Monthly;
                    break;
                case "q":
                    request.Frequency = Frequencies.Quarterly;
                    break;
                case "a":
                    request.Frequency = Frequencies.Annualy;
                    break;
                default:
                    request.Frequency = Frequencies.Daily;
                    break;
            }

            request.Truncation = datapointsNumber;
            request.Sort = SortOrders.Descending;
            request.Transformation = Transformations.None;

            //OUTPUT: https://www.quandl.com/api/v1/datasets/PRAGUESE/PX.json?auth_token=xNA_rA8KzZepxFUeu9bA&collapse=monthly&transformation=diff&sort_order=asc&rows=150
            //https://www.quandl.com/api/v3/datasets/YAHOO/YHOO.json

            //Initialize data structure
            ParsedData pData = new ParsedData();
            List<string> paramList = new List<string>();
            List<string> paramType = new List<string>();

            //Parsing the data
            using (WebClient web = new WebClient())
            {
                string data = web.DownloadString(string.Format(request.ToRequestString()));
                JObject o = JObject.Parse(data);

                //Parse column_names
                foreach (string parameter in o["column_names"].Children())
                {
                    pData.Add(parameter.ToString(), "Heading");
                    paramList.Add(parameter.ToString());
                }

                //var headings = o["column_names"].Children();
                pData.dataName = (string)o["name"].ToString();

                var results = o["data"].Children();

                //REWRITE THIS---------------------------
                //Find the parameters of the data
                foreach (var val in results)
                {
                    foreach (var type in val)
                    {
                        paramType.Add(type.Type.ToString());
                    }
                    if (paramType.Count > paramList.Count)
                        break;
                }
                pData.AddDataTypeList(paramType);
                //-----------------------------------------
                foreach (var dataPoint in results)
                {
                    int count = 0;
                    foreach (var val in dataPoint)
                    {
                        pData.Add(paramList[count], val.ToString());
                        count++;
                    }
                }
                return pData;
               }
        }
Exemplo n.º 9
0
 private static string GetSingleData(string source, string code, DateTime start, Frequencies freq, Transformations trans)
 {
     QuandlDownloadRequest requestRawData = new QuandlDownloadRequest();
     requestRawData.APIKey = APIK_KEY;
     requestRawData.Datacode = new Datacode(source, code);
     requestRawData.Format = FileFormats.JSON;
     requestRawData.Frequency = freq;
     requestRawData.Transformation = trans;
     requestRawData.StartDate = start;
     requestRawData.EndDate = DateTime.Now;
     var urlRawData = requestRawData.ToRequestString();
     return GetMessage(urlRawData);
 }
Exemplo n.º 10
0
 private void Initialize()
 {
   if (_request == null)
   {
     _request = new QuandlDownloadRequest();
   }
 }
Exemplo n.º 11
0
 static IQuandlRequest CreateRequest(string sym, Datacode dc, FileFormats form)
 {
     QuandlDownloadRequest qdr = new QuandlDownloadRequest();
     qdr.APIKey = APIK;
     qdr.Datacode = dc;
     qdr.Format = form;
     return qdr;
 }
Exemplo n.º 12
0
    public void ToRequestString_StartDateBeforeEndDate_ExceptionNotThrown()
    {
      var request = new QuandlDownloadRequest()
      {
        Datacode = new Datacode("DW", "TEST"),
        StartDate = DateTime.Now.AddDays(-10), 
        EndDate = DateTime.Now.AddDays(10)     // End 20 days after start
      };

      var requestString = request.ToRequestString();
    }