Add float initializer to FtPrecise
This commit is contained in:
parent
e7cb1b7375
commit
ed004236ce
@ -709,8 +709,8 @@ class Exchange:
|
||||
# counting_mode=self.precisionMode,
|
||||
# ))
|
||||
if self.precisionMode == TICK_SIZE:
|
||||
precision = FtPrecise(str(self.markets[pair]['precision']['price']))
|
||||
price_str = FtPrecise(str(price))
|
||||
precision = FtPrecise(self.markets[pair]['precision']['price'])
|
||||
price_str = FtPrecise(price)
|
||||
missing = price_str % precision
|
||||
if not missing == FtPrecise("0"):
|
||||
price = round(float(str(price_str - missing + precision)), 14)
|
||||
|
@ -1,9 +1,12 @@
|
||||
"""
|
||||
Slim wrapper around ccxt's Precise (string math)
|
||||
To have imports from freqtrade
|
||||
To have imports from freqtrade - and support float initializers
|
||||
"""
|
||||
from ccxt import Precise
|
||||
|
||||
|
||||
class FtPrecise(Precise):
|
||||
pass
|
||||
def __init__(self, number, decimals=None):
|
||||
if not isinstance(number, str):
|
||||
number = str(number)
|
||||
super().__init__(number, decimals)
|
||||
|
@ -73,3 +73,8 @@ def test_FtPrecise():
|
||||
|
||||
assert FtPrecise('3.1415') <= FtPrecise('3.1415')
|
||||
assert FtPrecise('3.1415') <= FtPrecise('3.14150000000000000000001')
|
||||
|
||||
assert FtPrecise(213) == '213'
|
||||
assert FtPrecise(-213) == '-213'
|
||||
assert str(FtPrecise(-213)) == '-213'
|
||||
assert FtPrecise(213.2) == '213.2'
|
||||
|
Loading…
Reference in New Issue
Block a user