Skip to content

Commit

Permalink
[GrapehenExchange] Fix Fee and add Fees to borrow()
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Jan 11, 2016
1 parent 11cc6dc commit 783eba6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions grapheneexchange/grapheneexchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def returnFees(self) :
op_name = name
fs = f[1]
for _type in fs :
fs[_type] = float(fs[_type]) * scale / 10 ** base["precision"]
r[op_name] = f[1]
fs[_type] = float(fs[_type]) * scale / 1e4 / 10 ** base["precision"]
r[op_name] = fs
return r

def returnTicker(self):
Expand Down Expand Up @@ -745,6 +745,9 @@ def borrow(self, amount, symbol, collateral_ratio):
:param float amount: Amount to borrow (denoted in 'asset')
:param str symbol: Asset to borrow
:param float collateral_ratio: Collateral ratio to borrow at
:raises ValueError: if symbol is not a bitasset
:raises ValueError: if collateral ratio is smaller than maintenance collateral ratio
:raises ValueError: if required amounts of collateral are not available
Example Output:
Expand Down Expand Up @@ -801,6 +804,14 @@ def borrow(self, amount, symbol, collateral_ratio):
settlement_price = self._get_price(bitasset["current_feed"]["settlement_price"])
amount_of_collateral = amount * collateral_ratio * settlement_price

# Verify that enough funds are available
balances = self.returnBalances()
fundsNeeded = amount_of_collateral + self.returnFees()["call_order_update"]["fee"]
fundsHave = balances[collateral_asset["symbol"]]
if fundsHave <= fundsNeeded:
raise ValueError("Not enough funds available. Need %f %s, but only %f %s are available" %
(fundsNeeded, collateral_asset["symbol"], fundsHave, collateral_asset["symbol"]))

# Borrow
return self.rpc.borrow_asset(self.config.account,
'{:.{prec}f}'.format(amount, prec=asset["precision"]),
Expand Down

0 comments on commit 783eba6

Please sign in to comment.