Skip to content

Commit

Permalink
Change relative orders config structure
Browse files Browse the repository at this point in the history
Flattened the target key for simpler structure
  • Loading branch information
mikakoi committed Apr 12, 2018
1 parent 708d8ed commit 6fbd7c2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
20 changes: 10 additions & 10 deletions dexbot/controllers/create_worker_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,21 @@ def get_account(worker_data):
return worker_data['account']

@staticmethod
def get_target_amount(worker_data):
return worker_data['target']['amount']
def get_amount(worker_data):
return worker_data.get('amount', 0)

@staticmethod
def get_target_amount_relative(worker_data):
return worker_data['target']['amount_relative']
def get_amount_relative(worker_data):
return worker_data.get('amount_relative', False)

@staticmethod
def get_target_center_price(worker_data):
return worker_data['target']['center_price']
def get_center_price(worker_data):
return worker_data.get('center_price', 0)

@staticmethod
def get_target_center_price_dynamic(worker_data):
return worker_data['target']['center_price_dynamic']
def get_center_price_dynamic(worker_data):
return worker_data.get('center_price_dynamic', True)

@staticmethod
def get_target_spread(worker_data):
return worker_data['target']['spread']
def get_spread(worker_data):
return worker_data.get('spread', 5)
13 changes: 6 additions & 7 deletions dexbot/strategies/relative_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ def __init__(self, *args, **kwargs):
self.error_onMarketUpdate = self.error
self.error_onAccount = self.error

self.target = self.worker.get("target", {})
self.is_center_price_dynamic = self.target["center_price_dynamic"]
self.is_center_price_dynamic = self.worker["center_price_dynamic"]
if self.is_center_price_dynamic:
self.center_price = None
else:
self.center_price = self.target["center_price"]
self.center_price = self.worker["center_price"]

self.is_relative_order_size = self.target['amount_relative']
self.order_size = float(self.target['amount'])
self.is_relative_order_size = self.worker['amount_relative']
self.order_size = float(self.worker['amount'])

self.buy_price = None
self.sell_price = None
Expand Down Expand Up @@ -64,8 +63,8 @@ def calculate_order_prices(self):
if self.is_center_price_dynamic:
self.center_price = self.calculate_center_price

self.buy_price = self.center_price * (1 - (self.target["spread"] / 2) / 100)
self.sell_price = self.center_price * (1 + (self.target["spread"] / 2) / 100)
self.buy_price = self.center_price * (1 - (self.worker["spread"] / 2) / 100)
self.sell_price = self.center_price * (1 + (self.worker["spread"] / 2) / 100)

def error(self, *args, **kwargs):
self.cancel_all()
Expand Down
14 changes: 5 additions & 9 deletions dexbot/views/create_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ def handle_save(self):
else:
amount = ui.amount_input.text()

target = {
'amount': amount,
'amount_relative': bool(ui.relative_order_size_checkbox.isChecked()),
'center_price': float(ui.center_price_input.text()),
'center_price_dynamic': bool(ui.center_price_dynamic_checkbox.isChecked()),
'spread': spread
}

base_asset = ui.base_asset_input.currentText()
quote_asset = ui.quote_asset_input.text()
strategy = ui.strategy_input.currentText()
Expand All @@ -135,7 +127,11 @@ def handle_save(self):
'market': '{}/{}'.format(quote_asset, base_asset),
'module': worker_module,
'strategy': strategy,
'target': target
'amount': amount,
'amount_relative': bool(ui.relative_order_size_checkbox.isChecked()),
'center_price': float(ui.center_price_input.text()),
'center_price_dynamic': bool(ui.center_price_dynamic_checkbox.isChecked()),
'spread': spread
}
self.worker_name = ui.worker_name_input.text()
self.accept()
24 changes: 10 additions & 14 deletions dexbot/views/edit_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ def __init__(self, controller, worker_name, config):
self.quote_asset_input.setText(self.controller.get_quote_asset(worker_data))
self.account_name.setText(self.controller.get_account(worker_data))

if self.controller.get_target_amount_relative(worker_data):
if self.controller.get_amount_relative(worker_data):
self.order_size_input_to_relative()
self.relative_order_size_checkbox.setChecked(True)
else:
self.order_size_input_to_static()
self.relative_order_size_checkbox.setChecked(False)

self.amount_input.setValue(float(self.controller.get_target_amount(worker_data)))
self.amount_input.setValue(float(self.controller.get_amount(worker_data)))

self.center_price_input.setValue(self.controller.get_target_center_price(worker_data))
self.center_price_input.setValue(self.controller.get_center_price(worker_data))

center_price_dynamic = self.controller.get_target_center_price_dynamic(worker_data)
center_price_dynamic = self.controller.get_center_price_dynamic(worker_data)
if center_price_dynamic:
self.center_price_input.setEnabled(False)
self.center_price_dynamic_checkbox.setChecked(True)
else:
self.center_price_input.setEnabled(True)
self.center_price_dynamic_checkbox.setChecked(False)

self.spread_input.setValue(self.controller.get_target_spread(worker_data))
self.spread_input.setValue(self.controller.get_spread(worker_data))
self.save_button.clicked.connect(self.handle_save)
self.cancel_button.clicked.connect(self.reject)
self.center_price_dynamic_checkbox.stateChanged.connect(self.onchange_center_price_dynamic_checkbox)
Expand Down Expand Up @@ -136,14 +136,6 @@ def handle_save(self):
else:
amount = self.amount_input.text()

target = {
'amount': amount,
'amount_relative': bool(self.relative_order_size_checkbox.isChecked()),
'center_price': float(self.center_price_input.text()),
'center_price_dynamic': bool(self.center_price_dynamic_checkbox.isChecked()),
'spread': spread
}

base_asset = self.base_asset_input.currentText()
quote_asset = self.quote_asset_input.text()
strategy = self.strategy_input.currentText()
Expand All @@ -153,7 +145,11 @@ def handle_save(self):
'market': '{}/{}'.format(quote_asset, base_asset),
'module': worker_module,
'strategy': strategy,
'target': target
'amount': amount,
'amount_relative': bool(self.relative_order_size_checkbox.isChecked()),
'center_price': float(self.center_price_input.text()),
'center_price_dynamic': bool(self.center_price_dynamic_checkbox.isChecked()),
'spread': spread
}
self.worker_name = self.worker_name_input.text()
self.accept()

0 comments on commit 6fbd7c2

Please sign in to comment.