Esempio n. 1
0
        public ActionResult <StockResponse> Get([FromRoute] Guid id, [FromQuery] DateTime?date)
        {
            var stock = _StockQuery.Get(id);

            if (stock == null)
            {
                return(NotFound());
            }

            Date requestedDate;

            if (date != null)
            {
                requestedDate = new Date((DateTime)date);
            }
            else
            {
                requestedDate = Date.Today;
            }

            return(Ok(stock.ToResponse(requestedDate)));
        }
Esempio n. 2
0
        public ServiceResult <CorporateAction> GetCorporateAction(Guid stockId, Guid id)
        {
            var stock = _StockQuery.Get(stockId);

            if (stock == null)
            {
                return(ServiceResult <CorporateAction> .NotFound());
            }

            Domain.CorporateActions.CorporateAction corporateAction;
            try
            {
                corporateAction = stock.CorporateActions[id];
            }
            catch
            {
                return(ServiceResult <CorporateAction> .NotFound());
            }

            var result = corporateAction.ToResponse();

            return(ServiceResult <CorporateAction> .Ok(result));
        }
Esempio n. 3
0
        public async Task Import(CancellationToken cancellationToken)
        {
            var asxCodes = _StockQuery.All(Date.Today).Select(x => x.Properties[Date.Today].AsxCode);

            var stockQuotes = await _DataService.GetMultiplePrices(asxCodes, cancellationToken);

            foreach (var stockQuote in stockQuotes)
            {
                if (stockQuote.Date == Date.Today)
                {
                    var stock = _StockQuery.Get(stockQuote.AsxCode, stockQuote.Date);
                    if (stock != null)
                    {
                        _Logger?.LogInformation("Updating current price for {0}: {1}", stockQuote.AsxCode, stockQuote.Price);

                        _StockService.UpdateCurrentPrice(stock.Id, stockQuote.Price);
                    }
                }
            }
        }
Esempio n. 4
0
        /*      public void ListStapledSecurity(Guid id, string asxCode, string name, Date listingDate, AssetCategory category, IEnumerable<StapledSecurityChild> childSecurities)
         *    {
         *        // Check that id is unique
         *        var stock = _StockRepository.Get(id);
         *        if (stock != null)
         *            throw new Exception("Id not unique");
         *
         *              if (command.Trust)
         *                return BadRequest("A Stapled security cannot be a trust");
         *
         *
         *        // Check if stock already exists with this code
         *        var effectivePeriod = new DateRange(listingDate, DateUtils.NoEndDate);
         *        if (_StockQuery.Find(effectivePeriod, y => y.ASXCode == asxCode).Any())
         *            throw new Exception(String.Format("Stock already exists with the code {0} at {1}", asxCode, listingDate));
         *
         *        var stapledSecurity = new StapledSecurity(id);
         *        stapledSecurity.List(asxCode, name, category, childSecurities);
         *        _StockRepository.Add(stock);
         *        _StockCache.Add(stock);
         *
         *        var stockPriceHistory = new StockPriceHistory(id);
         *        _StockPriceHistoryRepository.Add(stockPriceHistory);
         *        _StockPriceHistoryCache.Add(stockPriceHistory);
         *    } */

        public ServiceResult ChangeStock(Guid id, Date changeDate, string newAsxCode, string newName, AssetCategory newAssetCategory)
        {
            var stock = _StockQuery.Get(id);

            if (stock == null)
            {
                return(ServiceResult.NotFound());
            }

            if (stock.EffectivePeriod.FromDate == Date.MinValue)
            {
                return(ServiceResult.Error("Stock is not listed"));
            }

            if (stock.EffectivePeriod.ToDate != Date.MaxValue)
            {
                return(ServiceResult.Error("Stock is delisted"));
            }

            var stockProperties = stock.Properties.Value(changeDate);

            if (stockProperties.EffectivePeriod.ToDate != Date.MaxValue)
            {
                return(ServiceResult.Error("A later change has been made on {0}", stockProperties.EffectivePeriod.ToDate.AddDays(1).ToShortDateString()));
            }

            if (stockProperties.Properties.AsxCode != newAsxCode)
            {
                if (_StockQuery.Get(newAsxCode, changeDate) != null)
                {
                    return(ServiceResult.Error("A stock already exists with code {0} on {1}", newAsxCode, changeDate.ToShortDateString()));
                }
            }

            stock.ChangeProperties(changeDate, newAsxCode, newName, newAssetCategory);
            _StockRepository.Update(stock);

            return(ServiceResult.Ok());
        }