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)
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)
async def start_market_making(self, # type: HummingbotApplication restore: Optional[bool] = False): try: self.start_time = time.time() * 1e3 # Time in milliseconds self.clock = Clock(ClockMode.REALTIME) for market in self.markets.values(): if market is not None: self.clock.add_iterator(market) self.markets_recorder.restore_market_states(self.strategy_file_name, market) if len(market.limit_orders) > 0: if restore is False: self.notify(f"Canceling 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.global_config_map[global_config.PMM_SCRIPT_ENABLED_KEY].value: pmm_script_file = global_config.global_config_map[global_config.PMM_SCRIPT_FILE_PATH_KEY].value folder = dirname(pmm_script_file) if folder == "": pmm_script_file = join(settings.PMM_SCRIPTS_PATH, pmm_script_file) if self.strategy_name != "pure_market_making": self.notify("Error: PMM script feature is only available for pure_market_making strategy.") else: self._pmm_script_iterator = PMMScriptIterator(pmm_script_file, list(self.markets.values()), self.strategy, 0.1) self.clock.add_iterator(self._pmm_script_iterator) self.notify(f"PMM script ({pmm_script_file}) started.") self.strategy_task: asyncio.Task = safe_ensure_future(self._run_clock(), loop=self.ev_loop) self.notify(f"\n'{self.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)