Пример #1
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IQuotation Execute(StockQuotationsLastBeforeDateByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id).Quotations
            ?.Where(q => q.Date <= query.Date)
            .OrderByDescending(q => q.Date)
            .FirstOrDefault());
 }
Пример #2
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IQuotation Execute(StockQuotationsLastOfYearByIdQuery query)
        {
            var endDate = _dateCalculationService.GetEndDateOfYear(new DateTime(query.Year, 1, 1));

            return(_modelReaderRepository.GetById(query.Id).Quotations
                   ?.Where(q => q.Date <= endDate)
                   .OrderByDescending(q => q.Date)
                   .FirstOrDefault());
        }
Пример #3
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionBuyingOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var strategy = _strategyRepository.GetById(eventData.StrategyId);

            if (strategy == null)
            {
                throw new EventHandlerException($"No Strategy found with id: {eventData.StrategyId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var item = new BuyingTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                InitialSL       = eventData.InitialSL,
                InitialTP       = eventData.InitialTP,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Strategy        = strategy,
                Tag             = eventData.Tag,
                Shares          = eventData.Shares,
                Action          = "Kauf",
                PositionSize    = eventData.PositionSize,
                CRV             = eventData.CRV
            };

            _writerRepository.Add(item);

            //Add to transaction book
            _transactionBook.AddEntry(new BuyingTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts));
        }
Пример #4
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionDividendOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionSellingOrderAddedEventHandler));
            }

            var item = new DividendTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Tag             = eventData.Tag,
                Taxes           = eventData.Taxes,
                Shares          = eventData.Shares,
                Action          = "Dividende",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);


            //Add to transaction book
            _transactionBook.AddEntry(new DividendTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts,
                                          eventData.Taxes));
        }
Пример #5
0
        /// <summary>
        /// Adds the item.
        /// </summary>
        /// <param name="aggregateId">The aggregate identifier.</param>
        /// <param name="profitAbsolute">The profit absolute.</param>
        private void AddItem(Guid aggregateId, decimal profitAbsolute)
        {
            if (_modelRepository.GetById(aggregateId) != null)
            {
                return;
            }

            //Get date from transaction
            var balanceDate = _transactionRepository.GetById(aggregateId).OrderDate;

            //Get previous balance
            var lastBalance = _modelRepository.GetAll().OrderByDescending(a => a.Date).FirstOrDefault(a => a.Date < balanceDate);

            //Add new balance
            var item = new AccountBalance(aggregateId, lastBalance?.Balance + profitAbsolute ?? profitAbsolute, profitAbsolute, balanceDate);

            _modelRepository.Add(item);

            //Get future balances
            var futureAccountBalances = _modelRepository.GetAll().OrderBy(a => a.Date).Where(a => a.Date > balanceDate);

            using (var enumerator = futureAccountBalances.GetEnumerator())
            {
                var oldBalance = item.Balance;
                while (enumerator.MoveNext())
                {
                    var newBalance = new AccountBalance(
                        enumerator.Current.TransactionId,
                        oldBalance + enumerator.Current.BalanceChange,
                        enumerator.Current.BalanceChange,
                        enumerator.Current.Date);

                    _modelRepository.Update(newBalance);

                    oldBalance = newBalance.Balance;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionSplitOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionSplitOrderAddedEventHandler));
            }

            var item = new SplitTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Shares          = eventData.Shares,
                OrderCosts      = eventData.OrderCosts,
                Action          = "Split/Reverse Split",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);


            //Add to transaction book
            _transactionBook.AddEntry(new SplitTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare));
        }
Пример #7
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IStock Execute(StockByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id));
 }
Пример #8
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public ITransactionPerformance Execute(TransactionPerformanceByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id));
 }
Пример #9
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public int Execute(StockQuotationsCountByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id).Quotations.Count());
 }
Пример #10
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IQuotation> Execute(StockQuotationsByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id).Quotations.OrderBy(q => q.Date));
 }
Пример #11
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IImage Execute(StrategyImageByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id).Image);
 }
Пример #12
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public ICalculation Execute(CalculationByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id));
 }
Пример #13
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IImage Execute(TransactionImageByIdQuery query)
 {
     return(_modelReaderRepository.GetById(query.Id).Image);
 }
Пример #14
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionSellingOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionSellingOrderAddedEventHandler));
            }

            var feedbacks = _feedbackRepository.GetAll().Where(f => eventData.Feedback.Contains(f.Id)).ToList();

            if (feedbacks == null)
            {
                throw new EventHandlerException("No Feedback found for the given ids", typeof(TransactionSellingOrderAddedEventHandler));
            }

            var item = new SellingTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                Feedback        = feedbacks,
                MAE             = eventData.MAE,
                MFE             = eventData.MFE,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Tag             = eventData.Tag,
                Taxes           = eventData.Taxes,
                Shares          = eventData.Shares,
                Action          = "Verkauf",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);

            //Add to transaction book
            _transactionBook.AddEntry(new SellingTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts,
                                          eventData.Taxes));

            //Feedback Proportions
            var overallFeedbackAmount = _writerRepository.GetAll()
                                        .Where(t => t is ISellingTransaction).Cast <ISellingTransaction>()
                                        .Sum(transaction => transaction.Feedback.Count());


            foreach (var feedback in feedbacks)
            {
                var proportion = _feedbackProportionRepository.GetById(feedback.Id);

                proportion.FeedbackShare = _writerRepository
                                           .GetAll().Where(t => t is ISellingTransaction)
                                           .Cast <ISellingTransaction>()
                                           .SelectMany(t => t.Feedback)
                                           .Count(t => t.Id == feedback.Id);
            }

            foreach (var proportion in _feedbackProportionRepository.GetAll())
            {
                proportion.OverallFeedbackAmount = overallFeedbackAmount;
            }
        }