Skip to content

Commit

Permalink
Refactor base.py variable names and ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvai committed Sep 13, 2018
1 parent 4f9108b commit 18cd2a0
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions dexbot/strategies/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def __init__(self,
self.fee_asset = Asset('1.3.0')

# Ticker
self.ticker = self.market.ticker()
self.ticker = self.market.ticker

# Settings for bitshares instance
self.bitshares.bundle = bool(self.worker.get("bundle", False))
Expand Down Expand Up @@ -351,7 +351,7 @@ def calculate_worker_value(self, unit_of_measure):
quote_total += balance['amount']

# Calculate value of the orders in unit of measure
orders = self.current_market_own_orders
orders = self.get_own_orders
for order in orders:
if order['base']['symbol'] == self.quote_asset:
# Pick sell orders order's BASE amount, which is same as worker's QUOTE, to worker's BASE
Expand Down Expand Up @@ -399,7 +399,7 @@ def cancel_orders(self, orders, batch_only=False):
self._cancel_orders(order)
return True

def count_asset(self, order_ids=None, return_asset=False, refresh=True):
def count_asset(self, order_ids=None, return_asset=False):
""" Returns the combined amount of the given order ids and the account balance
The amounts are returned in quote and base assets of the market
Expand All @@ -422,9 +422,9 @@ def count_asset(self, order_ids=None, return_asset=False, refresh=True):

if order_ids is None:
# Get all orders from Blockchain
order_ids = [order['id'] for order in self.current_market_own_orders]
order_ids = [order['id'] for order in self.get_own_orders]
if order_ids:
orders_balance = self.orders_balance(order_ids)
orders_balance = self.get_allocated_assets(order_ids)
quote += orders_balance['quote']
base += orders_balance['base']

Expand Down Expand Up @@ -599,7 +599,7 @@ def get_market_buy_price(self, quote_amount=0, base_amount=0):
# Like get_market_sell_price(), but defaulting to base_amount if both base and quote are specified.
# In case amount is not given, return price of the lowest sell order on the market
if quote_amount == 0 and base_amount == 0:
return self.ticker.get('highestBid')
return self.ticker().get('highestBid')

asset_amount = base_amount

Expand Down Expand Up @@ -668,7 +668,7 @@ def get_market_sell_price(self, quote_amount=0, base_amount=00):
"""
# In case amount is not given, return price of the lowest sell order on the market
if quote_amount == 0 and base_amount == 0:
return self.ticker.get('lowestAsk')
return self.ticker().get('lowestAsk')

asset_amount = quote_amount

Expand Down Expand Up @@ -808,7 +808,7 @@ def get_own_buy_orders(self, orders=None):
"""
if not orders:
# List of orders was not given so fetch everything from the market
orders = self.current_market_own_orders
orders = self.get_own_orders

return self.filter_buy_orders(orders)

Expand All @@ -819,7 +819,7 @@ def get_own_sell_orders(self, orders=None):
"""
if not orders:
# List of orders was not given so fetch everything from the market
orders = self.current_market_own_orders
orders = self.get_own_orders

return self.filter_sell_orders(orders)

Expand Down Expand Up @@ -1125,16 +1125,15 @@ def all_own_orders(self, refresh=True):
return orders

@property
def current_market_own_orders(self, refresh=False):
def get_own_orders(self):
""" Return the account's open orders in the current market
:return: List of Order objects
"""
orders = []

# Refresh account data
if refresh:
self.account.refresh()
self.account.refresh()

for order in self.account.openorders:
if self.worker["market"] == order.market and self.account.openorders:
Expand Down Expand Up @@ -1192,8 +1191,8 @@ def get_updated_limit_order(limit_order):
Todo: If get_updated_order is removed, this can be removed as well.
"""
order = copy.deepcopy(limit_order)
price = order['sell_price']['base']['amount'] / order['sell_price']['quote']['amount']
base_amount = order['for_sale']
price = float(order['sell_price']['base']['amount']) / float(order['sell_price']['quote']['amount'])
base_amount = float(order['for_sale'])
quote_amount = base_amount / price
order['sell_price']['base']['amount'] = base_amount
order['sell_price']['quote']['amount'] = quote_amount
Expand Down

0 comments on commit 18cd2a0

Please sign in to comment.