From 7f483e28805a9947c1cdb9c834d8a30f3cc9a87f Mon Sep 17 00:00:00 2001 From: Vladimir Kamarzin Date: Tue, 10 Sep 2019 13:11:57 +0500 Subject: [PATCH] Recalculate price for virtual orders Order price is now more precise according to actual asset precisions. Should fix #642 --- dexbot/strategies/staggered_orders.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dexbot/strategies/staggered_orders.py b/dexbot/strategies/staggered_orders.py index 354557943..30941440a 100644 --- a/dexbot/strategies/staggered_orders.py +++ b/dexbot/strategies/staggered_orders.py @@ -1960,21 +1960,21 @@ def place_virtual_buy_order(self, amount, price): :return dict | order: Returns virtual order instance """ symbol = self.market['base']['symbol'] - precision = self.market['base']['precision'] - order = VirtualOrder() - order['price'] = price order['id'] = str(uuid.uuid4()) - quote_asset = Amount(amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares) + precise_quote_amount = round(amount, self.market['quote']['precision']) + quote_asset = Amount(precise_quote_amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares) order['quote'] = quote_asset - base_asset = Amount(amount * price, self.market['base']['symbol'], bitshares_instance=self.bitshares) + precise_base_amount = round(amount * price, self.market['base']['precision']) + base_asset = Amount(precise_base_amount, self.market['base']['symbol'], bitshares_instance=self.bitshares) order['base'] = base_asset order['for_sale'] = base_asset + order['price'] = precise_base_amount / precise_quote_amount self.log.info('Placing a virtual buy order with {:.{prec}f} {} @ {:.8f}' - .format(order['base']['amount'], symbol, price, prec=precision)) + .format(order['base']['amount'], symbol, order['price'], prec=self.market['base']['precision'])) self.virtual_orders.append(order) # Immediately lower avail balance @@ -1992,21 +1992,21 @@ def place_virtual_sell_order(self, amount, price): :return dict | order: Returns virtual order instance """ symbol = self.market['quote']['symbol'] - precision = self.market['quote']['precision'] - order = VirtualOrder() order['id'] = str(uuid.uuid4()) - order['price'] = price ** -1 - quote_asset = Amount(amount * price, self.market['base']['symbol'], bitshares_instance=self.bitshares) + precise_quote_amount = round(amount * price, self.market['base']['precision']) + quote_asset = Amount(precise_quote_amount, self.market['base']['symbol'], bitshares_instance=self.bitshares) order['quote'] = quote_asset - base_asset = Amount(amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares) + precise_base_amount = round(amount, self.market['quote']['precision']) + base_asset = Amount(precise_base_amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares) order['base'] = base_asset order['for_sale'] = base_asset + order['price'] = precise_base_amount / precise_quote_amount self.log.info('Placing a virtual sell order with {:.{prec}f} {} @ {:.8f}' - .format(amount, symbol, price, prec=precision)) + .format(amount, symbol, order['price'], prec=self.market['quote']['precision'])) self.virtual_orders.append(order) # Immediately lower avail balance