예제 #1
0
        public void Start()
        {
            _pricesReader.SubscribeToChanges(prices =>
            {
                foreach (var price in prices)
                {
                    _priceStraem.WriteToStream(_mapper.Map <PriceUpdate>(price));
                }
            });

            _tickerReader.SubscribeToChanges(tickers =>
            {
                foreach (var ticker in tickers)
                {
                    _tickerStream.WriteToStream(_mapper.Map <TickerUpdate>(ticker));
                }
            });

            _orderbookReader.SubscribeToChanges(orderbooks =>
            {
                foreach (var orderbook in orderbooks)
                {
                    var item = _mapper.Map <Orderbook>(orderbook);
                    item.Asks.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(orderbook.Asks));
                    item.Bids.AddRange(_mapper.Map <List <Orderbook.Types.PriceVolume> >(orderbook.Bids));
                    _orderbookStream.WriteToStream(item, orderbook.AssetPairId);
                }
            });

            _balanceReader.SubscribeToChanges(balances =>
            {
                var balancesByWallet = balances.GroupBy(x => x.WalletId);

                foreach (var walletBalanes in balancesByWallet)
                {
                    var balanceUpdate = new BalanceUpdate();
                    balanceUpdate.Balances.AddRange(_mapper.Map <List <Balance> >(walletBalanes.ToList()));
                    _balanceStream.WriteToStream(balanceUpdate, walletBalanes.Key);
                }
            });

            _orderReader.SubscribeToChanges(ordersEntities =>
            {
                var ordersByWallet = ordersEntities.GroupBy(x => x.WalletId);

                foreach (var walletOrders in ordersByWallet)
                {
                    var orderUpdate = new OrderUpdate();
                    orderUpdate.Orders.AddRange(_mapper.Map <List <Order> >(walletOrders.ToList()));
                    _orderStream.WriteToStream(orderUpdate, walletOrders.Key);
                }
            });

            _tradeReader.SubscribeToChanges(tradeEntities =>
            {
                var tradesByWallet = tradeEntities.GroupBy(x => x.WalletId);

                foreach (var walletTrades in tradesByWallet)
                {
                    var tradeUpdate = new TradeUpdate();

                    tradeUpdate.Trades.AddRange(_mapper.Map <List <Trade> >(walletTrades.ToList()));
                    _tradeStream.WriteToStream(tradeUpdate, walletTrades.Key);
                }
            });

            Console.WriteLine("Stream services started.");
        }