From 3f855fb47bdc948bc7bc43dee81103a48873fb08 Mon Sep 17 00:00:00 2001 From: Victor Lee Date: Sun, 24 Apr 2022 16:08:07 -0700 Subject: [PATCH] refactored binance symbol stream limit - to apply to all websocket streams --- .../BinanceGroup/BinanceGroupCommon.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs b/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs index 90612190..d875e63f 100644 --- a/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs +++ b/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs @@ -32,6 +32,11 @@ protected async Task GetWebSocketStreamUrlForSymbolsAsync(string suffix, { marketSymbols = (await GetMarketSymbolsAsync()).ToArray(); } + if (marketSymbols.Length > 400) + { + marketSymbols = marketSymbols.Take(400).ToArray(); + Logger.Warn("subscribing to the first 400 symbols"); // binance does not allow subscribing to more than 400 symbols at a time + } StringBuilder streams = new StringBuilder("/stream?streams="); for (int i = 0; i < marketSymbols.Length; i++) @@ -234,9 +239,15 @@ protected override async Task>> return tickers; } - protected override Task OnGetTickersWebSocketAsync(Action>> callback, params string[] symbols) + protected override async Task OnGetTickersWebSocketAsync(Action>> callback, params string[] symbols) { - return ConnectPublicWebSocketAsync("/stream?streams=!ticker@arr", async (_socket, msg) => + string url = null; + if (symbols == null || symbols.Length == 0) + { + url = "/stream?streams=!ticker@arr"; + } + else url = await GetWebSocketStreamUrlForSymbolsAsync("@ticker", symbols); + return await ConnectPublicWebSocketAsync(url, async (_socket, msg) => { JToken token = JToken.Parse(msg.ToStringFromUTF8()); List> tickerList = new List>(); @@ -275,11 +286,6 @@ protected override async Task OnGetTradesWebSocketAsync(Func 400) - { - marketSymbols = marketSymbols.Take(400).ToArray(); - Logger.Warn("subscribing to the first 400 symbols"); // binance does not allow subscribing to more than 400 symbols at a time - } string url = await GetWebSocketStreamUrlForSymbolsAsync("@aggTrade", marketSymbols); return await ConnectPublicWebSocketAsync(url, messageCallback: async (_socket, msg) => {