public AnalyticsManager(IAnalyticsStorage analyticsStorage, List <double> precisions, List <int> markets, List <OrderInfo> orders, int tradesHistorySize = 100)
 {
     this.analyticsStorage = analyticsStorage ?? throw new ArgumentNullException(nameof(analyticsStorage));
     AnalyticsExchange     = AnalyticsExchange.RestoreExchange(markets, orders);
     PriceHistoryManager   = new PriceHistoryManager(analyticsStorage, markets ?? throw new ArgumentNullException(nameof(markets)));
     TradesHistoryManager  = new TradesHistoryManager(markets, tradesHistorySize);
     MarketDepthsManager   = new MarketDepthsManager(markets, precisions, AnalyticsExchange.OrderMap);
     MarketTickersManager  = new MarketTickersManager(markets, PriceHistoryManager);
 }
        public static AnalyticsExchange RestoreExchange(List <int> assets, List <OrderInfo> orders)
        {
            var exchange = new AnalyticsExchange();

            foreach (var asset in assets)
            {
                exchange.AddMarket(asset);
            }

            foreach (var order in orders)
            {
                var orderData = OrderIdConverter.Decode(order.OrderId);
                var market    = exchange.GetMarket(orderData.Asset);
                var orderbook = market.GetOrderbook(orderData.Side);
                orderbook.InsertOrder(new OrderInfoWrapper {
                    Order = order
                });
            }
            return(exchange);
        }
        public async Task OnUpdates(ExchangeUpdate updates)
        {
            await syncRoot.WaitAsync();

            try
            {
                AnalyticsExchange.OnUpdates(updates);
                await PriceHistoryManager.OnTrade(updates);

                TradesHistoryManager.OnTrade(updates);
                MarketDepthsManager.OnOrderUpdates(updates);
            }
            catch (Exception exc)
            {
                //TODO: add support for delayed trades, now it failes during rising
                OnError?.Invoke(exc);
                logger.Error(exc);
            }
            finally
            {
                syncRoot.Release();
            }
        }