Skip to content

Commit 33ac215

Browse files
authored
fix[binacne]Update binance per connection limit (#1087)
* fix[binacne]Update binance.py per connection limit Now: A single connection can listen to a maximum of 1024 streams. * fix typo * fix address test
1 parent 71a985c commit 33ac215

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cryptofeed/exchanges/binance.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Binance(Feed, BinanceRestMixin):
4545
ORDER_INFO: ORDER_INFO
4646
}
4747
request_limit = 20
48+
per_connection_limit = 1024
4849

4950
@classmethod
5051
def timestamp_normalize(cls, ts: float) -> float:
@@ -135,14 +136,14 @@ def _address(self) -> Union[str, Dict]:
135136
pair = pair.lower()
136137
subs.append(f"{pair}@{stream}")
137138

138-
if 0 < len(subs) < 200:
139+
if 0 < len(subs) < self.per_connection_limit:
139140
return address + '/'.join(subs)
140141
else:
141142
def split_list(_list: list, n: int):
142143
for i in range(0, len(_list), n):
143144
yield _list[i:i + n]
144145

145-
return [address + '/'.join(chunk) for chunk in split_list(subs, 200)]
146+
return [address + '/'.join(chunk) for chunk in split_list(subs, self.per_connection_limit)]
146147

147148
def _reset(self):
148149
self._l2_book = {}

tests/unit/test_binance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_binance_address_generation():
2222
sub = random.sample(symbols, length)
2323
addr = Binance(symbols=sub, channels=channels)._address()
2424

25-
if length * len(channels) < 200:
25+
if length * len(channels) < 1024:
2626
assert isinstance(addr, str)
2727
value = addr.split("=", 1)[1]
2828
value = value.split("/")

0 commit comments

Comments
 (0)