Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recalculate price for virtual orders #690

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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