bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
385 stars 129 forks source link

unified account is forbidden error in switch_margin_mode #180

Closed SaeedRz96 closed 9 months ago

SaeedRz96 commented 9 months ago

I'm using the latest release(5.6.2) and all methods work correctly except switch_margin_mode. This is my code sample:

from pybit.unified_trading import HTTP
session = HTTP(
    testnet=False,
    api_key="API_KEY",
    api_secret="API_SECRET"
)
session.switch_margin_mode(
    category="linear",
    symbol='BTCUSDT',
    tradeMode=1,
    buyLeverage='5',
    sellLeverage='5',
)

And i got this error:

pybit.exceptions.InvalidRequestError: unified account is forbidden (ErrCode: 100028) (ErrTime: 06:49:29).
Request → POST https://api.bybit.com/v5/position/switch-isolated: {"category": "linear", "symbol": "BTCUSDT", "tradeMode": 1, "buyLeverage": "5", "sellLeverage": "5"}.
dextertd commented 9 months ago

Could you share the output of print(session.get_account_info())

SaeedRz96 commented 9 months ago

Could you share the output of print(session.get_account_info())

Here is the output:

{'retCode': 0, 'retMsg': 'OK', 'result': {'marginMode': 'REGULAR_MARGIN', 'updatedTime': '1701804436000', 'unifiedMarginStatus': 3, 'dcpStatus': 'OFF', 'timeWindow': 10, 'smpGroup': 0, 'isMasterTrader': False, 'spotHedgingStatus': 'OFF'}}
dextertd commented 9 months ago

The unified trading account ('unifiedMarginStatus': 3) doesn't support category linear. See which account covers what in the documentation https://bybit-exchange.github.io/docs/v5/position/cross-isolate

You should use this endpoint instead set_margin_mode() https://bybit-exchange.github.io/docs/v5/account/set-margin-mode