Example #1
0
 def remove_offline_worker(config, worker_name):
     # 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()
Example #2
0
 def configure(cls, return_base_config=True):
     return BaseStrategy.configure(return_base_config) + [
         ConfigElement(
             'amount', 'float', 1, 'Amount',
             'Fixed order size, expressed in quote asset, unless "relative order size" selected',
             (0, None, 8, '')),
         ConfigElement(
             'relative_order_size', 'bool', False, 'Relative order size',
             'Amount is expressed as a percentage of the account balance of quote/base asset',
             None),
         ConfigElement('spread', 'float', 5, 'Spread',
                       'The percentage difference between buy and sell',
                       (0, 100, 2, '%')),
         ConfigElement(
             'center_price', 'float', 0, 'Center price',
             'Fixed center price expressed in base asset: base/quote',
             (0, None, 8, '')),
         ConfigElement(
             'center_price_dynamic', 'bool', True,
             'Update center price from closest market orders',
             'Always calculate the middle from the closest market orders',
             None),
         ConfigElement(
             'center_price_offset', 'bool', False,
             'Center price offset based on asset balances',
             'Automatically adjust orders up or down based on the imbalance of your assets',
             None),
         ConfigElement(
             'manual_offset', 'float', 0, 'Manual center price offset',
             "Manually adjust orders up or down. "
             "Works independently of other offsets and doesn't override them",
             (-50, 100, 2, '%'))
     ]
Example #3
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement("spread", "float", 5,
                       "Percentage difference between buy and sell",
                       (0, 100)),
         ConfigElement("wall", "float", 0.0,
                       "the default amount to buy/sell, in quote",
                       (0.0, None)),
         ConfigElement("max", "float", 100.0,
                       "bot will not trade if price above this",
                       (0.0, None)),
         ConfigElement("min", "float", 100.0,
                       "bot will not trade if price below this",
                       (0.0, None)),
         ConfigElement("start", "float", 100.0,
                       "Starting price, as percentage of bid/ask spread",
                       (0.0, 100.0)),
         ConfigElement("reset", "bool", False,
                       "bot will alwys reset orders on start", (0.0, None)),
         ConfigElement("staggers", "int", 1,
                       "Number of additional staggered orders to place",
                       (1, 100)),
         ConfigElement("staggerspread", "float", 5,
                       "Percentage difference between staggered orders",
                       (1, 100))
     ]
Example #4
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement("spread", "float", 5,
                       "Percentage difference between buy and sell",
                       (0, 100)),
         ConfigElement(
             "wall_percent", "float", 0,
             "the default amount to buy/sell, as a percentage of the balance",
             (0, 100)),
         ConfigElement("max", "float", 100.0,
                       "worker will not trade if price above this",
                       (0.0, None)),
         ConfigElement("min", "float", 100.0,
                       "worker will not trade if price below this",
                       (0.0, None)),
         ConfigElement("start", "float", 100.0,
                       "Starting price, as percentage of bid/ask spread",
                       (0.0, 100.0)),
         ConfigElement("reset", "bool", False,
                       "worker will always reset orders on start",
                       (0.0, None)),
         ConfigElement("staggers", "int", 1,
                       "Number of additional staggered orders to place",
                       (1, 100)),
         ConfigElement("staggerspread", "float", 5,
                       "Percentage difference between staggered orders",
                       (0, 100)),
         ConfigElement(
             'bias', 'float', 0,
             "Percentage of bias higher or lower (negative is lower) from the baseprice",
             (-100, 100))
     ]
Example #5
0
 def configure(cls, return_base_config=True):
     return BaseStrategy.configure(return_base_config) + [
         ConfigElement('amount', 'float', 1, 'Amount',
                       'Fixed order size, expressed in quote asset',
                       (0, None, 8, '')),
         ConfigElement('spread', 'float', 6, 'Spread',
                       'The percentage difference between buy and sell',
                       (0, None, 2, '%')),
         ConfigElement(
             'increment', 'float', 4, 'Increment',
             'The percentage difference between staggered orders',
             (0, None, 2, '%')),
         ConfigElement(
             'center_price_dynamic', 'bool', True, 'Dynamic center price',
             'Always calculate the middle from the closest market orders',
             None),
         ConfigElement(
             'center_price', 'float', 0, 'Center price',
             'Fixed center price expressed in base asset: base/quote',
             (0, None, 8, '')),
         ConfigElement('lower_bound', 'float', 1, 'Lower bound',
                       'The bottom price in the range', (0, None, 8, '')),
         ConfigElement('upper_bound', 'float', 1000000, 'Upper bound',
                       'The top price in the range', (0, None, 8, ''))
     ]
Example #6
0
def configure_dexbot(config, ctx):
    whiptail = get_whiptail('DEXBot configure')
    workers = config.get('workers', {})
    if not workers:
        while True:
            txt = whiptail.prompt("Your name for the worker")
            config['workers'] = {txt: configure_worker(whiptail, {})}
            if not whiptail.confirm(
                    "Set up another worker?\n(DEXBot can run multiple workers in one instance)"
            ):
                break
        setup_systemd(whiptail, config)
    else:
        bitshares_instance = ctx.bitshares
        action = whiptail.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 = whiptail.menu("Select worker to edit",
                                        [(i, i) for i in workers])
            config['workers'][worker_name] = configure_worker(
                whiptail, config['workers'][worker_name])

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

            strategy = BaseStrategy(worker_name,
                                    bitshares_instance=bitshares_instance)
            strategy.purge()
        elif action == 'NEW':
            txt = whiptail.prompt("Your name for the new worker")
            config['workers'][txt] = configure_worker(whiptail, {})
        elif action == 'CONF':
            choice = whiptail.node_radiolist(
                msg="Choose node",
                items=select_choice(config['node'][0],
                                    [(i, i) for i in config['node']]))
            # Move selected node as first item in the config file's node list
            config['node'].remove(choice)
            config['node'].insert(0, choice)

            setup_systemd(whiptail, config)
    whiptail.clear()
    return config
Example #7
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement("spread", "float", 5,
                       "Percentage difference between buy and sell",
                       (0, 100)),
         ConfigElement(
             "wall_percent", "float", 0,
             "the default amount to buy/sell, as a percentage of the balance",
             (0, 100)),
         ConfigElement(
             "diff", "float", 100.0,
             "minimum difference from a pre-existing bid/ask price",
             (0.0, None))
     ]
Example #8
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement('amount', 'float', 1.0,
                       'The amount of buy/sell orders', (0.0, None)),
         ConfigElement(
             'spread', 'float', 6.0,
             'The percentage difference between buy and sell (Spread)',
             (0.0, None)),
         ConfigElement(
             'increment', 'float', 4.0,
             'The percentage difference between staggered orders (Increment)',
             (0.0, None)),
         ConfigElement('upper_bound', 'float', 1.0,
                       'The top price in the range', (0.0, None)),
         ConfigElement('lower_bound', 'float', 1000.0,
                       'The bottom price in the range', (0.0, None))
     ]
Example #9
0
 def configure(cls, return_base_config=True):
     return BaseStrategy.configure(return_base_config) + [
         ConfigElement("spread", "float", 5, "Spread",
                       "The spread between sell and buy as percentage",
                       (0, 100, 2, '%')),
         ConfigElement(
             "threshold", "float", 5, "Threshold",
             "Percentage the feed has to move before we change orders",
             (0, 100, 2, '%')),
         ConfigElement("buy", "float", 0, "Buy",
                       "The default amount to buy", (0, None, 8, '')),
         ConfigElement("sell", "float", 0, "Sell",
                       "The default amount to sell", (0, None, 8, '')),
         ConfigElement("blocks", "int", 20, "Block num",
                       "Number of blocks to wait before re-calculating",
                       (0, 10000, ''))
     ]
Example #10
0
def configure_dexbot(config):
    d = get_whiptail()
    workers = config.get('workers', {})
    if not workers:
        while True:
            txt = d.prompt("Your name for the worker")
            config['workers'] = {txt: configure_worker(d, {})}
            if not d.confirm(
                    "Set up another worker?\n(DEXBot can run multiple workers in one instance)"
            ):
                break
        setup_systemd(d, config)
    else:
        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':
            txt = d.prompt("Your name for the new worker")
            config['workers'][txt] = configure_worker(d, {})
        elif action == 'CONF':
            config['node'] = d.prompt("BitShares node to use",
                                      default=config['node'])
            setup_systemd(d, config)
    d.clear()
    return config
Example #11
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement(
             'amount_relative', 'bool', False,
             'Amount is expressed as a percentage of the account balance of quote/base asset',
             None),
         ConfigElement('amount', 'float', 1.0,
                       'The amount of buy/sell orders', (0.0, None)),
         ConfigElement('center_price_dynamic', 'bool', True,
                       'Dynamic centre price', None),
         ConfigElement('center_price', 'float', 0.0, 'Initial center price',
                       (0, 0, None)),
         ConfigElement('center_price_offset', 'bool', False,
                       'Center price offset based on asset balances', None),
         ConfigElement(
             'spread', 'float', 5.0,
             'The percentage difference between buy and sell (Spread)',
             (0.0, 100.0))
     ]
Example #12
0
 def configure(cls):
     return BaseStrategy.configure() + [
         ConfigElement("spread", "int", 5,
                       "the spread between sell and buy as percentage",
                       (0, 100)),
         ConfigElement(
             "threshold", "int", 5,
             "percentage the feed has to move before we change orders",
             (0, 100)),
         ConfigElement("buy", "float", 0.0, "the default amount to buy",
                       (0.0, None)),
         ConfigElement("sell", "float", 0.0, "the default amount to sell",
                       (0.0, None)),
         ConfigElement("blocks", "int", 20,
                       "number of blocks to wait before re-calculating",
                       (0, 10000)),
         ConfigElement(
             "dry_run", "bool", False,
             "Dry Run Mode\nIf Yes the bot won't buy or sell anything, just log what it would do.\nIf No, the bot will buy and sell for real.",
             None)
     ]
Example #13
0
 def remove_offline_worker_data(worker_name):
     BaseStrategy.purge_worker_data(worker_name)
Example #14
0
 def remove_offline_worker(config, worker_name):
     # Initialize the base strategy to get control over the data
     strategy = BaseStrategy(worker_name, config)
     strategy.purge()
Example #15
0
 def remove_offline_bot(config, bot_name):
     # Initialize the base strategy to get control over the data
     strategy = BaseStrategy(config, bot_name)
     strategy.purge()
Example #16
0
def configure_dexbot(config, shell=False):
    global bitshares_instance
    d = get_whiptail()
    workers = config.get('workers', {})
    if len(workers) == 0:
        d.view_text("""Welcome to the DEXBot text-based configuration.
You will be asked to set up at least one bot, this will then run in the background.
You can use the arrow keys or TAB to move between buttons, and RETURN to select, the mouse does not work. Use Space to select an item in a list. Selecting Cancel will exit the program.
""")
        while True:
            txt = d.prompt("Your name for the new worker")
            config['workers'] = {txt: configure_worker(d, {})}
            if not d.confirm("Set up another worker?\n(DEXBot can run multiple workers in one instance)"):
                break
        setup_systemd(d, config, shell)
        add_key(d, bitshares_instance)
        return True
    else:
        menu = [('NEW', 'Create a new bot'),
                ('DEL', 'Delete a bot'),
                ('EDIT', 'Edit a bot'),
                ('REPORT', 'Configure reporting'),
                ('NODE', 'Set the BitShares node'),
                ('KEY', 'Add a private key'),
                ('WIPE', 'Wipe all private keys'),
                ('LOG', 'Show the DEXBot event log'),
                ('SHELL', 'Escape to the Linux command shell')]
        if shell:
            menu.extend([('PASSWD', 'Set the account password'),
                         ('LOGOUT', 'Logout of the server')])
        else:
            menu.append(('QUIT', 'Quit without saving'))
        action = d.menu("Select an action:", menu)
        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])
            strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance)
            if not bitshares_instance:
                bitshares_instance = BitShares(config['node'])
            unlock_wallet(d, bitshares_instance)
            strategy.purge()
            return True
        elif action == 'DEL':
            worker_name = d.menu("Select worker to delete", [(i, i) for i in workers])
            del config['workers'][worker_name]
            if not bitshares_instance:
                bitshares_instance = BitShares(config['node'])
            unlock_wallet(d, bitshares_instance)
            strategy = BaseStrategy(worker_name, bitshares_instance=bitshares_instance)
            strategy.purge()
            return True
        elif action == 'NEW':
            txt = d.prompt("Your name for the new worker")
            config['workers'][txt] = configure_worker(d, {})
            return True
        elif action == 'REPORT':
            setup_reporter(d, config)
            return True
        elif action == 'NODE':
            config['node'] = d.prompt(
                "BitShares node to use",
                default=config['node'])
            return True
        elif action == 'KEY':
            add_key(d, bitshares_instance)
            return False
        elif action == 'WIPE':
            if not bitshares_instance:
                bitshares_instance = BitShares()
            if bitshares_instance.wallet.created():
                if d.confirm("Really wipe your wallet of keys?", default='no'):
                    unlock_wallet(d, bitshares_instance)
                    bitshares_instance.wallet.wipe(True)
            else:
                d.alert("No wallet to wipe")
            return False
        elif action == 'LOG':
            os.system("journalctl --user-unit=dexbot -n 1000 -e")
            return False
        elif action == 'LOGOUT':
            sys.exit()
        elif action == 'PASSWD':
            os.system("passwd")
            return False
        elif action == 'SHELL':
            os.system("/bin/bash")
            return False
        elif action == 'QUIT':
            return False
        else:
            d.prompt("Unknown command {}".format(action))
            return False