Add methods to get precision_amount from markets

This commit is contained in:
Matthias 2022-08-15 19:56:25 +02:00
parent 15e85797c2
commit 22241c55d5

View File

@ -680,21 +680,33 @@ class Exchange:
""" """
return endpoint in self._api.has and self._api.has[endpoint] return endpoint in self._api.has and self._api.has[endpoint]
def get_precision_amount(self, pair: str) -> Optional[float]:
"""
Returns the amount precision of the exchange.
:param pair:
"""
return self.markets[pair].get('precision', {}).get('amount', None)
def get_precision_price(self, pair: str) -> Optional[float]:
"""
Returns the price precision of the exchange.
:param pair:
"""
return self.markets[pair].get('precision', {}).get('price', None)
def amount_to_precision(self, pair: str, amount: float) -> float: def amount_to_precision(self, pair: str, amount: float) -> float:
""" """
Returns the amount to buy or sell to a precision the Exchange accepts Returns the amount to buy or sell to a precision the Exchange accepts
""" """
return amount_to_precision(amount, self.markets[pair]['precision']['amount'], return amount_to_precision(amount, self.get_precision_amount(pair), self.precisionMode)
self.precisionMode)
def price_to_precision(self, pair: str, price: float) -> float: def price_to_precision(self, pair: str, price: float) -> float:
""" """
Returns the price rounded up to the precision the Exchange accepts. Returns the price rounded up to the precision the Exchange accepts.
Rounds up Rounds up
""" """
return price_to_precision(price, self.markets[pair]['precision']['price'], return price_to_precision(price, self.get_precision_price(pair), self.precisionMode)
self.precisionMode)
def price_get_one_pip(self, pair: str, price: float) -> float: def price_get_one_pip(self, pair: str, price: float) -> float:
""" """