Beispiel #1
0
    async def prompt_a_config_legacy(
        self,  # type: HummingbotApplication
        config: ConfigVar,
        input_value=None,
        assign_default=True,
    ):
        if config.key == "inventory_price":
            await self.inventory_price_prompt_legacy(self.strategy_config_map, input_value)
            return
        if input_value is None:
            if assign_default:
                self.app.set_text(parse_config_default_to_text(config))
            prompt = await config.get_prompt()
            input_value = await self.app.prompt(prompt=prompt, is_password=config.is_secure)

        if self.app.to_stop_config:
            return
        value = parse_cvar_value(config, input_value)
        err_msg = await config.validate(input_value)
        if err_msg is not None:
            self.notify(err_msg)
            config.value = None
            await self.prompt_a_config_legacy(config)
        else:
            config.value = value
Beispiel #2
0
    def test_instance_creation_using_configuration_parameters(self):
        metrics_config = ConfigVar(key="anonymized_metrics_enabled", prompt="")
        metrics_config.value = True
        global_config_map["anonymized_metrics_enabled"] = metrics_config

        url_config = ConfigVar(key="log_server_url", prompt="")
        url_config.value = "localhost/reporting-proxy"
        global_config_map["log_server_url"] = url_config

        interval_config = ConfigVar(key="anonymized_metrics_interval_min",
                                    prompt="")
        interval_config.value = 5
        global_config_map["anonymized_metrics_interval_min"] = interval_config

        instance_id_config = ConfigVar(key="instance_id", prompt="")
        instance_id_config.value = self.instance_id
        global_config_map["instance_id"] = instance_id_config

        metrics_collector = TradeVolumeMetricCollector.from_configuration(
            connector=MagicMock(),
            rate_provider=self.rate_oracle,
            valuation_token="USDT")

        self.assertEqual(5 * 60, metrics_collector._activation_interval)
        self.assertEqual("localhost/reporting-proxy",
                         metrics_collector._dispatcher.log_server_url)
        self.assertEqual(self.instance_id, metrics_collector._instance_id)
        self.assertEqual(self.client_version,
                         metrics_collector._client_version)
        self.assertEqual("USDT", metrics_collector._valuation_token)
    async def prompt_answer(
        self,  # type: HummingbotApplication
        config: ConfigVar,
        input_value: Optional[str] = None,
        assign_default: bool = True,
    ):

        if input_value is None:
            if assign_default:
                self.app.set_text(parse_config_default_to_text(config))
            prompt = await config.get_prompt()
            input_value = await self.app.prompt(prompt=prompt)

        if self.app.to_stop_config:
            return
        config.value = parse_cvar_value(config, input_value)
        err_msg = await config.validate(input_value)
        if err_msg is not None:
            self.notify(err_msg)
            config.value = None
            await self.prompt_answer(config)
 async def prompt_a_config(
         self,  # type: HummingbotApplication
         config: ConfigVar,
         input_value=None,
         assign_default=True):
     if input_value is None:
         if assign_default:
             self.app.set_text(parse_config_default_to_text(config))
         input_value = await self.app.prompt(prompt=config.prompt,
                                             is_password=config.is_secure)
     err_msg = config.validate(input_value)
     if err_msg is not None:
         self._notify(err_msg)
         await self.prompt_a_config(config)
     else:
         config.value = parse_cvar_value(config, input_value)
    def test_import_config_file_handles_network_timeouts_legacy(
            self, status_check_all_mock: AsyncMock,
            load_strategy_config_map_from_file: AsyncMock):
        strategy_name = "some_strategy"
        strategy_file_name = f"{strategy_name}.yml"
        status_check_all_mock.side_effect = self.raise_timeout
        strategy_conf_var = ConfigVar("strategy", None)
        strategy_conf_var.value = strategy_name
        load_strategy_config_map_from_file.return_value = {
            "strategy": strategy_conf_var
        }

        with self.assertRaises(asyncio.TimeoutError):
            self.async_run_with_timeout_coroutine_must_raise_timeout(
                self.app.import_config_file(strategy_file_name))
        self.assertEqual(None, self.app.strategy_file_name)
        self.assertEqual(None, self.app.strategy_name)
    def test_import_config_file_success_legacy(
            self, status_check_all_mock: AsyncMock,
            load_strategy_config_map_from_file: AsyncMock):
        strategy_name = "some_strategy"
        strategy_file_name = f"{strategy_name}.yml"
        status_check_all_mock.return_value = True
        strategy_conf_var = ConfigVar("strategy", None)
        strategy_conf_var.value = strategy_name
        load_strategy_config_map_from_file.return_value = {
            "strategy": strategy_conf_var
        }

        self.async_run_with_timeout(
            self.app.import_config_file(strategy_file_name))
        self.assertEqual(strategy_file_name, self.app.strategy_file_name)
        self.assertEqual(strategy_name, self.app.strategy_name)
        self.assertTrue(
            self.cli_mock_assistant.check_log_called_with(
                "\nEnter \"start\" to start market making."))
Beispiel #7
0
    def test_instance_creation_using_configuration_parameters_when_disabled(
            self):
        metrics_config = ConfigVar(key="anonymized_metrics_enabled", prompt="")
        metrics_config.value = False
        global_config_map["anonymized_metrics_enabled"] = metrics_config

        metrics_collector = TradeVolumeMetricCollector.from_configuration(
            connector=MagicMock(),
            rate_provider=self.rate_oracle,
            valuation_token="USDT")

        self.assertEqual(DummyMetricsCollector, type(metrics_collector))

        del (global_config_map["anonymized_metrics_enabled"])

        metrics_collector = TradeVolumeMetricCollector.from_configuration(
            connector=MagicMock(),
            rate_provider=self.rate_oracle,
            valuation_token="USDT")

        self.assertEqual(DummyMetricsCollector, type(metrics_collector))
Beispiel #8
0
    def test_list_configs(self, notify_mock, get_strategy_config_map_mock):
        captures = []
        notify_mock.side_effect = lambda s: captures.append(s)
        strategy_name = "some-strategy"
        self.app.strategy_name = strategy_name

        tables_format_config_var = global_config_map["tables_format"]
        global_config_map.clear()
        global_config_map[
            tables_format_config_var.key] = tables_format_config_var
        tables_format_config_var.value = "psql"
        global_config_map[global_configs_to_display[0]] = ConfigVar(
            key=global_configs_to_display[0], prompt="")
        global_config_map[global_configs_to_display[0]].value = "first"
        global_config_map[global_configs_to_display[1]] = ConfigVar(
            key=global_configs_to_display[1], prompt="")
        global_config_map[global_configs_to_display[1]].value = "second"
        global_config_map[color_settings_to_display[0]] = ConfigVar(
            key=color_settings_to_display[0], prompt="")
        global_config_map[color_settings_to_display[0]].value = "third"
        global_config_map[color_settings_to_display[1]] = ConfigVar(
            key=color_settings_to_display[1], prompt="")
        global_config_map[color_settings_to_display[1]].value = "fourth"
        strategy_config_map_mock = {
            "five": ConfigVar(key="five", prompt=""),
            "six": ConfigVar(key="six", prompt="", default="sixth"),
        }
        strategy_config_map_mock["five"].value = "fifth"
        strategy_config_map_mock["six"].value = "sixth"
        get_strategy_config_map_mock.return_value = strategy_config_map_mock

        self.app.list_configs()

        self.assertEqual(6, len(captures))
        self.assertEqual("\nGlobal Configurations:", captures[0])

        df_str_expected = ("    +---------------------+-----------+"
                           "\n    | Key                 |   Value   |"
                           "\n    |---------------------+-----------|"
                           "\n    | tables_format       | psql      |"
                           "\n    | autofill_import     | first     |"
                           "\n    | kill_switch_enabled | second    |"
                           "\n    +---------------------+-----------+")

        self.assertEqual(df_str_expected, captures[1])
        self.assertEqual("\nColor Settings:", captures[2])

        df_str_expected = ("    +-------------+-----------+"
                           "\n    | Key         |   Value   |"
                           "\n    |-------------+-----------|"
                           "\n    | top-pane    | third     |"
                           "\n    | bottom-pane | fourth    |"
                           "\n    +-------------+-----------+")

        self.assertEqual(df_str_expected, captures[3])
        self.assertEqual("\nStrategy Configurations:", captures[4])

        df_str_expected = ("    +-------+-----------+"
                           "\n    | Key   |   Value   |"
                           "\n    |-------+-----------|"
                           "\n    | five  | fifth     |"
                           "\n    | six   | sixth     |"
                           "\n    +-------+-----------+")

        self.assertEqual(df_str_expected, captures[5])