Esempio n. 1
0
    def purge_all_local_worker_data(worker_name):
        """
        Removes worker's data and orders from local sqlite database.

        :param worker_name: Name of the worker to be removed
        """
        Storage.clear_worker_data(worker_name)
Esempio n. 2
0
    def __init__(self,
                 name,
                 config=None,
                 _account=None,
                 _market=None,
                 fee_asset_symbol=None,
                 bitshares_instance=None,
                 bitshares_bundle=None,
                 *args,
                 **kwargs):

        # BitShares instance
        self.bitshares = bitshares_instance or shared_bitshares_instance()

        # Dex instance used to get different fees for the market
        self.dex = Dex(self.bitshares)

        # Storage
        Storage.__init__(self, name)

        # Events
        Events.__init__(self)

        # Redirect this event to also call order placed and order matched
        self.onMarketUpdate += self._callbackPlaceFillOrders

        if config:
            self.config = config
        else:
            self.config = Config.get_worker_config_file(name)

        self._market = _market
        self._account = _account

        # Recheck flag - Tell the strategy to check for updated orders
        self.recheck_orders = False

        # Count of orders to be fetched from the API
        self.fetch_depth = 8

        self.fee_asset = fee_asset_symbol

        # CER cache
        self.core_exchange_rate = None

        # Ticker
        self.ticker = self._market.ticker

        # Settings for bitshares instance
        self.bitshares.bundle = bitshares_bundle

        # Disabled flag - this flag can be flipped to True by a worker and will be reset to False after reset only
        self.disabled = False

        # Order expiration time in seconds
        self.expiration = 60 * 60 * 24 * 365 * 5

        # buy/sell actions will return order id by default
        self.returnOrderId = 'head'
Esempio n. 3
0
 def __init__(self, config, bots):
     self.bots = bots
     self.config = config
     Storage.__init__(self, "reporter")
     if not "lastrun" in self:
         self['lastrun'] = self.lastrun = time.time()
     else:
         self.lastrun = self['lastrun']
Esempio n. 4
0
def test_init(storage):

    # Storage instances with same db_file using single DatabaseWorker()
    _, db_file = tempfile.mkstemp()  # noqa: F811
    storage1 = Storage('test', db_file=db_file)
    storage2 = Storage('test2', db_file=db_file)
    assert storage1.db_worker is storage2.db_worker

    # Different db files - different DatabaseWorker()
    storage3 = Storage('test')
    assert storage3.db_worker is not storage1.db_worker
Esempio n. 5
0
 def __init__(self, **config):
     self.worker_inf = config['worker_infrastructure']
     self.config = config
     
     Storage.__init__(self, "reporter")
     if not "lastrun" in self:
         self['lastrun'] = self.lastrun = time.time()
     else:
         self.lastrun = self['lastrun']
     logging.getLogger("dexbot.per_bot").addHandler(
         SQLiteHandler())  # and log to SQLIte DB
Esempio n. 6
0
    def __init__(self, worker_name, config, main_ctrl, view):
        super().__init__()

        self.main_ctrl = main_ctrl
        self.running = False
        self.worker_name = worker_name
        self.worker_config = self.main_ctrl.config.get_worker_config(
            worker_name)
        self.view = view
        self.storage = Storage(self.worker_name)

        self.setupUi(self)

        self.edit_button.clicked.connect(lambda: self.handle_edit_worker())
        self.details_button.clicked.connect(lambda: self.handle_open_details())
        self.toggle.mouseReleaseEvent = lambda _: self.toggle_worker()
        self.onoff.mouseReleaseEvent = lambda _: self.toggle_worker()

        self.setup_ui_data(config)
Esempio n. 7
0
    def __init__(self,
                 name,
                 config=None,
                 onAccount=None,
                 onOrderMatched=None,
                 onOrderPlaced=None,
                 onMarketUpdate=None,
                 onUpdateCallOrder=None,
                 ontick=None,
                 bitshares_instance=None,
                 *args,
                 **kwargs):

        # BitShares instance
        self.bitshares = bitshares_instance or shared_bitshares_instance()

        # Storage
        Storage.__init__(self, name)

        # Events
        Events.__init__(self)

        if ontick:
            self.ontick += ontick
        if onMarketUpdate:
            self.onMarketUpdate += onMarketUpdate
        if onAccount:
            self.onAccount += onAccount
        if onOrderMatched:
            self.onOrderMatched += onOrderMatched
        if onOrderPlaced:
            self.onOrderPlaced += onOrderPlaced
        if onUpdateCallOrder:
            self.onUpdateCallOrder += onUpdateCallOrder

        # Redirect this event to also call order placed and order matched
        self.onMarketUpdate += self._callbackPlaceFillOrders

        self.assets_intersections_data = None
        if config:
            self.config = config
            self.assets_intersections_data = Config.assets_intersections(
                config)
        else:
            self.config = config = Config.get_worker_config_file(name)

        # Get worker's parameters from the config
        self.worker = config["workers"][name]

        # Recheck flag - Tell the strategy to check for updated orders
        self.recheck_orders = False

        # Count of orders to be fetched from the API
        self.fetch_depth = 8

        # What percent of balance the worker should use
        self.operational_percent_quote = self.worker.get(
            'operational_percent_quote', 0) / 100
        self.operational_percent_base = self.worker.get(
            'operational_percent_base', 0) / 100

        # Get Bitshares account and market for this worker
        self._account = Account(self.worker["account"],
                                full=True,
                                bitshares_instance=self.bitshares)
        self._market = Market(config["workers"][name]["market"],
                              bitshares_instance=self.bitshares)

        # Set fee asset
        fee_asset_symbol = self.worker.get('fee_asset')

        if fee_asset_symbol:
            try:
                self.fee_asset = Asset(fee_asset_symbol,
                                       bitshares_instance=self.bitshares)
            except bitshares.exceptions.AssetDoesNotExistsException:
                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', bitshares_instance=self.bitshares)

        # CER cache
        self.core_exchange_rate = None

        # Ticker
        self.ticker = self._market.ticker

        # Settings for bitshares instance
        self.bitshares.bundle = bool(self.worker.get("bundle", False))

        # Disabled flag - this flag can be flipped to True by a worker and will be reset to False after reset only
        self.disabled = False

        # Order expiration time in seconds
        self.expiration = 60 * 60 * 24 * 365 * 5

        # buy/sell actions will return order id by default
        self.returnOrderId = 'head'

        # A private logger that adds worker identify data to the LogRecord
        self.log = logging.LoggerAdapter(
            logging.getLogger('dexbot.per_worker'), {
                'worker_name': name,
                'account': self.worker['account'],
                'market': self.worker['market'],
                'is_disabled': lambda: self.disabled
            })

        self.orders_log = logging.LoggerAdapter(
            logging.getLogger('dexbot.orders_log'), {})
Esempio n. 8
0
def storage():
    worker_name = 'test_worker'
    _, db_file = tempfile.mkstemp()  # noqa: F811
    storage = Storage(worker_name, db_file=db_file)
    yield storage
    os.unlink(db_file)
Esempio n. 9
0
def drop_state(worker_name):
    """Drop state of the worker (sqlite data)"""
    click.echo('Dropping state for {}'.format(worker_name))
    storage = Storage(worker_name)
    storage.clear_worker_data()
    time.sleep(1)
Esempio n. 10
0
    def __init__(
        self,
        name,
        config=None,
        _account=None,
        _market=None,
        fee_asset_symbol=None,
        bitshares_instance=None,
        *args,
        **kwargs
    ):

        # BitShares instance
        self.bitshares = bitshares_instance or shared_bitshares_instance()

        # Dex instance used to get different fees for the market
        self.dex = Dex(self.bitshares)

        # Storage
        Storage.__init__(self, name)

        # Events
        Events.__init__(self)

        # Redirect this event to also call order placed and order matched
        self.onMarketUpdate += self._callbackPlaceFillOrders

        if config:
            self.config = config
        else:
            self.config = Config.get_worker_config_file(name)

        # Get worker's parameters from the config
        self.worker = config["workers"][name]
        self._market = _market or Market(self.worker["market"], bitshares_instance=self.bitshares)
        self._account = _account or Account(self.worker["account"], full=True, bitshares_instance=self.bitshares)

        # Recheck flag - Tell the strategy to check for updated orders
        self.recheck_orders = False

        # Count of orders to be fetched from the API
        self.fetch_depth = 8

        # Set fee asset
        fee_asset_symbol = fee_asset_symbol or self.worker.get('fee_asset')

        if fee_asset_symbol:
            try:
                self.fee_asset = Asset(fee_asset_symbol, bitshares_instance=self.bitshares)
            except bitshares.exceptions.AssetDoesNotExistsException:
                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', bitshares_instance=self.bitshares)

        # CER cache
        self.core_exchange_rate = None

        # Ticker
        self.ticker = self._market.ticker

        # Settings for bitshares instance
        self.bitshares.bundle = bool(self.worker.get("bundle", False))

        # Disabled flag - this flag can be flipped to True by a worker and will be reset to False after reset only
        self.disabled = False

        # Order expiration time in seconds
        self.expiration = 60 * 60 * 24 * 365 * 5

        # buy/sell actions will return order id by default
        self.returnOrderId = 'head'

        self.log = logging.LoggerAdapter(logging.getLogger('dexbot.orderengine'), {})
Esempio n. 11
0
def storage():
    worker_name = 'test_worker'
    yield Storage(worker_name)
    Storage.clear_worker_data(worker_name)