Exemplo n.º 1
0
 /// <summary>
 /// gets quandl datacode given source and symbol
 /// </summary>
 /// <param name="source"></param>
 /// <param name="symbol"></param>
 /// <returns></returns>
 public static Datacode BuildQdlCode(qdl_ds source, qdl_freq freq,  params string[] datasetids)
 {
     if (freq== qdl_freq.None)
         return BuildQdlCode(GetQdlDataCode(source),datasetids);
     List<string> ids = new List<string>(datasetids);
     ids.Add(GetQdlFreq(freq));
     return BuildQdlCode(GetQdlDataCode(source), ids.ToArray());
 }
Exemplo n.º 2
0
        static string GetQdlFreq(qdl_freq freq)
        {
            switch (freq)
            {
                case qdl_freq.None:
                    return string.Empty;
                case qdl_freq.Annual:
                    return DATASOURCE_FREQ_YEAR;
                case qdl_freq.Quarterly:
                    return DATASOURCE_FREQ_QTR;
                default:
                    throw new Exception("Data set frequency: " + freq + " not yet implemented.");
            }

        }
Exemplo n.º 3
0
 public static RootObject GetRandomData(Datacode dc, qdl_freq freq) { return GetRandomData(dc, freq == qdl_freq.Quarterly ? 4 * 5 : 5); }
Exemplo n.º 4
0
 public static RootObject GetRandomData(qdl_freq freq ) { return GetRandomData(null, freq== qdl_freq.Quarterly ? 4*5 : 5); }
Exemplo n.º 5
0
        /// <summary>
        /// get a quandl data set for particular symbol/column/frequency
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="symbol"></param>
        /// <param name="trycache"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        public static RootObject Get(qdl_ds ds, string symbol, string additionaldataset, qdl_freq freq, bool trycache, DebugDelegate d)
        {
            if (_d==null)
                _d = d;
            Datacode dc = null;
            string raw = string.Empty;
            RootObject ro = null;
            try
            {
                if (string.IsNullOrWhiteSpace(additionaldataset))
                    dc = BuildQdlCode(ds,freq, symbol);
                else
                    dc = BuildQdlCode(ds, freq, symbol, additionaldataset);
            }
            catch (Exception ex)
            {
                debug("Unable to get data, error building dataset: " + qh.dc2str(dc) + " " + symbol + " err: " + ex.Message + ex.StackTrace);
                return default(RootObject);
            }
            try
            {
                raw = GetData(symbol, dc, trycache, d);
                // verify data retrieved before continuing
                if (string.IsNullOrWhiteSpace(raw))
                {
                    if (isUseFakeDataOnError)
                    {
                        ro = GetRandomData(dc, freq);
                        debug("FakeDataOnError enabled, using: " + ro.data.Count + " randomized data set.");
                        return ro;
                    }
                    else
                    {
                        debug(symbol + " " + qh.dc2str(dc) + " no data was retrieved.  Retry or contact [email protected]");
                        return default(RootObject);
                    }
                }
            }
            catch (Exception ex)
            {
                debug("Unable to get data, error retrieving set: " + qh.dc2str(dc) + " " + symbol + " err: " + ex.Message + ex.StackTrace);
                return default(RootObject);
            }
            try
            {

                ro = json.Deserialize2Root(raw, false, d);
                v(symbol + " " + qh.dc2str(dc) + " got data model containing " + ro.column_names.Count.ToString("N0") + " columns and " + ro.data.Count.ToString("N0") + " records.");
            }
            catch (Exception ex)
            {

                if (isVerboseDebugging)
                {
                    debug("Unable to get data, error parsing set: " + ds + " " + symbol + " err: " + ex.Message + ex.StackTrace);
                    debug(symbol + " " + qh.dc2str(dc) + " errored data set: " + raw);
                }
                else
                    debug("Unable to get data, error parsing set: " + qh.dc2str(dc) + " " + symbol + " err: " + ex.Message + ex.StackTrace);

                return default(RootObject);

            }
            return ro;
        }