Skip to content

Commit

Permalink
Merge remote-tracking branch 'vvk/556-557-lost-bitshares_instance' in…
Browse files Browse the repository at this point in the history
…to pr-558-merge
  • Loading branch information
joelvai committed May 2, 2019
2 parents 111f89d + 32cbaad commit 9798a45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
29 changes: 14 additions & 15 deletions dexbot/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ def __init__(self,

if fee_asset_symbol:
try:
self.fee_asset = Asset(fee_asset_symbol)
self.fee_asset = Asset(fee_asset_symbol, bitshares_instance=self.bitshares)
except bitshares.exceptions.AssetDoesNotExistsException:
self.fee_asset = Asset('1.3.0')
self.fee_asset = Asset('1.3.0', bitshares_instance=self.bitshares)
else:
# If there is no fee asset, use BTS
self.fee_asset = Asset('1.3.0')
self.fee_asset = Asset('1.3.0', bitshares_instance=self.bitshares)

# CER cache
self.core_exchange_rate = None
Expand Down Expand Up @@ -269,10 +269,10 @@ def balance(self, asset, fee_reservation=0):
return balance

def calculate_order_data(self, order, amount, price):
quote_asset = Amount(amount, self.market['quote']['symbol'])
quote_asset = Amount(amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares)
order['quote'] = quote_asset
order['price'] = price
base_asset = Amount(amount * price, self.market['base']['symbol'])
base_asset = Amount(amount * price, self.market['base']['symbol'], bitshares_instance=self.bitshares)
order['base'] = base_asset
return order

Expand Down Expand Up @@ -376,8 +376,8 @@ def count_asset(self, order_ids=None, return_asset=False):
base += orders_balance['base']

if return_asset:
quote = Amount(quote, quote_asset)
base = Amount(base, base_asset)
quote = Amount(quote, quote_asset, bitshares_instance=self.bitshares)
base = Amount(base, base_asset, bitshares_instance=self.bitshares)

return {'quote': quote, 'base': base}

Expand Down Expand Up @@ -410,8 +410,8 @@ def get_allocated_assets(self, order_ids=None, return_asset=False):

# Return as Amount objects instead of only float values
if return_asset:
quote = Amount(quote, quote_asset)
base = Amount(base, base_asset)
quote = Amount(quote, quote_asset, bitshares_instance=self.bitshares)
base = Amount(base, base_asset, bitshares_instance=self.bitshares)

return {'quote': quote, 'base': base}

Expand Down Expand Up @@ -968,7 +968,7 @@ def place_market_buy_order(self, amount, price, return_none=False, *args, **kwar
buy_transaction = self.retry_action(
self.market.buy,
price,
Amount(amount=amount, asset=self.market["quote"]),
Amount(amount=amount, asset=self.market["quote"], bitshares_instance=self.bitshares),
account=self.account.name,
expiration=self.expiration,
returnOrderId=return_order_id,
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def place_market_sell_order(self, amount, price, return_none=False, invert=False
sell_transaction = self.retry_action(
self.market.sell,
price,
Amount(amount=amount, asset=self.market["quote"]),
Amount(amount=amount, asset=self.market["quote"], bitshares_instance=self.bitshares),
account=self.account.name,
expiration=self.expiration,
returnOrderId=return_order_id,
Expand Down Expand Up @@ -1280,7 +1280,7 @@ def convert_fee(self, fee_amount, fee_asset):
:return: float | amount of fee_asset to pay fee
"""
if isinstance(fee_asset, str):
fee_asset = Asset(fee_asset)
fee_asset = Asset(fee_asset, bitshares_instance=self.bitshares)

if fee_asset['id'] == '1.3.0':
# Fee asset is BTS, so no further calculations are needed
Expand All @@ -1292,8 +1292,7 @@ def convert_fee(self, fee_amount, fee_asset):
self.core_exchange_rate = temp_market.ticker()['core_exchange_rate']
return fee_amount * self.core_exchange_rate['base']['amount']

@staticmethod
def get_order(order_id, return_none=True):
def get_order(self, order_id, return_none=True):
""" Get Order object with order_id
:param str | dict order_id: blockchain object id of the order can be an order dict with the id key in it
Expand All @@ -1305,7 +1304,7 @@ def get_order(order_id, return_none=True):
if 'id' in order_id:
order_id = order_id['id']
try:
order = Order(order_id)
order = Order(order_id, blockchain_instance=self.bitshares)
except Exception:
logging.getLogger(__name__).error('Got an exception getting order id {}'.format(order_id))
raise
Expand Down
8 changes: 4 additions & 4 deletions dexbot/strategies/staggered_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,10 +1773,10 @@ def place_virtual_buy_order(self, amount, price):
order = VirtualOrder()
order['price'] = price

quote_asset = Amount(amount, self.market['quote']['symbol'])
quote_asset = Amount(amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares)
order['quote'] = quote_asset

base_asset = Amount(amount * price, self.market['base']['symbol'])
base_asset = Amount(amount * price, self.market['base']['symbol'], bitshares_instance=self.bitshares)
order['base'] = base_asset
order['for_sale'] = base_asset

Expand All @@ -1802,10 +1802,10 @@ def place_virtual_sell_order(self, amount, price):
order = VirtualOrder()
order['price'] = price ** -1

quote_asset = Amount(amount * price, self.market['base']['symbol'])
quote_asset = Amount(amount * price, self.market['base']['symbol'], bitshares_instance=self.bitshares)
order['quote'] = quote_asset

base_asset = Amount(amount, self.market['quote']['symbol'])
base_asset = Amount(amount, self.market['quote']['symbol'], bitshares_instance=self.bitshares)
order['base'] = base_asset
order['for_sale'] = base_asset

Expand Down

0 comments on commit 9798a45

Please sign in to comment.