sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.99k stars 2.2k forks source link

better round_step_size function #1119

Closed sh4dowb closed 2 years ago

sh4dowb commented 2 years ago

original one returns wrong:

>>> round_step_size(2.6, 1)
3.0

not exactly "wrong" for numbers such as 0.001, it rounds as stated, but you might not have that extra 0.4 coins when creating orders. also it won't work with anything else than powers of 0.1:

>>> round_step_size(55.3, 0.2)
55.3

this one properly rounds to step size, even with floats such as 0.003:


>>> round_step_size(2.6, 1)
2.0

>>> round_step_size(2.6, 0.003)
2.598

decided to contribute this after a few hours of floating point nightmare

sammchardy commented 2 years ago

Thanks @sh4dowb