Пример #1
0
    async def start_market_making(
            self,  # type: HummingbotApplication
            strategy_name: str,
            restore: Optional[bool] = False):
        start_strategy: Callable = get_strategy_starter_file(strategy_name)
        if strategy_name in settings.STRATEGIES:
            start_strategy(self)
        else:
            raise NotImplementedError

        try:
            config_path: str = self.strategy_file_name
            self.start_time = time.time() * 1e3  # Time in milliseconds
            self.clock = Clock(ClockMode.REALTIME)
            if self.wallet is not None:
                self.clock.add_iterator(self.wallet)
            for market in self.markets.values():
                if market is not None:
                    self.clock.add_iterator(market)
                    self.markets_recorder.restore_market_states(
                        config_path, market)
                    if len(market.limit_orders) > 0:
                        if restore is False:
                            self._notify(
                                f"Cancelling dangling limit orders on {market.name}..."
                            )
                            await market.cancel_all(5.0)
                        else:
                            self._notify(
                                f"Restored {len(market.limit_orders)} limit orders on {market.name}..."
                            )
            if self.strategy:
                self.clock.add_iterator(self.strategy)
            if global_config_map["script_enabled"].value:
                script_file = global_config_map["script_file_path"].value
                folder = dirname(script_file)
                if folder == "":
                    script_file = join(settings.SCRIPTS_PATH, script_file)
                if self.strategy_name != "pure_market_making":
                    self._notify(
                        "Error: script feature is only available for pure_market_making strategy (for now)."
                    )
                else:
                    self._script_iterator = ScriptIterator(
                        script_file, list(self.markets.values()),
                        self.strategy, 0.1)
                    self.clock.add_iterator(self._script_iterator)
                    self._notify(f"Script ({script_file}) started.")
            # TODO: HAHA this is where everything starts
            self.strategy_task: asyncio.Task = safe_ensure_future(
                self._run_clock(), loop=self.ev_loop)
            self._notify(f"\n'{strategy_name}' strategy started.\n"
                         f"Run `status` command to query the progress.")
            self.logger().info("start command initiated.")

            if self._trading_required:
                self.kill_switch = KillSwitch(self)
                await self.wait_till_ready(self.kill_switch.start)
        except Exception as e:
            self.logger().error(str(e), exc_info=True)
Пример #2
0
 def _initialize_strategy(self, strategy_name: str):
     if self.is_current_strategy_script_strategy():
         self.start_script_strategy()
     else:
         start_strategy: Callable = get_strategy_starter_file(strategy_name)
         if strategy_name in settings.STRATEGIES:
             start_strategy(self)
         else:
             raise NotImplementedError
Пример #3
0
    async def start_market_making(
            self,  # type: HummingbotApplication
            strategy_name: str):
        await ExchangeRateConversion.get_instance().ready_notifier.wait()

        start_strategy: Callable = get_strategy_starter_file(strategy_name)
        if strategy_name in STRATEGIES:
            start_strategy(self)
        else:
            raise NotImplementedError

        try:
            config_path: str = in_memory_config_map.get(
                "strategy_file_path").value
            self.start_time = time.time() * 1e3  # Time in milliseconds
            self.clock = Clock(ClockMode.REALTIME)
            if self.wallet is not None:
                self.clock.add_iterator(self.wallet)
            for market in self.markets.values():
                if market is not None:
                    self.clock.add_iterator(market)
                    self.markets_recorder.restore_market_states(
                        config_path, market)
                    if len(market.limit_orders) > 0:
                        self._notify(
                            f"  Cancelling dangling limit orders on {market.name}..."
                        )
                        await market.cancel_all(5.0)
            if self.strategy:
                self.clock.add_iterator(self.strategy)
            self.strategy_task: asyncio.Task = safe_ensure_future(
                self._run_clock(), loop=self.ev_loop)
            self._notify(
                f"\n  '{strategy_name}' strategy started.\n"
                f"  You can use the `status` command to query the progress.")

            if not self.starting_balances:
                self.starting_balances = await self.wait_till_ready(
                    self.balance_snapshot)

            if self._trading_required:
                self.kill_switch = KillSwitch(self)
                await self.wait_till_ready(self.kill_switch.start)
        except Exception as e:
            self.logger().error(str(e), exc_info=True)