Skip to content
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

Ignoring error codes leads to consistently retrying while sending request #248

Open
SharpKoi opened this issue Oct 11, 2024 · 0 comments
Open

Comments

@SharpKoi
Copy link

SharpKoi commented Oct 11, 2024

Scenario

I'm implementing a feature to automatically execute my trading plan using HTTP instance. It involves setting leverage. In fact, if we set the same leverage, it will raise error, but I actually don't care if it remains the same. I found there's an option, ignore_codes, in _V5HTTPManager that can ignore the error codes. I added 110043, which presents "leverage not changed", to the ignore_codes, like following:

client = HTTP(
    testnet=True,
    api_key=MY_API_KEY,
    api_secret=MY_API_SECRET
)
client.ignore_codes.add(110043)

Expected Behavior

I expected the client to literally ignore the error of setting the same leverage.

Actual Behavior

This snippet here _http_manager.py#L375-376 does not escape from the while loop so the client consistently retried until max_retries and raised FailedRequestError: Bad request. retries exceeded maximum.

Code to Reproduce

import time
from pybit.unified_trading import HTTP

client = HTTP(
    testnet=True,
    api_key=MY_API_KEY,
    api_secret=MY_API_SECRET
)
client.ignore_codes.add(110043)

for _ in range(2):
  client.set_leverage(
      category="linear",
      symbol="BTCUSDT",
      buyLeverage="10",
      sellLeverage="10",
  )
  
  time.sleep(1)

The output be like:

{'retCode': 0, 'retMsg': 'OK', 'result': {}, 'retExtInfo': {}, 'time': 1728617834265}
FailedRequestError: Bad request. retries exceeded maximum. (ErrCode: 400) (ErrTime: 03:37:14).
Request → POST https://api-testnet.bybit.com/v5/position/set-leverage: {"category": "linear", "symbol": "BTCUSDT", "buyLeverage": "10", "sellLeverage": "10"}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant