Beispiel #1
0
        /// <summary>
        /// Stream <see cref="MarketDepth"/> updates
        /// </summary>
        /// <param name="marketDepth">Market depth</param>
        public void StreamUpdates(MarketDepth marketDepth)
        {
            if (marketDepth == null)
            {
                throw new ArgumentNullException(nameof(marketDepth));
            }

            _webSocketClient.ConnectToDepthWebSocket(
                marketDepth.Symbol,
                marketData => marketDepth.UpdateDepth(marketData.AskDepthDeltas, marketData.BidDepthDeltas, marketData.UpdateId));
        }
        /// <summary>
        /// Stream <see cref="MarketDepth"/> updates
        /// </summary>
        /// <param name="marketDepth">Market depth</param>
        /// <param name="updateInterval"></param>
        public void StreamUpdates(MarketDepth marketDepth, TimeSpan?updateInterval = default)
        {
            if (marketDepth == null)
            {
                throw new ArgumentNullException(nameof(marketDepth));
            }

            _webSocketClient.Spot.SubscribeToOrderBookUpdatesAsync(
                marketDepth.Symbol,
                (int)updateInterval?.TotalMilliseconds,
                marketData => marketDepth.UpdateDepth(marketData.Data.Asks, marketData.Data.Bids, marketData.Data.LastUpdateId));
        }
Beispiel #3
0
 /// <param name="symbol"></param>
 /// <param name="marketStrategy"></param>
 /// <param name="webSocketClient"></param>
 /// <param name="logger"></param>
 /// <param name="binanceRestClient"></param>
 /// <exception cref="ArgumentNullException"><paramref name="symbol"/> cannot be <see langword="null"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="marketStrategy"/> cannot be <see langword="null"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="webSocketClient"/> cannot be <see langword="null"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="binanceRestClient"/> cannot be <see langword="null"/></exception>
 public MarketMakerBot(
     string symbol,
     NaiveMarketMakerStrategy marketStrategy,
     IBinanceClient binanceRestClient,
     IBinanceSocketClient webSocketClient,
     Logger logger) :
     base(symbol, marketStrategy, logger)
 {
     _marketDepth       = new MarketDepth(symbol);
     _binanceRestClient = binanceRestClient ?? throw new ArgumentNullException(nameof(binanceRestClient));
     _webSocketClient   = webSocketClient ?? throw new ArgumentNullException(nameof(webSocketClient));
 }
Beispiel #4
0
        /// <summary>
        /// Build <see cref="MarketDepth"/>
        /// </summary>
        /// <param name="marketDepth">Market depth</param>
        /// <param name="limit">Limit of returned orders count</param>
        public async Task BuildAsync(MarketDepth marketDepth, int limit = 100)
        {
            if (marketDepth == null)
            {
                throw new ArgumentNullException(nameof(marketDepth));
            }
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            OrderBookResponse orderBook = await _restClient.GetOrderBookAsync(marketDepth.Symbol, false, limit);

            marketDepth.UpdateDepth(orderBook.Asks, orderBook.Bids, orderBook.LastUpdateId);
        }
        /// <summary>
        /// Build <see cref="MarketDepth"/>
        /// </summary>
        /// <param name="marketDepth">Market depth</param>
        /// <param name="limit">Limit of returned orders count</param>
        public async Task BuildAsync(MarketDepth marketDepth, short limit = 10)
        {
            if (marketDepth == null)
            {
                throw new ArgumentNullException(nameof(marketDepth));
            }
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }

            WebCallResult <BinanceOrderBook> response = await _restClient.Spot.Market.GetOrderBookAsync(marketDepth.Symbol, limit);

            BinanceOrderBook orderBook = response.Data;

            marketDepth.UpdateDepth(orderBook.Asks, orderBook.Bids, orderBook.LastUpdateId);
        }