public OrderBookEventArgs(BitmexOrderL2Book orders) : this()
        {
            OrderBook = new OrderBook();
            var asks = new List <Order>();
            var bids = new List <Order>();

            foreach (var order in orders.Data)
            {
                if (order.OrderSide == OrderSide.ASK)
                {
                    asks.Add(new Order {
                        Price = order.Price.Value, Amount = order.Size
                    });
                }
                else
                {
                    bids.Add(new Order {
                        Price = order.Price.Value, Amount = order.Size
                    });
                }
            }

            OrderBook.Asks = asks.ToArray();
            OrderBook.Bids = bids.ToArray();
        }
Esempio n. 2
0
        public string ProcessBook(BitmexOrderL2Book book, ref double bid, ref double ask)
        {
            SortedList <long, double> bids = null;
            string symbol   = null;
            double tickSize = 0;
            int    idx      = 0;

            bool delete = book.Action.StartsWith("del");

            if (!delete)
            {
                bool create = book.Action.StartsWith("ins") || book.Action.StartsWith("upd") || book.Action.StartsWith("par");
                if (!create)
                {
                    return(symbol);
                }
            }
            if (book.Data.Length > 0)
            {
                symbol   = book.Data[0].Symbol;
                bids     = _bids[symbol];
                idx      = _indexes[symbol];
                tickSize = symbol.StartsWith("XBT") ? 0.01 : _tickSizes[symbol]; // LEGACY_TICKS = {"XBTUSD":0.01}
            }
            foreach (var item in book.Data)
            {
                if (item.OrderSide == DataType.OrderSide.BID)
                {
                    if (delete)
                    {
                        if (bids.ContainsKey(item.Id))
                        {
                            bids.Remove(item.Id);
                        }
                    }
                    else
                    {
                        if (!bids.ContainsKey(item.Id))
                        {
                            var price = GetPriceById(item.Id, idx, tickSize);
                            bids.Add(item.Id, price);
                        }
                    }
                }
            }
            if (_bids.Count > 0)
            {
                if (_bids[symbol].Count > 0)
                {
                    var k = _bids[symbol].Keys[0];
                    bid = _bids[symbol][k];
                    ask = bid + _tickSizes[symbol];
                }
            }
            return(symbol);
        }
Esempio n. 3
0
        private void ProcessOrderBookRequest(BitmexOrderL2Book obj)
        {
            double bid = 0, ask = 0;
            string symbol = null;

            lock (_obj) symbol = _bookL2.ProcessBook(obj, ref bid, ref ask);
            if (symbol == null)
            {
                return;
            }

            var args = new ExchangePricesEventArgs(bid, ask, symbol);

            args.CreatedAt = DateTime.UtcNow;

            Task.Run(() =>
            {
                if (args.BtcPrice != null)
                {
                    if (XbtOrderBookChanged != null)
                    {
                        XbtOrderBookChanged(this, args);
                    }
                }
                else if (args.EthPrice != null)
                {
                    if (EthOrderBookChanged != null)
                    {
                        EthOrderBookChanged(this, args);
                    }
                }
                else if (args.LtcPrice != null)
                {
                    if (LtcOrderBookChanged != null)
                    {
                        LtcOrderBookChanged(this, args);
                    }
                }
                else if (args.EosPrice != null)
                {
                    if (EosOrderBookChanged != null)
                    {
                        EosOrderBookChanged(this, args);
                    }
                }
                else if (args.XrpPrice != null)
                {
                    if (XrpOrderBookChanged != null)
                    {
                        XrpOrderBookChanged(this, args);
                    }
                }
                else if (args.TrxPrice != null)
                {
                    if (TrxOrderBookChanged != null)
                    {
                        TrxOrderBookChanged(this, args);
                    }
                }
                else if (args.AdaPrice != null)
                {
                    if (AdaOrderBookChanged != null)
                    {
                        AdaOrderBookChanged(this, args);
                    }
                }
                else if (args.BchPrice != null)
                {
                    if (BchOrderBookChanged != null)
                    {
                        BchOrderBookChanged(this, args);
                    }
                }
            });

            if (args.BtcPrice != null)
            {
                XbtPriceChanged(this, args);
            }
            else if (args.EthPrice != null)
            {
                EthPriceChanged(this, args);
            }
            else if (args.LtcPrice != null)
            {
                LtcPriceChanged(this, args);
            }
            else if (args.EosPrice != null)
            {
                EosPriceChanged(this, args);
            }
            else if (args.XrpPrice != null)
            {
                XrpPriceChanged(this, args);
            }
            else if (args.AdaPrice != null)
            {
                AdaPriceChanged(this, args);
            }
            else if (args.TrxPrice != null)
            {
                TrxPriceChanged(this, args);
            }
            else if (args.BchPrice != null)
            {
                BchPriceChanged(this, args);
            }
        }