Skip to content

Rate limit error. Response from bybit without X-Bapi-Limit-Reset-Timestamp #340

@gersichka

Description

@gersichka

pybit=="5.13.0"

Hi!
Im calling get_kline like this:

klines = self.session.get_kline(
                      category="linear",
                      symbol= symbol,
                      interval=timeframe,
                      start = date_from,
                      end=date_to,
                      limit=limit
                      )

Exception accured once

2026-01-24 21:00:02,121-MainProcess-urllib3.connectionpool-[connectionpool.py:289]-[DEBUG] - Resetting dropped connection: api.bybit.com
2026-01-24 21:00:03,039-MainProcess-urllib3.connectionpool-[connectionpool.py:544]-[DEBUG] - https://api.bybit.com:443 "GET /v5/market/kline?category=linear&interval=15&limit=500&symbol=ETHUSDT HTTP/1.1" 200 123
2026-01-24 21:00:03,041-MainProcess-pybit._http_manager-[_http_manager.py:308]-[ERROR] - Too many visits. Exceeded the API Rate Limit. (ErrCode: 10006). Hit the API rate limit on https://api.bybit.com/v5/market/kline?category=linear&interval=15&limit=500&symbol=ETHUSDT. Sleeping then trying again.
2026-01-24 21:00:03,044-MainProcess-realtime_robot-[RealtimeRobot.py:222]-[CRITICAL] - Unexpected error accued: 'x-bapi-limit-reset-timestamp', stopping
Traceback (most recent call last):
...
  File "C:\Users\user\OneDrive\projects\trading_assistant\trading_assistant\data_connectors\ByBitConnector.py", line 198, in get_rates_for_current_day
    rates = (self._get_kline(symbol,None,None,timeframe,amount_of_bars))['result']['list']
             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

"ByBitConnector.py", line 156, in _get_kline
    klines = self.session.get_kline(
                                category="linear",
    ...<4 lines>...
                                limit=limit
                                )
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pybit\_v5_market.py", line 33, in get_kline
    return self._submit_request(
           ~~~~~~~~~~~~~~~~~~~~^
        method="GET",
        ^^^^^^^^^^^^^
        path=f"{self.endpoint}{Market.GET_KLINE}",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        query=kwargs,
        ^^^^^^^^^^^^^
    )
    ^
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pybit\_http_manager.py", line 197, in _submit_request
    return self._handle_response(response, method, path, req_params, recv_window, retries_attempted)
           ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pybit\_http_manager.py", line 278, in _handle_response
    self._handle_retryable_error(response, error_code, error_msg, recv_window)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\pybit\_http_manager.py", line 309, in _handle_retryable_error
    limit_reset_time = int(response.headers["X-Bapi-Limit-Reset-Timestamp"])
                           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user\AppData\Local\Programs\Python\Python313\Lib\site-packages\requests\structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
           ~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'x-bapi-limit-reset-timestamp'

On _http_manager.py", line 309, in _handle_retryable_error
limit_reset_time = int(response.headers["X-Bapi-Limit-Reset-Timestamp"])
Somehow bybit doesn't set "X-Bapi-Limit-Reset-Timestamp" in their response wich leaded to the unhandled KeyError

Metadata

Metadata

Assignees

No one assigned

    Labels

    prioritizedThis issue is confirmed and we're working on it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions