From 78bab4a82f3a3b5b72ff70a6a07d79f12c28380d Mon Sep 17 00:00:00 2001 From: Vladimir Kamarzin Date: Fri, 27 Mar 2020 17:21:40 +0500 Subject: [PATCH] Adjust 0 balance message in "both" mode To not scary user when some asset has 0 balance in "both" mode, change log message level to debug. Despite report, such condition doesn't leads to "worker disabled" error. Closes: #715 --- dexbot/strategies/king_of_the_hill.py | 18 ++++++++++++------ .../king_of_the_hill/test_king_of_the_hill.py | 7 +++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dexbot/strategies/king_of_the_hill.py b/dexbot/strategies/king_of_the_hill.py index 05fcf49d8..8c08c5b07 100644 --- a/dexbot/strategies/king_of_the_hill.py +++ b/dexbot/strategies/king_of_the_hill.py @@ -221,9 +221,12 @@ def place_order(self, order_type): amount_base = Decimal(self.amount_base).quantize(Decimal(0).scaleb(-self.market['base']['precision'])) if not amount_base: - self.log.error( - 'Cannot place {} order with 0 amount. Adjust your settings or add balance'.format(order_type) - ) + if self.mode == 'both': + self.log.debug('Not placing %s order in "both" mode due to insufficient balance', order_type) + else: + self.log.error( + 'Cannot place {} order with 0 amount. Adjust your settings or add balance'.format(order_type) + ) return False price = Decimal(self.top_buy_price) @@ -263,9 +266,12 @@ def place_order(self, order_type): amount_quote = Decimal(self.amount_quote).quantize(Decimal(0).scaleb(-self.market['quote']['precision'])) if not amount_quote: - self.log.error( - 'Cannot place {} order with 0 amount. Adjust your settings or add balance'.format(order_type) - ) + if self.mode == 'both': + self.log.debug('Not placing %s order in "both" mode due to insufficient balance', order_type) + else: + self.log.error( + 'Cannot place {} order with 0 amount. Adjust your settings or add balance'.format(order_type) + ) return False price = Decimal(self.top_sell_price) diff --git a/tests/strategies/king_of_the_hill/test_king_of_the_hill.py b/tests/strategies/king_of_the_hill/test_king_of_the_hill.py index a25e9133d..6c7a042ee 100644 --- a/tests/strategies/king_of_the_hill/test_king_of_the_hill.py +++ b/tests/strategies/king_of_the_hill/test_king_of_the_hill.py @@ -92,6 +92,13 @@ def test_place_order_zero_amount(worker, other_orders, monkeypatch): monkeypatch.setattr(worker.__class__, 'amount_base', 0) assert worker.place_order('buy') is False + # Test other modes too + worker.mode = 'buy' + assert worker.place_order('buy') is False + + worker.mode = 'sell' + assert worker.place_order('sell') is False + def test_place_orders(worker2, other_orders): """ Test that orders are placed according to mode (buy, sell, buy + sell). Simple test, just make sure buy/sell