Пример #1
0
        public IReadOnlyList <OrderBook> GetFilteredByWallets()
        {
            var allOrderBooks = GetAll();

            var wallets = GetSettings().Wallets;

            if (!wallets.Any())
            {
                return(allOrderBooks);
            }

            var result = new List <OrderBook>();

            foreach (var orderBook in allOrderBooks)
            {
                var newBids = orderBook.Bids.Where(x => wallets.Keys.Contains(x.WalletId)).ToList();
                var newAsks = orderBook.Asks.Where(x => wallets.Keys.Contains(x.WalletId)).ToList();

                if (!newBids.Any() && !newAsks.Any())
                {
                    continue;
                }

                var newOrderBook = new OrderBook(orderBook.Source, orderBook.AssetPair, newBids, newAsks, orderBook.Timestamp);
                result.Add(newOrderBook);
            }

            return(result);
        }
Пример #2
0
        private static OrderBook Convert(CacheProviderOrderBook orderBook)
        {
            var bids = new List <LimitOrder>();
            var asks = new List <LimitOrder>();

            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 LimitOrder(limitOrder.Id, limitOrder.ClientId, (decimal)limitOrder.Price, (decimal)limitOrder.Volume));
                }
                else
                {
                    asks.Add(new LimitOrder(limitOrder.Id, limitOrder.ClientId, (decimal)limitOrder.Price, Math.Abs((decimal)limitOrder.Volume)));
                }
            }

            var result = new OrderBook(LykkeExchangeName, new AssetPair(orderBook.AssetPair), bids, asks, orderBook.Timestamp);

            return(result);
        }
Пример #3
0
        private void AddOrderBookFromCacheProvider(OrderBook orderBook)
        {
            if (!_assetPairs.ContainsKey(orderBook.AssetPair.Id))
            {
                return;
            }

            orderBook.SetAssetPair(_assetPairs[orderBook.AssetPair.Id]);

            lock (_sync)
            {
                if (!_dirtyLykkeOrderBooks.ContainsKey(orderBook.AssetPair.Id))
                {
                    _dirtyLykkeOrderBooks.Add(orderBook.AssetPair.Id, orderBook);
                }
                else
                {
                    // Update half only if it doesn't exist
                    var dirtyOrderBook = _dirtyLykkeOrderBooks[orderBook.AssetPair.Id];

                    var newBids = dirtyOrderBook.Bids ?? orderBook.Bids;
                    var newAsks = dirtyOrderBook.Asks ?? orderBook.Asks;

                    var newOrderBook = new OrderBook(orderBook.Source, orderBook.AssetPair, newBids, newAsks, orderBook.Timestamp);
                    _dirtyLykkeOrderBooks[orderBook.AssetPair.Id] = newOrderBook;
                }
            }

            MoveFromDirtyToMain(orderBook.AssetPair.Id);
        }
Пример #4
0
        public Task HandleAsync(OrderBook orderBook)
        {
            if (!_assetPairs.ContainsKey(orderBook.AssetPair.Id))
            {
                return(Task.CompletedTask);
            }

            orderBook.SetAssetPair(_assetPairs[orderBook.AssetPair.Id]);

            lock (_sync)
            {
                if (!_dirtyLykkeOrderBooks.ContainsKey(orderBook.AssetPair.Id))
                {
                    _dirtyLykkeOrderBooks.Add(orderBook.AssetPair.Id, orderBook);
                }
                else
                {
                    // Update half even if it already exists
                    var dirtyOrderBook = _dirtyLykkeOrderBooks[orderBook.AssetPair.Id];

                    var newBids = orderBook.Bids ?? dirtyOrderBook.Bids;
                    var newAsks = orderBook.Asks ?? dirtyOrderBook.Asks;

                    var newOrderBook = new OrderBook(orderBook.Source, orderBook.AssetPair, newBids, newAsks, orderBook.Timestamp);
                    _dirtyLykkeOrderBooks[orderBook.AssetPair.Id] = newOrderBook;
                }
            }

            MoveFromDirtyToMain(orderBook.AssetPair.Id);

            return(Task.CompletedTask);
        }
Пример #5
0
        private IReadOnlyList <string> GetMarketMakers(OrderBook orderBook)
        {
            var result = new List <string>();

            var wallets   = GetSettings().Wallets;
            var walletIds = wallets.Keys;

            if (!wallets.Any())
            {
                return(result);
            }

            var bidsWalletIds     = orderBook.Bids.Select(x => x.WalletId).Intersect(walletIds);
            var asksWalletIds     = orderBook.Asks.Select(x => x.WalletId).Intersect(walletIds);
            var allFoundWalletIds = bidsWalletIds.Union(asksWalletIds);

            foreach (var walletId in allFoundWalletIds)
            {
                result.Add(wallets[walletId]);
            }

            return(result.Distinct().OrderBy(x => x).ToList());
        }