Beispiel #1
0
        public void HandleOrderBook(OrderBookPartialResponse response)
        {
            var ob = response.Data;

            _bids = ob.Bids;
            _asks = ob.Asks;
        }
Beispiel #2
0
        private void HandleSnapshot(OrderBookPartialResponse response)
        {
            // received snapshot, convert and stream
            var levels = ConvertSnapshot(response.Data);
            var bulk   = new OrderBookLevelBulk(OrderBookAction.Insert, levels, CryptoOrderBookType.L2)
            {
                ExchangeName   = ExchangeName,
                ServerSequence = response.Data.LastUpdateId
            };

            StreamSnapshot(bulk);
        }
Beispiel #3
0
        /// <summary>
        /// Request a new order book snapshot, will be fakely streamed via communicator (WebsocketClient)
        /// Method doesn't throw exception, just logs it
        /// </summary>
        /// <param name="communicator">Target communicator</param>
        /// <param name="pair">Target pair</param>
        /// <param name="count">Max level count</param>
        public async Task LoadSnapshot(BinanceWebsocketCommunicator communicator, string pair, int count = 1000)
        {
            CryptoValidations.ValidateInput(communicator, nameof(communicator));

            var snapshot = await LoadSnapshotRaw(pair, count);

            if (snapshot == null)
            {
                return;
            }

            OrderBookPartialResponse.StreamFakeSnapshot(snapshot, communicator);
        }
Beispiel #4
0
        private bool HandleObjectMessage(string msg)
        {
            var response = BinanceJsonSerializer.Deserialize <JObject>(msg);

            // ********************
            // ADD OBJECT HANDLERS BELOW
            // ********************

            return

                (TradeResponse.TryHandle(response, Streams.TradesSubject) ||
                 AggregatedTradeResponse.TryHandle(response, Streams.TradeBinSubject) ||
                 OrderBookPartialResponse.TryHandle(response, Streams.OrderBookPartialSubject) ||
                 OrderBookDiffResponse.TryHandle(response, Streams.OrderBookDiffSubject)
                );
        }
Beispiel #5
0
        private void HandleOrderBook(OrderBookPartialResponse response)
        {
            _orderBookStatsComputer.HandleOrderBook(response);

            var stats = _orderBookStatsComputer.GetStats();

            if (stats == OrderBookStats.NULL)
            {
                return;
            }

            _view.Bid = stats.Bid.ToString("#.00");
            _view.Ask = stats.Ask.ToString("#.00");

            _view.BidAmount = $"{stats.BidAmountPerc:###}%{Environment.NewLine}{FormatToMillions(stats.BidAmount)}";
            _view.AskAmount = $"{stats.AskAmountPerc:###}%{Environment.NewLine}{FormatToMillions(stats.AskAmount)}";
        }