okex.get_max_pair_stake_amount

This commit is contained in:
Sam Germain
2022-02-07 03:44:37 -06:00
parent ff915b241c
commit 720a86778e
3 changed files with 223 additions and 1 deletions

View File

@@ -692,13 +692,14 @@ class Exchange:
self,
pair: str,
price: float,
leverage: float = 1.0
) -> float:
max_stake_amount = self._get_stake_amount_limit(pair, price, 0.0, 'max')
if max_stake_amount is None:
# * Should never be executed
raise OperationalException(f'{self.name}.get_max_pair_stake_amount should'
'never set max_stake_amount to None')
return max_stake_amount
return max_stake_amount / leverage
def _get_stake_amount_limit(
self,

View File

@@ -49,3 +49,23 @@ class Okx(Exchange):
def get_leverage_tiers(self, pair: str):
return self._api.fetch_leverage_tiers(pair)
def get_max_pair_stake_amount(
self,
pair: str,
price: float,
leverage: float = 1.0
) -> float:
if self.trading_mode == TradingMode.SPOT:
return float('inf') # Not actually inf, but this probably won't matter for SPOT
if pair not in self._leverage_tiers:
tiers = self.get_leverage_tiers_for_pair(pair)
if not tiers: # Not a leveraged market
return float('inf')
else:
self._leverage_tiers[pair] = tiers
pair_tiers = self._leverage_tiers[pair]
return pair_tiers[-1]['max'] / leverage