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

Method modify_margin_helper

python/ccxt/hyperliquid.py:3670–3707  ·  view source on GitHub ↗
(self, symbol: str, amount, type, params={})

Source from the content-addressed store, hash-verified

3668 return self.modify_margin_helper(symbol, amount, 'reduce', params)
3669
3670 def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
3671 self.load_markets()
3672 market = self.market(symbol)
3673 asset = self.parse_to_int(market['baseId'])
3674 sz = self.parse_to_int(Precise.string_mul(self.amount_to_precision(symbol, amount), '1000000'))
3675 if type == 'reduce':
3676 sz = -sz
3677 nonce = self.milliseconds()
3678 updateAction = {
3679 'type': 'updateIsolatedMargin',
3680 'asset': asset,
3681 'isBuy': True,
3682 'ntli': sz,
3683 }
3684 vaultAddress = None
3685 vaultAddress, params = self.handle_option_and_params_2(params, 'modifyMargin', 'vaultAddress', 'subAccountAddress')
3686 vaultAddress = self.format_vault_address(vaultAddress)
3687 signature = self.sign_l1_action(updateAction, nonce, vaultAddress)
3688 request = {
3689 'action': updateAction,
3690 'nonce': nonce,
3691 'signature': signature,
3692 # 'vaultAddress': vaultAddress,
3693 }
3694 if vaultAddress is not None:
3695 request['vaultAddress'] = vaultAddress
3696 response = self.privatePostExchange(request)
3697 #
3698 # {
3699 # 'response': {
3700 # 'type': 'default'
3701 # },
3702 # 'status': 'ok'
3703 # }
3704 #
3705 return self.extend(self.parse_margin_modification(response, market), {
3706 'code': self.safe_string(response, 'status'),
3707 })
3708
3709 def parse_margin_modification(self, data: dict, market: Market = None) -> MarginModification:
3710 #

Callers 2

add_marginMethod · 0.95
reduce_marginMethod · 0.95

Calls 13

marketMethod · 0.95
amount_to_precisionMethod · 0.95
format_vault_addressMethod · 0.95
sign_l1_actionMethod · 0.95
parse_to_intMethod · 0.80
string_mulMethod · 0.80
safe_stringMethod · 0.80
privatePostExchangeMethod · 0.65
load_marketsMethod · 0.45
millisecondsMethod · 0.45

Tested by

no test coverage detected