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

Method set_margin

python/ccxt/lighter.py:3024–3065  ·  view source on GitHub ↗

Either adds or reduces margin in an isolated position in order to set the margin to a specific value :param str symbol: unified market symbol of the market to set margin in :param float amount: the amount to set the margin to :param dict [params]: parameters specific

(self, symbol: str, amount: float, params={})

Source from the content-addressed store, hash-verified

3022 return self.set_margin(symbol, amount, self.extend(request, params))
3023
3024 def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3025 """
3026 Either adds or reduces margin in an isolated position in order to set the margin to a specific value
3027 :param str symbol: unified market symbol of the market to set margin in
3028 :param float amount: the amount to set the margin to
3029 :param dict [params]: parameters specific to the bingx api endpoint
3030 :param str [params.accountIndex]: account index
3031 :param str [params.apiKeyIndex]: api key index
3032 :returns dict: A `margin structure <https://docs.ccxt.com/?id=add-margin-structure>`
3033 """
3034 self.load_markets()
3035 apiKeyIndex = None
3036 apiKeyIndex, params = self.handle_api_key_index(params, 'setMargin', 'apiKeyIndex', 'api_key_index')
3037 direction = self.safe_integer(params, 'direction') # 1 increase margin 0 decrease margin
3038 if direction is None:
3039 raise ArgumentsRequired(self.id + ' setMargin() requires a direction parameter either 1(increase margin) or 0(decrease margin)')
3040 if not self.in_array(direction, [0, 1]):
3041 raise ArgumentsRequired(self.id + ' setMargin() requires a direction parameter either 1(increase margin) or 0(decrease margin)')
3042 if symbol is None:
3043 raise ArgumentsRequired(self.id + ' setMargin() requires a symbol argument')
3044 accountIndex = None
3045 accountIndex, params = self.handle_account_index(params, 'setMargin', 'accountIndex', 'account_index')
3046 strAccountIndex = self.number_to_string(accountIndex)
3047 strApiKeyIndex = self.number_to_string(apiKeyIndex)
3048 signer = self.load_account(self.options['chainId'], self.get_lighter_private_key(strAccountIndex, strApiKeyIndex), strApiKeyIndex, strAccountIndex, params)
3049 market = self.market(symbol)
3050 nonce = self.fetch_nonce(accountIndex, apiKeyIndex, params)
3051 signRaw = {
3052 'market_index': self.parse_to_int(market['id']),
3053 'usdc_amount': self.parse_to_int(Precise.string_mul(self.pow('10', '6'), self.currency_to_precision('USDC', amount))),
3054 'direction': direction,
3055 'nonce': nonce,
3056 'api_key_index': apiKeyIndex,
3057 'account_index': accountIndex,
3058 }
3059 txType, txInfo = self.lighter_sign_update_margin(signer, self.extend(signRaw, params))
3060 request = {
3061 'tx_type': txType,
3062 'tx_info': txInfo,
3063 }
3064 response = self.publicPostSendTx(request)
3065 return self.parse_margin_modification(response, market)
3066
3067 def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3068 timestamp = self.safe_integer(data, 'predicted_execution_time_ms')

Callers 2

add_marginMethod · 0.95
reduce_marginMethod · 0.95

Calls 15

handle_api_key_indexMethod · 0.95
handle_account_indexMethod · 0.95
load_accountMethod · 0.95
fetch_nonceMethod · 0.95
powMethod · 0.95
ArgumentsRequiredClass · 0.90
safe_integerMethod · 0.80
in_arrayMethod · 0.80
parse_to_intMethod · 0.80
string_mulMethod · 0.80

Tested by

no test coverage detected