private async Task InitializeOrderBooksAsync() { foreach (var assetIdAssetPair in _lykkeAssetIdsAssetPairs) { CacheProviderOrderBook providerOrderBook = null; try { providerOrderBook = await _orderBookProviderClient.GetOrderBookAsync(assetIdAssetPair.Key); } catch (Exception) { // Some order books can't be found by asset pair id } if (providerOrderBook == null) { continue; } var orderBook = Convert(providerOrderBook); AddOrderBookFromCacheProvider(orderBook); } var lykkeOrderBooksCount = _allOrderBooks.Values.Count(x => x.Source.Equals(LykkeExchangeName, StringComparison.InvariantCultureIgnoreCase)); _log.Info($"Initialized {lykkeOrderBooksCount} of {_lykkeAssetIdsAssetPairs.Count} order books."); }
private OrderBook Convert(CacheProviderOrderBook orderBook) { var bids = new List <VolumePrice>(); var asks = new List <VolumePrice>(); foreach (var limitOrder in orderBook.Prices) { // Filter out negative or zero prices and zero volumes if (limitOrder.Price <= 0 || (decimal)limitOrder.Volume == 0) { continue; } if (limitOrder.Volume > 0) { bids.Add(new VolumePrice((decimal)limitOrder.Price, (decimal)limitOrder.Volume)); } else { asks.Add(new VolumePrice((decimal)limitOrder.Price, Math.Abs((decimal)limitOrder.Volume))); } } var assetPair = _lykkeAssetIdsAssetPairs[orderBook.AssetPair]; var result = new OrderBook(LykkeExchangeName, assetPair, bids, asks, orderBook.Timestamp); return(result); }
private async Task InitializeOrderBooks() { var assetPairs = _assetPairs.Values.ToList(); foreach (var assetPair in assetPairs) { CacheProviderOrderBook providerOrderBook = null; try { providerOrderBook = await _orderBookProviderClient.GetOrderBookAsync(assetPair.Id); } catch (Exception) { // Some order books can't be found by asset pair id } if (providerOrderBook == null) { continue; } var orderBook = Convert(providerOrderBook); AddOrderBookFromCacheProvider(orderBook); } int lykkeOrderBooksCount; lock (_sync) { lykkeOrderBooksCount = _lykkeOrderBooks.Count; } _log.Info($"Initialized {lykkeOrderBooksCount} of {assetPairs.Count} order books."); }