private void TranslateToTickerQuotes(GetTimeSeriesResponse response, IQuotesDalGetTimeseriesValuesResult getResult)
        {
            IQuotesData quotesData = getResult.Quotes[0];

            ITimeSeriesRecord rcFirst = quotesData.Quotes.FirstOrDefault();
            ITimeSeriesRecord rcLast  = quotesData.Quotes.LastOrDefault();

            TickerQuotes tickerQuotes = new TickerQuotes();

            tickerQuotes.Code        = quotesData.Ticker;
            tickerQuotes.TimePeriod  = quotesData.TimeFrame;
            tickerQuotes.PeriodStart = rcFirst != null ? rcFirst.Time : DateTime.MinValue;
            tickerQuotes.PeriodEnd   = rcLast != null ? rcLast.Time : DateTime.MinValue;
            tickerQuotes.Quotes.AddRange(quotesData.Quotes.Select(x => new QuoteRecord(x.Time, x.Values)).ToList());

            response.Payload.Values = tickerQuotes;
        }
        public IQuotesSourceGetQuotesResult GetQuotes(IQuotesSourceGetQuotesParams getQuotesParams)
        {
            StooqApi api = new StooqApi();

            IQuotesSourceGetQuotesResult result = new StooqSourceGetQuotesResult();

            foreach (var t in getQuotesParams.Tickers)
            {
                IQuotesSourceCanImportParams canImportParams = CreateCanImportParams();
                canImportParams.Tickers.Add(t);
                IQuotesSourceCanImportResult canImportRes = CanImport(canImportParams);
                if (canImportRes.Success)
                {
                    try
                    {
                        IQuotesData qd = new BaseQuotesData();

                        var quotes = api.Download(t,
                                                  getQuotesParams.PeriodStart,
                                                  getQuotesParams.PeriodEnd,
                                                  getQuotesParams.Country,
                                                  getQuotesParams.TimeFrame == ETimeFrame.Daily ? StooqApi.ETimeFrame.Daily : (getQuotesParams.TimeFrame == ETimeFrame.Weekly ? StooqApi.ETimeFrame.Weekly : StooqApi.ETimeFrame.Monthly));

                        foreach (var q in quotes.Quotes)
                        {
                            ITimeSeriesRecord newRec = qd.CreateQuotesRecord();
                            newRec["Close"]  = q.Close;
                            newRec["High"]   = q.High;
                            newRec["Open"]   = q.Open;
                            newRec["Low"]    = q.Low;
                            newRec["Volume"] = q.Volume;
                            newRec.Time      = ToPeriodStart(q.PeriodEnd, getQuotesParams.TimeFrame);

                            qd.AddRecord(newRec);
                        }

                        qd.Country   = getQuotesParams.Country;
                        qd.Ticker    = t;
                        qd.Name      = this.TickerName(t);
                        qd.TimeFrame = getQuotesParams.TimeFrame;
                        qd.Type      = this.TickerType(t);
                        qd.Unit      = this.TickerUnit(t);

                        result.QuotesData.Add(qd);
                    }
                    catch (Exception ex)
                    {
                        result.Success = false;
                        result.AddError(Interfaces.EErrorCodes.QuotesSourceFail, Interfaces.EErrorType.Error, ex.Message);
                    }
                }
            }

            result.Success = result.QuotesData.Count > 0;
            if (result.Success && result.QuotesData.Count != getQuotesParams.Tickers.Count)
            {
                result.AddError(Interfaces.EErrorCodes.QuotesNotFound, Interfaces.EErrorType.Warning, "Not all quotes were found");
            }
            else if (!result.Success)
            {
                result.AddError(Interfaces.EErrorCodes.QuotesNotFound, Interfaces.EErrorType.Error, "Requested tickers are not supported or quotes for them not found");
            }

            return(result);
        }
 public void AddRecord(ITimeSeriesRecord newRecord)
 {
     (Quotes as List <ITimeSeriesRecord>).Add(newRecord);
 }