Skip to content

Commit b90fa9b

Browse files
committed
Revery concurrent_http changes and snapshot refresh changes due to bugs
1 parent 90b55ef commit b90fa9b

File tree

10 files changed

+801
-1859
lines changed

10 files changed

+801
-1859
lines changed

cryptofeed/exchanges/binance.py

Lines changed: 34 additions & 217 deletions
Large diffs are not rendered by default.

cryptofeed/exchanges/binance_futures.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
Please see the LICENSE file for the terms and conditions
55
associated with this software.
66
'''
7-
from asyncio import create_task
87
from decimal import Decimal
98
import logging
109
from typing import List, Tuple, Callable, Dict
1110

1211
from yapic import json
1312

14-
from cryptofeed.connection import AsyncConnection, HTTPPoll, HTTPConcurrentPoll
13+
from cryptofeed.connection import AsyncConnection, HTTPPoll
1514
from cryptofeed.defines import BALANCES, BINANCE_FUTURES, BUY, FUNDING, LIMIT, LIQUIDATIONS, MARKET, OPEN_INTEREST, ORDER_INFO, POSITIONS, SELL
1615
from cryptofeed.exchanges.binance import Binance
1716
from cryptofeed.exchanges.mixins.binance_rest import BinanceFuturesRestMixin
@@ -98,7 +97,7 @@ def connect(self) -> List[Tuple[AsyncConnection, Callable[[None], None], Callabl
9897
ret = []
9998
if self.address:
10099
ret = super().connect()
101-
PollCls = HTTPConcurrentPoll if self.concurrent_http else HTTPPoll
100+
PollCls = HTTPPoll
102101
for chan in set(self.subscription):
103102
if chan == 'open_interest':
104103
addrs = [f"{self.rest_endpoint}/openInterest?symbol={pair}" for pair in self.subscription[chan]]
@@ -244,10 +243,7 @@ async def message_handler(self, msg: str, conn: AsyncConnection, timestamp: floa
244243

245244
# Handle REST endpoint messages first
246245
if 'openInterest' in msg:
247-
coro = self._open_interest(msg, timestamp)
248-
if self.concurrent_http:
249-
return create_task(coro)
250-
return await coro
246+
return await self._open_interest(msg, timestamp)
251247

252248
# Handle account updates from User Data Stream
253249
if self.requires_authentication:

examples/demo_concurrent_proxy.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
OrderBooks require a snapshot on initial subscription, hence connecting to a lot of symbols will eat up rate limits.
33
44
Use a 'http_proxy' to bypass this limitation.
5-
Use 'concurrent_http' to make concurrent HTTP requests (used in polling and http GETs)
65
76
Notes:
87
1. 'http_proxy' will only be used for GET requests (not Websockets). For more information visit https://docs.aiohttp.org/en/stable/client_reference.html
@@ -34,8 +33,8 @@ def all_found(self):
3433
return False
3534
return True
3635

37-
def callback(self, exchange, channel, symbols, concurrent_http):
38-
concurrency = "[concurrent_http]" if concurrent_http else "[sync_http]"
36+
def callback(self, exchange, channel, symbols):
37+
concurrency = "[sync_http]"
3938
key = f'{exchange}:{channel} {concurrency}'
4039
self.counts[key] = defaultdict(int)
4140
self.total[key] = len(symbols)
@@ -83,28 +82,24 @@ def main(proxy):
8382
f = FeedHandler()
8483
counter = Counter(f)
8584
f.add_feed(Binance(depth_interval='1000ms',
86-
concurrent_http=False,
8785
http_proxy=proxy,
8886
max_depth=1,
8987
symbols=book_symbols,
9088
channels=[L2_BOOK],
9189
callbacks={L2_BOOK: counter.callback(BINANCE, L2_BOOK, book_symbols, False)}))
9290
f.add_feed(Binance(depth_interval='1000ms',
93-
concurrent_http=True,
9491
http_proxy=proxy,
9592
max_depth=1,
9693
symbols=book_symbols,
9794
channels=[L2_BOOK],
9895
callbacks={L2_BOOK: counter.callback(BINANCE, L2_BOOK, book_symbols, True)}))
9996
f.add_feed(BinanceFutures(http_proxy=proxy,
10097
open_interest_interval=1.0,
101-
concurrent_http=False,
10298
symbols=futures_symbols,
10399
channels=[OPEN_INTEREST],
104100
callbacks={OPEN_INTEREST: counter.callback(BINANCE_FUTURES, OPEN_INTEREST, futures_symbols, False)}))
105101
f.add_feed(BinanceFutures(http_proxy=proxy,
106102
open_interest_interval=1.0,
107-
concurrent_http=True,
108103
symbols=futures_symbols,
109104
channels=[OPEN_INTEREST],
110105
callbacks={OPEN_INTEREST: counter.callback(BINANCE_FUTURES, OPEN_INTEREST, futures_symbols, True)}))

sample_data/BINANCE.0

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

sample_data/BINANCE.http.0.0

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

sample_data/BINANCE.ws.1.0

Lines changed: 267 additions & 1004 deletions
Large diffs are not rendered by default.

sample_data/BINANCE_US.0

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

sample_data/BINANCE_US.http.0.0

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

sample_data/BINANCE_US.ws.1.0

Lines changed: 481 additions & 610 deletions
Large diffs are not rendered by default.

tests/unit/test_exchange.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
lookup_table = {
2222
BEQUANT: {L2_BOOK: 978, TICKER: 1235, TRADES: 4040, CANDLES: 4040},
23-
BINANCE: {L2_BOOK: 532, TICKER: 412, TRADES: 28, CANDLES: 17},
24-
BINANCE_US: {TICKER: 241, TRADES: 3, L2_BOOK: 358, CANDLES: 3},
23+
BINANCE: {L2_BOOK: 176, TICKER: 84, TRADES: 2, CANDLES: 2},
24+
BINANCE_US: {TICKER: 128, TRADES: 11, L2_BOOK: 336, CANDLES: 5},
2525
BINANCE_FUTURES: {CANDLES: 67, L2_BOOK: 756, TICKER: 613, TRADES: 91},
2626
BINANCE_DELIVERY: {L2_BOOK: 1798, TICKER: 2240, TRADES: 51, CANDLES: 33},
2727
FMFW: {L2_BOOK: 1748, TICKER: 75, TRADES: 4, CANDLES: 4},

0 commit comments

Comments
 (0)