Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored binance symbol stream limit #769

Merged
merged 1 commit into from
Apr 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ protected async Task<string> 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++)
Expand Down Expand Up @@ -234,9 +239,15 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
return tickers;
}

protected override Task<IWebSocket> OnGetTickersWebSocketAsync(Action<IReadOnlyCollection<KeyValuePair<string, ExchangeTicker>>> callback, params string[] symbols)
protected override async Task<IWebSocket> OnGetTickersWebSocketAsync(Action<IReadOnlyCollection<KeyValuePair<string, ExchangeTicker>>> 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<KeyValuePair<string, ExchangeTicker>> tickerList = new List<KeyValuePair<string, ExchangeTicker>>();
Expand Down Expand Up @@ -275,11 +286,6 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
{
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
}
string url = await GetWebSocketStreamUrlForSymbolsAsync("@aggTrade", marketSymbols);
return await ConnectPublicWebSocketAsync(url, messageCallback: async (_socket, msg) =>
{
Expand Down