cryptofeed
cryptofeed copied to clipboard
kucoin with candles : {'code': 509, 'data': 'exceed max permits per 10 seconds'}
Describe the bug
While I encounter no problems with TRADE, it is different with CANDLES.
I am getting this 'code': 509, 'data': 'exceed max permits per 10 seconds'
error.
1203 tickers
2022-04-30 10:44:28,417 : WARNING : KUCOIN: error from exchange {'id': 'XMFzvWJeHw', 'type': 'error', 'code': 509, 'data': 'exceed max permits per 10 seconds'}
2022-04-30 10:44:28,418 : WARNING : KUCOIN: error from exchange {'id': 'XMFzvWJeHx', 'type': 'error', 'code': 509, 'data': 'exceed max permits per 10 seconds'}
2022-04-30 10:44:28,419 : WARNING : KUCOIN: error from exchange {'id': 'XMFzvWJeHy', 'type': 'error', 'code': 509, 'data': 'exceed max permits per 10 seconds'}
2022-04-30 10:44:28,490 : WARNING : KUCOIN.ws.6: encountered connection issue no close frame received or sent - reconnecting in 1.0 seconds...
Traceback (most recent call last):
File "/home/karl/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 945, in transfer_data
message = await self.read_message()
File "/home/karl/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1015, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "/home/karl/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1090, in read_data_frame
frame = await self.read_frame(max_size)
File "/home/karl/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1149, in read_frame
extensions=self.extensions,
File "/home/karl/.local/lib/python3.7/site-packages/websockets/legacy/framing.py", line 70, in read
data = await reader(2)
File "/usr/lib/python3.7/asyncio/streams.py", line 677, in readexactly
raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes
To Reproduce
from cryptofeed.defines import TRADES
from cryptofeed.defines import CANDLES
from cryptofeed.exchanges import KuCoin
from cryptofeed.feedhandler import FeedHandler
from cryptofeed.callback import TradeCallback
from cryptofeed.callback import CandleCallback
async def trade(*args):
print(args)
async def candle(*args):
print(args)
pairs = KuCoin.info()['symbols']
channels=[CANDLES]
f = FeedHandler()
f.add_feed( KuCoin( symbols=pairs[0:300], channels=channels, callbacks={TRADES: TradeCallback(trade), CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[300:600], channels=channels, callbacks={TRADES: TradeCallback(trade), CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[600:900], channels=channels, callbacks={TRADES: TradeCallback(trade), CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[900:1200], channels=channels, callbacks={TRADES: TradeCallback(trade), CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[1200:1500], channels=channels, callbacks={TRADES: TradeCallback(trade), CANDLES: CandleCallback(candle)}))
f.run()
Operating System: Linux Debian
Cryptofeed Version Pip installed, cryptofeed 2.2.0
Some more info, using 100 symbols as below it works,
Works:
channels = [CANDLES]
f = FeedHandler()
f.add_feed( KuCoin( symbols=pairs[0:100], channels=channels, callbacks={CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[100:200], channels=channels, callbacks={CANDLES: CandleCallback(candle)}))
...
f.add_feed( KuCoin( symbols=pairs[1100:1200], channels=channels, callbacks={CANDLES: CandleCallback(candle)}))
f.add_feed( KuCoin( symbols=pairs[1200:1300], channels=channels, callbacks={CANDLES: CandleCallback(candle)}))
as soon as >=101 symbols are used, it gives the {code:509, data:'exceed max permits per seconds'}
.
The labelling of the error is weird (suggests too much bytes sent per seconds).
python.py
has:
def __init__(self, **kwargs):
address_info = self.http_sync.write('https://api.kucoin.com/api/v1/bullet-public', json=True)
token = address_info['data']['token']
address = address_info['data']['instanceServers'][0]['endpoint']
address = f"{address}?token={token}"
self.websocket_endpoints = [WebsocketEndpoint(address, options={'ping_interval': address_info['data']['instanceServers'][0]['pingInterval'] / 2000})]
super().__init__(**kwargs)
if any([len(self.subscription[chan]) > 300 for chan in self.subscription]):
raise ValueError("Kucoin has a limit of 300 symbols per connection")
self.__reset()
For me on kucoin, a limit of 300 works for trades, but not for candles.