Esempio n. 1
0
        public static RootObject GetRandomData(Datacode dc, int numrecords, decimal basevalue, decimal mult, DateTime startdate)
        {
            RootObject ro = new RootObject();

            if (dc != null)
            {
                ro.source_code = dc.ToDatacodeString('.');
            }

            System.Random rnd = new Random();
            ro.id           = rnd.Next(1, 1000000);
            ro.isCacheable  = false;
            ro.column_names = new List <string>();
            ro.column_names.Add(qh.DefaultDateColumnName);
            ro.column_names.Add(qh.DefaultValueColumnName);
            ro.data = new List <List <object> >();
            for (int i = 0; i < numrecords; i++)
            {
                var val  = ((decimal)rnd.NextDouble() * mult) + basevalue;
                var date = new DateTime(startdate.Ticks);
                ro.data.Add(new List <object>(new object[] { date, val }));
                // next date
                startdate = startdate.AddDays(1);
            }
            return(ro);
        }
Esempio n. 2
0
 /// <summary>
 /// Add all columns for the supplied datasource
 /// </summary>
 /// <param name="datasource">The datasource</param>
 public void AddColumns(Datacode datasource)
 {
     if (_datacolumns.Length > 0)
     {
         _datacolumns.Append(',');
     }
     _datacolumns.Append(datasource.ToDatacodeString('.'));
 }
Esempio n. 3
0
 /// <summary>
 /// Add a column to the collection of columns to be returned
 /// </summary>
 /// <param name="datasource">The datasource</param>
 /// <param name="column">The column to add</param>
 public void AddColumn(Datacode datasource, int column)
 {
     if (_datacolumns.Length > 0)
     {
         _datacolumns.Append(',');
     }
     _datacolumns.Append(string.Format("{0}.{1}", datasource.ToDatacodeString('.'), column));
 }
Esempio n. 4
0
        private string CreateRequestString()
        {
            ValidateData();

            StringBuilder sb = new StringBuilder();

            sb.Append(Constants.APIDatasetsAddress)
            .Append('/')
            .Append(Datacode.ToDatacodeString('/'))
            .Append(TypeConverter.FileFormatToString(Format))
            .Append('?');

            if (APIKey != string.Empty)
            {
                sb.Append(Constants.APIAuthorization)
                .Append(APIKey)
                .Append('&');
            }

            sb.Append(Constants.APIFrequency)
            .Append(TypeConverter.FrequencyToString(Frequency))
            .Append('&')
            .Append(Constants.APITransformation)
            .Append(TypeConverter.TransformationsToString(Transformation))
            .Append('&')
            .Append(Constants.APISortOrder)
            .Append(TypeConverter.SortOrdersToString(Sort));

            if (Truncation > 0)
            {
                sb.Append('&')
                .Append(Constants.APITruncation)
                .Append(Truncation);
            }

            if (StartDate != DateTime.MinValue)
            {
                sb.Append('&')
                .Append(Constants.APIStartDate)
                .Append(TypeConverter.DateToString(StartDate));
            }

            if (EndDate != DateTime.MaxValue)
            {
                sb.Append('&')
                .Append(Constants.APIEndDate)
                .Append(TypeConverter.DateToString(EndDate));
            }

            if (Format == FileFormats.CSV)
            {
                sb.Append('&')
                .Append(Constants.APIHeader)
                .Append(!Headers);
            }

            return(sb.ToString());
        }
Esempio n. 5
0
        public void GetDatacode_Correct()
        {
            var datacode = new Datacode()
            {
                Source = "PRAGUESE",
                Code   = "PX"
            };

            Assert.AreEqual("PRAGUESE/PX", datacode.ToDatacodeString('/'), "The unique code should be the Source and Code separated by a forward slash");
        }
Esempio n. 6
0
 /// <summary>
 /// gets pretty quandl code
 /// </summary>
 /// <param name="dc"></param>
 /// <returns></returns>
 public static string DataCode2String(Datacode dc)
 {
     return(dc.ToDatacodeString('.'));
 }