Skip to content

Commit

Permalink
Recalculate price for virtual orders
Browse files Browse the repository at this point in the history
Order price is now more precise according to actual asset precisions.

Closes: #642
  • Loading branch information
bitphage committed Sep 28, 2019
1 parent 0a4970b commit 1b73074
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions dexbot/strategies/staggered_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1b73074

Please sign in to comment.