Skip to content

http request doesn't retry when a retryable response code is encountered #342

@thefloat

Description

@thefloat

There "appears" to be an implementation for retrying an http request when certain response codes are encountered--stored in "retry_codes" attribute of _V5HTTPManager. The logic -
https://github.com/bybit-exchange/pybit/blob/ae9201f021d582ae42b29d86d1f4b3ad25e513fe/pybit/_http_manager.py#L277

In reality, pybit doesn't actually retry but instead produces the following exception:

Exception: Retryable error occurred, retrying...

Example
Error Code - 10002 (The request time exceeds the time window range) is in retry_codes by default.
Logs and traceback when Error Code - 10002 is encountered:

08:38:53 [DEBUG] pybit._http_manager:115 Initializing HTTP session.
08:38:53 [DEBUG] urllib3.connectionpool:1049 Starting new HTTPS connection (1): api-demo.bybit.com:443
08:38:56 [DEBUG] urllib3.connectionpool:544 https://api-demo.bybit.com:443 "GET /v5/order/realtime?category=linear&openOnly=0&symbol=BTCUSDT HTTP/1.1" 200 230
08:38:56 [ERROR] pybit._http_manager:314 invalid request, please check your server timestamp or recv_window param: req_timestamp[1769758733519],server_timestamp[1769758736149],recv_window[1000] (ErrCode: 10002). Added 2.5 seconds to recv_window. Retrying...
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "C:\Users\user\livetrader\tests\test_api_helpers.py", line 140, in
main()
~~~~^^
File "C:\Users\user\livetrader\tests\test_api_helpers.py", line 50, in main
test_get_open_orders(trade_manager)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\user\livetrader\tests\test_api_helpers.py", line 92, in test_get_open_orders
order_res = trade_manager.get_open_orders()
File "C:\Users\user\livetrader\modules\trade_manager.py", line 375, in get_open_orders
res = self.session.get_open_orders(**params)
File "C:\Users\user\pybit.venv\Lib\site-packages\pybit_v5_trade.py", line 84, in get_open_orders
return self._submit_request(
~~~~~~~~~~~~~~~~~~~~^
method="GET",
^^^^^^^^^^^^^
...<2 lines>...
auth=True,
^^^^^^^^^^
)
^
File "C:\Users\user\pybit.venv\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\pybit.venv\Lib\site-packages\pybit_http_manager.py", line 279, in _handle_response
raise Exception("Retryable error occurred, retrying...")
Exception: Retryable error occurred, retrying...

#341

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions