/// <summary> /// Calculate ticker info from recent trade and update it /// </summary> /// <param name="trade"></param> public void CalculateTickerInfo(Trade trade) { var tickerReadModel = _tickerInfoRepository.GetTickerInfoByCurrencyPair(trade.CurrencyPair); if (tickerReadModel == null) { TickerInfoReadModel model = new TickerInfoReadModel(trade.CurrencyPair, trade.ExecutionPrice.Value, trade.ExecutedVolume.Value); //model.CurrencyPair = trade.CurrencyPair; _persistanceRepository.SaveOrUpdate(model); } else { object[] todays = CalculateTodaysData(trade); log.Debug("Recevied today:" + todays); object[] last24Hours = Calculate24HoursData(trade); log.Debug("Received 24Hours:" + last24Hours); decimal openingPrice = 0; decimal lastTradePrice = 0; decimal lastTradeVolume = 0; IList <TradeReadModel> trades = _tradeRepository.GetTradesBetweenDates(trade.ExecutionTime, DateTime.Today, trade.CurrencyPair); if (trades != null) { if (trades.Count > 0) { log.Debug("Total Trades=" + trades.Count); openingPrice = trades[trades.Count - 1].Price; lastTradePrice = trades[0].Price; lastTradeVolume = trades[0].Volume; } } tickerReadModel.UpdateTickerInfo(todays, last24Hours, openingPrice, lastTradePrice, lastTradeVolume); _persistanceRepository.SaveOrUpdate(tickerReadModel); } }