Beispiel #1
0
    def read(reloadable_config: ReloadableConfig, spread_feed: Feed,
             control_feed: Feed, history: History):
        assert (isinstance(reloadable_config, ReloadableConfig))
        assert (isinstance(spread_feed, Feed))
        assert (isinstance(control_feed, Feed))
        assert (isinstance(history, History))

        try:
            config = reloadable_config.get_config(spread_feed.get()[0])
            control_feed_value = control_feed.get()[0]

            buy_bands = list(map(BuyBand, config['buyBands']))
            buy_limits = SideLimits(
                config['buyLimits'] if 'buyLimits' in config else [],
                history.buy_history)
            sell_bands = list(map(SellBand, config['sellBands']))
            sell_limits = SideLimits(
                config['sellLimits'] if 'sellLimits' in config else [],
                history.sell_history)

            if 'canBuy' not in control_feed_value or 'canSell' not in control_feed_value:
                logging.getLogger().warning(
                    "Control feed expired. Assuming no buy bands and no sell bands."
                )

                buy_bands = []
                sell_bands = []

            else:
                if not control_feed_value['canBuy']:
                    logging.getLogger().warning(
                        "Control feed says we shall not buy. Assuming no buy bands."
                    )
                    buy_bands = []

                if not control_feed_value['canSell']:
                    logging.getLogger().warning(
                        "Control feed says we shall not sell. Assuming no sell bands."
                    )
                    sell_bands = []

        except Exception as e:
            logging.getLogger().exception(
                f"Config file is invalid ({e}). Treating the config file as it has no bands."
            )

            buy_bands = []
            buy_limits = SideLimits([], history.buy_history)
            sell_bands = []
            sell_limits = SideLimits([], history.buy_history)

        return Bands(buy_bands=buy_bands,
                     buy_limits=buy_limits,
                     sell_bands=sell_bands,
                     sell_limits=sell_limits)
Beispiel #2
0
    def read(reloadable_config: ReloadableConfig, spread_feed: Feed,
             history: History):
        assert (isinstance(reloadable_config, ReloadableConfig))
        assert (isinstance(history, History))

        try:
            config = reloadable_config.get_config(spread_feed.get()[0])

            buy_bands = list(map(BuyBand, config['buyBands']))
            buy_limits = SideLimits(
                config['buyLimits'] if 'buyLimits' in config else [],
                history.buy_history)
            sell_bands = list(map(SellBand, config['sellBands']))
            sell_limits = SideLimits(
                config['sellLimits'] if 'sellLimits' in config else [],
                history.sell_history)
        except Exception as e:
            logging.getLogger().warning(
                f"Config file is invalid ({e}). Treating the config file as it has no bands."
            )

            buy_bands = []
            buy_limits = SideLimits([], history.buy_history)
            sell_bands = []
            sell_limits = SideLimits([], history.buy_history)

        return Bands(buy_bands=buy_bands,
                     buy_limits=buy_limits,
                     sell_bands=sell_bands,
                     sell_limits=sell_limits)
Beispiel #3
0
    def __init__(self, reloadable_config: ReloadableConfig, spread_feed: Feed, history: History):
        assert(isinstance(reloadable_config, ReloadableConfig))
        assert(isinstance(history, History))

        try:
            config = reloadable_config.get_config(spread_feed.get()[0])

            self.buy_bands = list(map(BuyBand, config['buyBands']))
            self.buy_limits = SideLimits(config['buyLimits'] if 'buyLimits' in config else [], history.buy_history)
            self.sell_bands = list(map(SellBand, config['sellBands']))
            self.sell_limits = SideLimits(config['sellLimits'] if 'sellLimits' in config else [], history.sell_history)
        except Exception as e:
            self.logger.warning(f"Config file is invalid ({e}). Treating the config file as it has no bands.")

            self.buy_bands = []
            self.buy_limits = SideLimits([], history.buy_history)
            self.sell_bands = []
            self.sell_limits = SideLimits([], history.buy_history)

        if self._bands_overlap(self.buy_bands) or self._bands_overlap(self.sell_bands):
            self.logger.warning("Bands in the config file overlap. Treating the config file as it has no bands.")

            self.buy_bands = []
            self.sell_bands = []