Skip to content

Commit

Permalink
Merge branch 'worker-enable-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikakoi committed Jun 21, 2018
2 parents 2056ea7 + d7a2fe2 commit d937084
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dexbot/__init__.py
@@ -1,4 +1,4 @@
APP_NAME = 'dexbot'
VERSION = '0.4.7'
VERSION = '0.4.8'
AUTHOR = 'Codaone Oy'
__version__ = VERSION
2 changes: 1 addition & 1 deletion dexbot/basestrategy.py
Expand Up @@ -496,8 +496,8 @@ def calculate_order_data(self, order, amount, price):
def purge(self):
""" Clear all the worker data from the database and cancel all orders
"""
self.cancel_all()
self.clear_orders()
self.cancel_all()
self.clear()

@staticmethod
Expand Down
5 changes: 4 additions & 1 deletion dexbot/cli.py
Expand Up @@ -108,6 +108,9 @@ def run(ctx):

@main.command()
@click.pass_context
@configfile
@chain
@unlock
def configure(ctx):
""" Interactively configure dexbot
"""
Expand All @@ -117,7 +120,7 @@ def configure(ctx):
os.system('systemctl --user stop dexbot')

config = Config(path=ctx.obj['configfile'])
configure_dexbot(config)
configure_dexbot(config, ctx)
config.save_config()

click.echo("New configuration saved")
Expand Down
8 changes: 5 additions & 3 deletions dexbot/cli_conf.py
Expand Up @@ -179,7 +179,7 @@ def configure_worker(d, worker):
return worker


def configure_dexbot(config):
def configure_dexbot(config, ctx):
d = get_whiptail()
workers = config.get('workers', {})
if not workers:
Expand All @@ -190,21 +190,23 @@ def configure_dexbot(config):
break
setup_systemd(d, config)
else:
bitshares_instance = ctx.bitshares
action = d.menu("You have an existing configuration.\nSelect an action:",
[('NEW', 'Create a new worker'),
('DEL', 'Delete a worker'),
('EDIT', 'Edit a worker'),
('CONF', 'Redo general config')])

if action == 'EDIT':
worker_name = d.menu("Select worker to edit", [(i, i) for i in workers])
config['workers'][worker_name] = configure_worker(d, config['workers'][worker_name])
bitshares_instance = BitShares(config['node'])

strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance)
strategy.purge()
elif action == 'DEL':
worker_name = d.menu("Select worker to delete", [(i, i) for i in workers])
del config['workers'][worker_name]
bitshares_instance = BitShares(config['node'])

strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance)
strategy.purge()
elif action == 'NEW':
Expand Down
5 changes: 2 additions & 3 deletions dexbot/controllers/main_controller.py
Expand Up @@ -63,14 +63,13 @@ def remove_worker(self, worker_name):
else:
# Worker not running
config = self.config.get_worker_config(worker_name)
WorkerInfrastructure.remove_offline_worker(config, worker_name)
WorkerInfrastructure.remove_offline_worker(config, worker_name, self.bitshares_instance)
else:
# Worker manager not running
config = self.config.get_worker_config(worker_name)
WorkerInfrastructure.remove_offline_worker(config, worker_name)
WorkerInfrastructure.remove_offline_worker(config, worker_name, self.bitshares_instance)

@staticmethod
def create_worker(worker_name):
# Deletes old worker's data
WorkerInfrastructure.remove_offline_worker_data(worker_name)

5 changes: 3 additions & 2 deletions dexbot/views/worker_item.py
Expand Up @@ -3,11 +3,9 @@
from .ui.worker_item_widget_ui import Ui_widget
from .confirmation import ConfirmationDialog
from .edit_worker import EditWorkerView
from .errors import gui_error
from dexbot.storage import db_worker
from dexbot.controllers.worker_controller import WorkerController
from dexbot.views.errors import gui_error
from dexbot.resources import icons_rc

from PyQt5 import QtCore, QtWidgets

Expand Down Expand Up @@ -141,7 +139,10 @@ def remove_widget_dialog(self):
self.remove_widget()

def remove_widget(self):
account = self.worker_config['workers'][self.worker_name]['account']

self.main_ctrl.remove_worker(self.worker_name)
self.main_ctrl.bitshares_instance.wallet.removeAccount(account)
self.view.remove_worker_widget(self.worker_name)
self.main_ctrl.config.remove_worker_config(self.worker_name)
self.deleteLater()
Expand Down
3 changes: 1 addition & 2 deletions dexbot/worker.py
Expand Up @@ -223,9 +223,8 @@ def remove_market(self, worker_name):
self.markets.remove(market)

@staticmethod
def remove_offline_worker(config, worker_name):
def remove_offline_worker(config, worker_name, bitshares_instance):
# Initialize the base strategy to get control over the data
bitshares_instance = BitShares(config['node'])
strategy = BaseStrategy(worker_name, config, bitshares_instance=bitshares_instance)
strategy.purge()

Expand Down

0 comments on commit d937084

Please sign in to comment.