Skip to content

Commit

Permalink
[GrapheneExchange] Verify sell/buy amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Jan 12, 2016
1 parent bab5ea9 commit 8d0c5df
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions grapheneexchange/grapheneexchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8d0c5df

Please sign in to comment.