set margin mode(account) or trade mode(symbol) https://bybit-exchange.github.io/docs/v5/account/set-margin-mode https://bybit-exchange.github.io/docs/v5/position/cross-isolate :param str marginMode: account mode must be either [isolated, cross, portfolio], trade mo
(self, marginMode: str, symbol: Str = None, params={})
| 6632 | } |
| 6633 | |
| 6634 | def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}): |
| 6635 | """ |
| 6636 | set margin mode(account) or trade mode(symbol) |
| 6637 | |
| 6638 | https://bybit-exchange.github.io/docs/v5/account/set-margin-mode |
| 6639 | https://bybit-exchange.github.io/docs/v5/position/cross-isolate |
| 6640 | |
| 6641 | :param str marginMode: account mode must be either [isolated, cross, portfolio], trade mode must be either [isolated, cross] |
| 6642 | :param str symbol: unified market symbol of the market the position is held in, default is None |
| 6643 | :param dict [params]: extra parameters specific to the exchange API endpoint |
| 6644 | :param str [params.leverage]: the rate of leverage, is required if setting trade mode(symbol) |
| 6645 | :returns dict: response from the exchange |
| 6646 | """ |
| 6647 | self.load_markets() |
| 6648 | enableUnifiedMargin, enableUnifiedAccount = self.is_unified_enabled() |
| 6649 | isUnifiedAccount = (enableUnifiedMargin or enableUnifiedAccount) |
| 6650 | market = None |
| 6651 | response: dict |
| 6652 | if isUnifiedAccount: |
| 6653 | if marginMode == 'isolated': |
| 6654 | marginMode = 'ISOLATED_MARGIN' |
| 6655 | elif marginMode == 'cross': |
| 6656 | marginMode = 'REGULAR_MARGIN' |
| 6657 | elif marginMode == 'portfolio': |
| 6658 | marginMode = 'PORTFOLIO_MARGIN' |
| 6659 | else: |
| 6660 | raise NotSupported(self.id + ' setMarginMode() marginMode must be either [isolated, cross, portfolio]') |
| 6661 | request = { |
| 6662 | 'setMarginMode': marginMode, |
| 6663 | } |
| 6664 | response = self.privatePostV5AccountSetMarginMode(self.extend(request, params)) |
| 6665 | else: |
| 6666 | if symbol is None: |
| 6667 | raise ArgumentsRequired(self.id + ' setMarginMode() requires a symbol parameter for non unified account') |
| 6668 | market = self.market(symbol) |
| 6669 | isUsdcSettled = market['settle'] == 'USDC' |
| 6670 | if isUsdcSettled: |
| 6671 | if marginMode == 'cross': |
| 6672 | marginMode = 'REGULAR_MARGIN' |
| 6673 | elif marginMode == 'portfolio': |
| 6674 | marginMode = 'PORTFOLIO_MARGIN' |
| 6675 | else: |
| 6676 | raise NotSupported(self.id + ' setMarginMode() for usdc market marginMode must be either [cross, portfolio]') |
| 6677 | request = { |
| 6678 | 'setMarginMode': marginMode, |
| 6679 | } |
| 6680 | response = self.privatePostV5AccountSetMarginMode(self.extend(request, params)) |
| 6681 | else: |
| 6682 | type = None |
| 6683 | type, params = self.get_bybit_type('setPositionMode', market, params) |
| 6684 | tradeMode = None |
| 6685 | if marginMode == 'cross': |
| 6686 | tradeMode = 0 |
| 6687 | elif marginMode == 'isolated': |
| 6688 | tradeMode = 1 |
| 6689 | else: |
| 6690 | raise NotSupported(self.id + ' setMarginMode() with symbol marginMode must be either [isolated, cross]') |
| 6691 | sellLeverage = None |
nothing calls this directly
no test coverage detected