Skip to content

Commit

Permalink
Merge remote-tracking branch 'vvk/done/715-koth-trade-0-balance' into…
Browse files Browse the repository at this point in the history
… pr-755-merge
  • Loading branch information
joelvai committed Mar 31, 2020
2 parents 5ccf509 + 78bab4a commit 3f10fbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 12 additions & 6 deletions dexbot/strategies/king_of_the_hill.py
Expand Up @@ -285,9 +285,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)
Expand Down Expand Up @@ -326,9 +329,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)
Expand Down
7 changes: 7 additions & 0 deletions tests/strategies/king_of_the_hill/test_king_of_the_hill.py
Expand Up @@ -102,6 +102,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
Expand Down

0 comments on commit 3f10fbc

Please sign in to comment.