Example #1
0
        /// <summary>
        /// Fetch stock information and data
        /// </summary>
        /// <param name="symbol"></param>
        /// <returns></returns>
        public async Task <Result <StockInfoClientResponseDto> > GetStockInfo(string symbol)
        {
            _logger.LogInformation("Fetching data for ticker {0}", symbol);

            AddQueryParam("t", symbol);

            var response = await _http.GetAsync(BuildQuery());

            _logger.LogInformation("Data fetched for ticker {0}", symbol);

            var result = await HandleClientResponse(response);

            if (!result.Succedded)
            {
                _logger.LogInformation("Fetchind data for ticker {0} failed -> {1}", symbol, result.Message);
                return(ResultExtensions.Failure <StockInfoClientResponseDto>(result.Message));
            }

            if (!ContainsTickerId(result.Instance, symbol))
            {
                _logger.LogInformation("Ticker {0} not found", symbol);
                return(ResultExtensions.Failure <StockInfoClientResponseDto>("Ticker not found"));
            }

            var fetchedInstance = ParseInstanceFromHtmlContent(result.Instance);

            _logger.LogInformation("Data for ticker fetched and prepared");

            return(ResultExtensions.Success(fetchedInstance));
        }
Example #2
0
        public async Task <Result <PremarketDataResponseDto> > FetchPremarketData(string symbol)
        {
            var result = await _client.GetPremarketData(symbol, StonkType.Stock);

            if (!result.Succedded)
            {
                return(ResultExtensions.Failure <PremarketDataResponseDto>("Stock with given symbol not found"));
            }

            if (!ValidPage(result.Instance, "intraday__data"))
            {
                return(ResultExtensions.Failure <PremarketDataResponseDto>("Stock with given symbol not found"));
            }

            var instance = CreateInstanceBasedOnHtmlContent(result.Instance);

            return(ResultExtensions.Success(instance));
        }
Example #3
0
        private Result <T> HandleBadRequest <T>(HttpResponseMessage response)
        {
            var result = ResultExtensions.Failure <T>("unexpected error");

            return(result);
        }