Example #1
0
        public async Task <IActionResult> PlaceOrder([FromBody] OrderWriteDTO orderWriteDto)
        {
            // Series of validations
            // BEGIN
            if (!_securitiesProvider.Securities.ContainsKey(orderWriteDto.Ticker))
            {
                return(BadRequest(new JsonResult("Ticker does not exist")));
            }

            TradableSecurity security = _securitiesProvider.Securities[orderWriteDto.Ticker];

            if (orderWriteDto.Amount == 0)
            {
                return(BadRequest(new JsonResult("Amount of shares must not be 0")));
            }
            else if (security.OutstandingAmount < orderWriteDto.Amount)
            {
                return(BadRequest(new JsonResult("Cannot ask for more shares than exists")));
            }

            // END

            Order order = _mapper.Map <Order>(orderWriteDto);

            order = await _stockExchange.PlaceOrder(order);

            if (order == null)
            {
                return(BadRequest());
            }

            return(Ok(order));
        }