public void Start() { _pricesReader.SubscribeToChanges(prices => { var tasks = new List <Task>(); foreach (var price in prices) { tasks.Add(_priceStream.WriteToStreamAsync(_mapper.Map <PriceUpdate>(price), price.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _candlesReader.SubscribeToChanges(candles => { var tasks = new List <Task>(); foreach (var candle in candles) { var key = $"{candle.AssetPairId}_{candle.PriceType}_{candle.TimeInterval}"; tasks.Add(_candlesStream.WriteToStreamAsync(_mapper.Map <CandleUpdate>(candle), key)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _tickersReader.SubscribeToChanges(tickers => { var tasks = new List <Task>(); foreach (var ticker in tickers) { var priceEntity = _pricesReader.Get(PriceEntity.GetPk(), ticker.AssetPairId); var priceUpdate = new PriceUpdate { AssetPairId = ticker.AssetPairId, VolumeBase24H = ticker.VolumeBase.ToString(CultureInfo.InvariantCulture), VolumeQuote24H = ticker.VolumeQuote.ToString(CultureInfo.InvariantCulture), PriceChange24H = ticker.PriceChange.ToString(CultureInfo.InvariantCulture), Timestamp = Timestamp.FromDateTime(ticker.UpdatedDt.ToUniversalTime()) }; if (priceEntity != null) { priceUpdate.Ask = priceEntity.Ask.ToString(CultureInfo.InvariantCulture); priceUpdate.Bid = priceEntity.Bid.ToString(CultureInfo.InvariantCulture); } tasks.Add(_priceStream.WriteToStreamAsync(priceUpdate, priceUpdate.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _orderbooksReader.SubscribeToChanges(orderbooks => { var tasks = new List <Task>(); 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)); tasks.Add(_orderbookStream.WriteToStreamAsync(item, orderbook.AssetPairId)); } Task.WhenAll(tasks).GetAwaiter().GetResult(); }); _sessionsReader.SubscribeToChanges(sessions => { }); Console.WriteLine("Stream services started."); }
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."); }