binance.get_max_leverage_fix

This commit is contained in:
Sam Germain
2022-01-29 03:45:01 -06:00
parent f10ef7f2da
commit 08e4a4a6dd
2 changed files with 42 additions and 34 deletions

View File

@@ -155,19 +155,21 @@ class Binance(Exchange):
except ccxt.BaseError as e:
raise OperationalException(e) from e
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
def get_max_leverage(self, pair: Optional[str], margin: Optional[float]) -> float:
"""
Returns the maximum leverage that a pair can be traded at
:param pair: The base/quote currency pair being traded
:nominal_value: The total value of the trade in quote currency (collateral + debt)
:margin: The total value of the traders collateral in quote currency
"""
if pair not in self._leverage_brackets:
return 1.0
pair_brackets = self._leverage_brackets[pair]
max_lev = 1.0
for [min_amount, margin_req] in pair_brackets:
lev = 1/margin_req
nominal_value = margin * lev
if nominal_value >= min_amount:
max_lev = 1/margin_req
max_lev = lev
return max_lev
@retrier