示例#1
0
        private void Snapshot(dynamic data)
        {
            var currencyPair = _currencyMapper.GetCurrency((string)data.product_id);
            var orderBook    = new OrderBook
            {
                CurrencyPair = currencyPair
            };

            foreach (var bid in data.bids)
            {
                var bookItem = new OrderBookItem()
                {
                    Price  = DecimalHelper.Get((string)bid[0]),
                    Volume = DecimalHelper.Get((string)bid[1]),
                };
                orderBook.Bids.Add(bookItem);
            }
            foreach (var ask in data.asks)
            {
                var bookItem = new OrderBookItem()
                {
                    Price  = DecimalHelper.Get((string)ask[0]),
                    Volume = DecimalHelper.Get((string)ask[1]),
                };
                orderBook.Asks.Add(bookItem);
            }
            SortBids(orderBook);
            SortAsks(orderBook);
            _orderBookDict[currencyPair] = orderBook;
            OrderBookChanged?.Invoke(orderBook.CurrencyPair, orderBook);
        }
示例#2
0
        private void RegisterOrderBookChannel(Pusher pusher, CurrencyPair pair)
        {
            var orderBookChannel = pusher.Subscribe($"order_book{GetSubscriptionName(pair)}");

            orderBookChannel.Subscribed += _chatChannel_Subscribed;

            orderBookChannel.Bind("data", (dynamic data) =>
            {
                _dateLastUpdated       = DateTime.UtcNow;
                var orderBook          = new OrderBook();
                orderBook.CurrencyPair = pair;
                foreach (var bid in data.bids)
                {
                    var orderBookItem = new OrderBookItem
                    {
                        Volume = bid[1],
                        Price  = bid[0]
                    };
                    orderBook.Bids.Add(orderBookItem);
                }
                foreach (var ask in data.asks)
                {
                    var orderBookItem = new OrderBookItem
                    {
                        Volume = ask[1],
                        Price  = ask[0]
                    };
                    orderBook.Asks.Add(orderBookItem);
                }
                _orderBookDict[pair] = orderBook;
                OrderBookChanged?.Invoke(pair, orderBook);
            });
        }
示例#3
0
        /// <summary>Update the list of buy/sell orders</summary>
        public void UpdateOrderBooks(IList <Offer> b2q, IList <Offer> q2b)
        {
            B2Q.Offers.Assign(b2q);
            Q2B.Offers.Assign(q2b);

            Debug.Assert(AssertOrdersValid());
            OrderBookChanged?.Invoke(this, EventArgs.Empty);
        }
示例#4
0
        private void OnOrderBookChanged()
        {
            OrderBookChanged?.Invoke(OrderBookAdapter);

            if (Pair != null)
            {
                UsdRateChanged?.Invoke(Pair.Market.UsdEquivalent.UsdRate(Pair.Pair.BaseCurrency));
            }
        }
示例#5
0
 private void L2Update(dynamic data)
 {
     try
     {
         var currencyPair = _currencyMapper.GetCurrency((string)data.product_id);
         var orderBook    = _orderBookDict[currencyPair];
         foreach (var change in data.changes)
         {
             var tradeType = (string)change[0];
             var price     = DecimalHelper.Get((string)change[1]);
             var volume    = DecimalHelper.Get((string)change[2]);
             if (tradeType == "buy")
             {
                 var bid = orderBook.Bids.FirstOrDefault(it => it.Price == price);
                 if (volume == 0)
                 {
                     if (bid != null)
                     {
                         orderBook.Bids.Remove(bid);
                         SortBids(orderBook);
                     }
                 }
                 else
                 {
                     if (bid != null)
                     {
                         bid.Volume = volume;
                     }
                     else
                     {
                         bid = new OrderBookItem()
                         {
                             Price  = price,
                             Volume = volume
                         };
                         orderBook.Bids.Add(bid);
                         SortBids(orderBook);
                     }
                 }
             }
             else
             {
                 var ask = orderBook.Asks.FirstOrDefault(it => it.Price == price);
                 if (volume == 0)
                 {
                     if (ask != null)
                     {
                         orderBook.Asks.Remove(ask);
                         SortAsks(orderBook);
                     }
                 }
                 if (ask != null)
                 {
                     ask.Volume = volume;
                 }
                 else
                 {
                     ask = new OrderBookItem()
                     {
                         Price  = price,
                         Volume = volume
                     };
                     orderBook.Asks.Add(ask);
                     SortAsks(orderBook);
                 }
             }
             OrderBookChanged?.Invoke(currencyPair, orderBook);
         }
     }
     catch (Exception)
     {
         //Todo:log data format error
     }
 }