From 8d0c5df9de01d1c16254ea7df50326b3d33a48dc Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Tue, 12 Jan 2016 10:19:24 +0100 Subject: [PATCH] [GrapheneExchange] Verify sell/buy amounts --- grapheneexchange/grapheneexchange.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/grapheneexchange/grapheneexchange.py b/grapheneexchange/grapheneexchange.py index 1f40a704..0626acde 100644 --- a/grapheneexchange/grapheneexchange.py +++ b/grapheneexchange/grapheneexchange.py @@ -680,6 +680,12 @@ def buy(self, currencyPair, rate, amount): # We buy quote and pay with base quote_symbol, base_symbol = currencyPair.split(self.market_separator) base = self.rpc.get_asset(base_symbol) + quote = self.rpc.get_asset(quote_symbol) + # Check amount > 0 + amountBase = '{:.{prec}f}'.format(amount * rate, prec=base["precision"]) + zero = '{:.{prec}f}'.format(0, prec=base["precision"]) + if amountBase == zero: + raise ValueError("You are asking for too little! Check amounts") return self.rpc.sell_asset(self.config.account, '{:.{prec}f}'.format(amount / rate, prec=base["precision"]), base_symbol, @@ -737,7 +743,13 @@ def sell(self, currencyPair, rate, amount): print("Please GrapheneExchange(config, safe_mode=False) to remove this and execute the transaction below") # We sell quote and pay with base quote_symbol, base_symbol = currencyPair.split(self.market_separator) + base = self.rpc.get_asset(base_symbol) quote = self.rpc.get_asset(quote_symbol) + # Check amount > 0 + amountBase = '{:.{prec}f}'.format(amount * rate, prec=base["precision"]) + zero = '{:.{prec}f}'.format(0, prec=base["precision"]) + if amountBase == zero: + raise ValueError("You are asking for too little! Check amounts") return self.rpc.sell_asset(self.config.account, '{:.{prec}f}'.format(amount, prec=quote["precision"]), quote_symbol,