Skip to content

Commit

Permalink
improve rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0rgal committed Jul 23, 2020
1 parent 27cb4c6 commit 369b8b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def assert_symbol_exists(self, symbol):
def round(self, symbol, amount):
if self.loaded:
precision = self.symbols[symbol]["baseAssetPrecision"]
return f"%.{precision}f" % round(amount, precision)
step_size = self.symbols[symbol]["stepSize"]
return (
f"%.{precision}f" % round((amount // step_size) * step_size, precision)
).strip("0")
return amount

def assert_symbol(self, symbol):
Expand Down
8 changes: 4 additions & 4 deletions binance/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def wrap_event(self, event_data):

stream = event_data["stream"] if "stream" in event_data else False
event_type = event_data["e"] if "e" in event_data else stream
if "@" in event_type: # lgtm [py/member-test-non-container]
if "@" in event_type: # lgtm [py/member-test-non-container]
event_type = event_type.split("@")[1]
if event_type.startswith("kline_"):
event_type = "kline"
Expand All @@ -81,7 +81,7 @@ def fire(self):


class AggregateTradeWrapper(BinanceEventWrapper):
def __init__(self, event_data, handlers): # lgtm [py/similar-function]
def __init__(self, event_data, handlers): # lgtm [py/similar-function]
super().__init__(event_data, handlers)
self.event_type = event_data["e"]
self.event_time = event_data["E"]
Expand All @@ -97,7 +97,7 @@ def __init__(self, event_data, handlers): # lgtm [py/similar-function]


class TradeWrapper(BinanceEventWrapper):
def __init__(self, event_data, handlers): # lgtm [py/similar-function]
def __init__(self, event_data, handlers): # lgtm [py/similar-function]
super().__init__(event_data, handlers)
self.event_type = event_data["e"]
self.event_time = event_data["E"]
Expand Down Expand Up @@ -140,7 +140,7 @@ def __init__(self, event_data, handlers):

class SymbolMiniTickerWrapper(BinanceEventWrapper):
def __init__(self, event_data, handlers):
super().__init__(event_data, handlers) # lgtm [py/similar-function]
super().__init__(event_data, handlers) # lgtm [py/similar-function]
self.event_type = event_data["e"]
self.event_time = event_data["E"]
self.symbol = event_data["s"]
Expand Down

0 comments on commit 369b8b2

Please sign in to comment.