/// <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)); }
/// <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)); }
/// <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)); }
/// <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; } }