Example #1
0
 public void SetColumns(IList <string> columns)
 {
     Series.Clear();
     SeriesNames.Clear();
     for (int i = 0; i < columns.Count; ++i)
     {
         IndicatorSeriesData data = new IndicatorSeriesData();
         data.Name = columns[i];
         Series.Add(columns[i], data);
         SeriesNames.Add(i, columns[i]);
     }
 }
        public IDictionary <DateTime, decimal> GetTimeseriesData(string ticker, string timeseries)
        {
            IDictionary <DateTime, decimal> values = null;
            IndicatorData       indData            = null;
            IndicatorSeriesData indSeriesData      = null;

            if (Indicators.TryGetValue(ticker, out indData) && indData.Series.TryGetValue(timeseries, out indSeriesData))
            {
                values = new Dictionary <DateTime, decimal>(indSeriesData.Values);
            }

            return(values);
        }
        public decimal GetDateValue(string ticker, string timeseries, DateTime dt)
        {
            decimal result = Decimal.MinValue;

            IndicatorData       indData       = null;
            IndicatorSeriesData indSeriesData = null;

            if (Indicators.TryGetValue(ticker, out indData) && indData.Series.TryGetValue(timeseries, out indSeriesData))
            {
                DateTime k = indSeriesData.Values.Keys.LastOrDefault(x => x <= dt);
                if (k != DateTime.MinValue)
                {
                    result = indSeriesData.Values[k];
                }
            }

            return(result);
        }
        public EErrorCodes GetTimeSeries(string country, string ticker, ETimeFrame timeframe, DateTime periodStart, DateTime periodEnd)
        {
            EErrorCodes result = EErrorCodes.GeneralError;

            try
            {
                if (SessionToken != null)
                {
                    GetTimeSeries reqGetTs = new GetTimeSeries();
                    reqGetTs.Ticker       = ticker;
                    reqGetTs.CountryCode  = country;
                    reqGetTs.SessionToken = SessionToken;
                    reqGetTs.PeriodStart  = periodStart != DateTime.MinValue ? periodStart : DateTime.Parse("01/01/1970");
                    reqGetTs.PeriodEnd    = periodEnd != DateTime.MinValue ? periodEnd : DateTime.Now;
                    reqGetTs.TimeFrame    = timeframe;

                    GetTimeSeriesResponse resGetTs = Post <GetTimeSeries, GetTimeSeriesResponse>("/api/timeseries/GetTimeSeries", reqGetTs);
                    if (resGetTs.Success)
                    {
                        // creating new records if needed
                        IndicatorData indData = null;
                        if (Indicators.TryGetValue(ticker, out indData))
                        {
                            for (int i = 0; i < resGetTs.Payload.Values.Quotes.Count; ++i)
                            {
                                QuoteRecord rec = resGetTs.Payload.Values.Quotes[i];
                                for (int v = 0; v < rec.Values.Count; ++v)
                                {
                                    String sTsName = indData.SeriesNames[v];
                                    IndicatorSeriesData indTsData = null;
                                    if (indData.Series.TryGetValue(sTsName, out indTsData))
                                    {
                                        indTsData.Values.Add(
                                            rec.Time,
                                            rec.Values[v]
                                            );
                                    }
                                }
                            }

                            result = EErrorCodes.Success;
                        }
                        else
                        {
                            result = EErrorCodes.TickerNotFound;
                        }
                    }
                    else
                    {
                        _lastError = new Exception(resGetTs.Errors[0].Message);
                        result     = resGetTs.Errors[0].Code;
                    }
                }
                else
                {
                    return(EErrorCodes.SessionClosed);
                }
            }
            catch (Exception ex)
            {
                _lastError = ex;
                result     = EErrorCodes.GeneralError;
            }

            return(result);
        }