MCPcopy Create free account
hub / github.com/ccxt/ccxt / set_margin_mode

Method set_margin_mode

python/ccxt/bybit.py:6634–6716  ·  view source on GitHub ↗

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={})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

is_unified_enabledMethod · 0.95
get_bybit_typeMethod · 0.95
NotSupportedClass · 0.90
ArgumentsRequiredClass · 0.90
safe_stringMethod · 0.80
safe_string_2Method · 0.80
load_marketsMethod · 0.45
extendMethod · 0.45
marketMethod · 0.45
omitMethod · 0.45

Tested by

no test coverage detected