-
Notifications
You must be signed in to change notification settings - Fork 200
fix: retry http request on receiving a retriable error code from bybit #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ | |||
|
|
||||
| from datetime import datetime as dt, timezone | ||||
|
|
||||
| from .exceptions import FailedRequestError, InvalidRequestError | ||||
| from .exceptions import FailedRequestError, InvalidRequestError, RetryableError | ||||
| from . import _helpers | ||||
|
|
||||
| # Requests will use simplejson if available. | ||||
|
|
@@ -201,6 +201,9 @@ def _submit_request(self, method=None, path=None, query=None, auth=False): | |||
| self._handle_network_error(e, retries_attempted) | ||||
| except JSONDecodeError as e: | ||||
| self._handle_json_error(e, retries_attempted) | ||||
| except RetryableError as e: | ||||
| self._handle_retryable_error(e.response, e.status_code, e.message, recv_window) | ||||
|
|
||||
|
|
||||
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -56,3 +56,21 @@ def __init__(self, request, message, status_code, time, resp_headers): | |||||
| f"{message} (ErrCode: {status_code}) (ErrTime: {time})" | ||||||
| f".\nRequest → {request}." | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| class RetryableError(Exception): | ||||||
| """ | ||||||
| Exception raised for retryable bybit error code | ||||||
|
||||||
| Exception raised for retryable bybit error code | |
| Exception raised for retryable Bybit error code |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring states "Attributes: response -- Response object" but the attribute name in the code is "response", not matching the naming convention seen in other exception classes like InvalidRequestError and FailedRequestError which use more descriptive names like "request", "message", "status_code", "time", and "resp_headers". For consistency, consider documenting what type of response object this is (e.g., "response -- HTTP Response object from requests library").
| response -- Response object | |
| response -- HTTP response object (for example, a Response instance from the requests library). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recv_window parameter modifications in _handle_retryable_error will not persist across retries. When error code 10002 is encountered, _handle_retryable_error adds 2500 to recv_window (line 312), but since recv_window is an integer (immutable in Python), this modification is lost when the exception handler returns and the retry loop continues. The next retry will still use the original recv_window value from line 182. This means the recv_window adjustment feature for error code 10002 is non-functional. Consider making recv_window an instance variable or returning the updated value from _handle_retryable_error and using it in subsequent iterations.