Exemplo n.º 1
0
        /// <summary>
        /// Gets the single quote stock data for a ticker.
        /// Retrieves from the cache <see cref="SingleQuoteCache"/> if it exists,
        /// otherwise it will fetch from the database.
        ///
        /// If does not exist in the database it will return no data.
        /// Returns empty
        /// </summary>
        /// <param name="ticker"></param>
        /// <returns>The <see cref="StockSingleQuoteDataDTO"/></returns>
        public async Task <StockSingleQuoteDataDTO> GetSingleQuoteData(int symbolId)
        {
            SingleQuoteQueryResult queryResult;
            SingleQuoteData        data;

            if (_singleQuoteCache.TryGet(symbolId, out queryResult))
            {
                return(new StockSingleQuoteDataDTO(symbolId, queryResult.Data));
            }

            data = await _stockDataRepository.GetSingleQuoteData(symbolId);


            if (data != null)
            {
                _singleQuoteCache.Add(symbolId, new SingleQuoteQueryResult(data.Ticker, data));
                return(new StockSingleQuoteDataDTO(symbolId, data));
            }

            return(StockSingleQuoteDataDTO.CreateNoDataExists(symbolId));
        }