From 0682f142d27ae97f8591b8d53cbef516e5359efe Mon Sep 17 00:00:00 2001 From: creslin <34645187+creslinux@users.noreply.github.com> Date: Mon, 30 Jul 2018 10:27:19 +0000 Subject: [PATCH] Update __init__.py Moved to pow(10, on recommendation from core team Removed excessive boiler plating for simple function Tested on sandbox with print output and in scratch conn is HTTPSConnectionPool(host='api-public.sandbox.gdax.com', port=443) conn is HTTPSConnectionPool(host='api-public.sandbox.gdax.com', port=443) be_amount 0.00610615427076642 sym prec is 8 af_amount 0.00610615 b4_price 8188.46 sym prec is 2 af_price 8188.46 --- freqtrade/exchange/__init__.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 4792a0a21..0f89eb660 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -155,32 +155,22 @@ class Exchange(object): ''' Returns the amount to buy or sell to a precision the Exchange accepts Rounded down - :param pair: the symbol - :param amount: amount - :return: amount ''' if self._api.markets[pair]['precision']['amount']: symbol_prec = self._api.markets[pair]['precision']['amount'] - multiplier = int('1' + ('0' * symbol_prec)) - big_amount = amount * multiplier - round_down = floor(big_amount) - amount = round_down / multiplier + big_amount = amount * pow(10, symbol_prec) + amount = floor(big_amount) / pow(10, symbol_prec) return amount def symbol_price_prec(self, pair, price: float): ''' Returns the price buying or selling with to the precision the Exchange accepts Rounds up - :param pair: the symbol - :param price: amount - :return: price ''' if self._api.markets[pair]['precision']['price']: symbol_prec = self._api.markets[pair]['precision']['price'] - multiplier = int('1' + ('0' * symbol_prec)) - big_price = price * multiplier - round_up = ceil(big_price) - price = round_up / multiplier + big_price = price * pow(10, symbol_prec) + price = ceil(big_price) / pow(10, symbol_prec) return price def buy(self, pair: str, rate: float, amount: float) -> Dict: