Beispiel #1
0
        public async Task AddIndexValues(StockIndexValueInputs stockIndexValueInputs)
        {
            if (ValidateInputs(stockIndexValueInputs) && await _stockIndexTickerService.CheckIfStockTickerExists(stockIndexValueInputs.Ticker))
            {
                var ticker = await _stockIndexTickerService.GetStockIndex(stockIndexValueInputs.Ticker);

                var tickerId   = ticker.TickerId;
                var connection = _connectionService.GetConnectionToCommonShard();
                var startTime  = stockIndexValueInputs.StartDate;
                var endTime    = stockIndexValueInputs.EndDate;

                var totalNumberOfDays           = CalculateNumberOfWeekDays(startTime, endTime);
                var numberOfDaysTickerIsPresent = await _stockIndexValueData.GetNumberOfDaysTickerValueIsPresent(connection, tickerId, startTime, endTime);

                if (numberOfDaysTickerIsPresent != totalNumberOfDays)
                {
                    var stockPrice = await _marketDataService.GetDailyStockPrice(stockIndexValueInputs.Ticker,
                                                                                 stockIndexValueInputs.StartDate,
                                                                                 stockIndexValueInputs.EndDate);

                    var indexValues = MapMarketDataToIndexValueModel(stockPrice, tickerId);
                    await _stockIndexValueData.AddIndexValue(connection, indexValues);
                }

                _connectionService.DisposeConnection(connection);
            }
        }
        public async Task <IActionResult> Post([FromBody] StockIndexTicker stockIndexTicker)
        {
            try
            {
                var tickerExists = await _stockIndexService.CheckIfStockTickerExists(stockIndexTicker.Ticker);

                if (!tickerExists)
                {
                    var tickerId = await _stockIndexService.AddStockIndex(stockIndexTicker);

                    return(Ok(tickerId));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }