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
This commit is contained in:
parent
28159f2fca
commit
6314639c4c
@ -155,32 +155,22 @@ class Exchange(object):
|
|||||||
'''
|
'''
|
||||||
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
|
||||||
Rounded down
|
Rounded down
|
||||||
:param pair: the symbol
|
|
||||||
:param amount: amount
|
|
||||||
:return: amount
|
|
||||||
'''
|
'''
|
||||||
if self._api.markets[pair]['precision']['amount'] > 0:
|
if self._api.markets[pair]['precision']['amount']:
|
||||||
symbol_prec = self._api.markets[pair]['precision']['amount']
|
symbol_prec = self._api.markets[pair]['precision']['amount']
|
||||||
multiplier = int('1' + ('0' * symbol_prec))
|
big_amount = amount * pow(10, symbol_prec)
|
||||||
big_amount = amount * multiplier
|
amount = floor(big_amount) / pow(10, symbol_prec)
|
||||||
round_down = floor(big_amount)
|
|
||||||
amount = round_down / multiplier
|
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
def symbol_price_prec(self, pair, price: float):
|
def symbol_price_prec(self, pair, price: float):
|
||||||
'''
|
'''
|
||||||
Returns the price buying or selling with to the precision the Exchange accepts
|
Returns the price buying or selling with to the precision the Exchange accepts
|
||||||
Rounds up
|
Rounds up
|
||||||
:param pair: the symbol
|
|
||||||
:param price: amount
|
|
||||||
:return: price
|
|
||||||
'''
|
'''
|
||||||
if self._api.markets[pair]['precision']['price'] > 0:
|
if self._api.markets[pair]['precision']['price']:
|
||||||
symbol_prec = self._api.markets[pair]['precision']['price']
|
symbol_prec = self._api.markets[pair]['precision']['price']
|
||||||
multiplier = int('1' + ('0' * symbol_prec))
|
big_price = price * pow(10, symbol_prec)
|
||||||
big_price = price * multiplier
|
price = ceil(big_price) / pow(10, symbol_prec)
|
||||||
round_up = ceil(big_price)
|
|
||||||
price = round_up / multiplier
|
|
||||||
return price
|
return price
|
||||||
|
|
||||||
def buy(self, pair: str, rate: float, amount: float) -> Dict:
|
def buy(self, pair: str, rate: float, amount: float) -> Dict:
|
||||||
|
Loading…
Reference in New Issue
Block a user