Exemplo n.º 1
0
    def status(self) -> bool:
        # Preliminary checks.
        self.app.log("\n  Preliminary checks:")
        if self.config_complete:
            self.app.log("   - Config check: Config complete")
        else:
            self.app.log(
                '   x Config check: Pending config. Please enter "config" before starting the bot.'
            )
            return False

        eth_node_valid = check_web3(
            global_config_map.get("ethereum_rpc_url").value)
        if eth_node_valid:
            self.app.log("   - Node check: Ethereum node running and current")
        else:
            self.app.log(
                '   x Node check: Bad ethereum rpc url. Your node may be syncing. '
                'Please re-configure by entering "config ethereum_rpc_url"')
            return False

        if self.wallet is not None:
            if self.wallet.network_status is NetworkStatus.CONNECTED:
                if self._trading_required:
                    has_minimum_eth = self.wallet.get_balance("ETH") > 0.01
                    if has_minimum_eth:
                        self.app.log(
                            "   - ETH wallet check: Minimum ETH requirement satisfied"
                        )
                    else:
                        self.app.log(
                            "   x ETH wallet check: Not enough ETH in wallet. "
                            "A small amount of Ether is required for sending transactions on "
                            "Decentralized Exchanges")
            else:
                self.app.log(
                    "   x ETH wallet check: ETH wallet is not connected.")

        loading_markets: List[MarketBase] = []
        for market in self.markets.values():
            if not market.ready:
                loading_markets.append(market)

        if len(loading_markets) > 0:
            self.app.log(
                f"   x Market check:  Waiting for markets " +
                ",".join([m.name.capitalize() for m in loading_markets]) +
                f" to get ready for trading. \n"
                f"                    Please keep the bot running and try to start again in a few minutes. \n"
            )

            for market in loading_markets:
                market_status_df = pd.DataFrame(
                    data=market.status_dict.items(),
                    columns=["description", "status"])
                self.app.log(
                    f"   x {market.name.capitalize()} market status:\n" +
                    "\n".join([
                        "     " + line for line in market_status_df.to_string(
                            index=False, ).split("\n")
                    ]) + "\n")
            return False

        elif not all([
                market.network_status is NetworkStatus.CONNECTED
                for market in self.markets.values()
        ]):
            offline_markets: List[str] = [
                market_name for market_name, market in self.markets.items()
                if market.network_status is not NetworkStatus.CONNECTED
            ]
            for offline_market in offline_markets:
                self.app.log(
                    f"   x Market check:  {offline_market} is currently offline."
                )

        # See if we can print out the strategy status.
        self.app.log("   - Market check: All markets ready")
        if self.strategy is None:
            self.app.log("   x initializing strategy.")
        else:
            self.app.log(self.strategy.format_status() + "\n")

        # Application warnings.
        self._expire_old_application_warnings()
        if len(self._app_warnings) > 0:
            self.app.log(self._format_application_warnings())

        return True
Exemplo n.º 2
0
    async def status_check_all(self,  # type: HummingbotApplication
                               notify_success=True) -> bool:

        if self.strategy is not None:
            return self.strategy_status()

        # Preliminary checks.
        self._notify("\nPreliminary checks:")
        if self.strategy_name is None or self.strategy_file_name is None:
            self._notify('  - Strategy check: Please import or create a strategy.')
            return False

        if not Security.is_decryption_done():
            self._notify('  - Security check: Encrypted files are being processed. Please wait and try again later.')
            return False

        invalid_conns = await self.validate_required_connections()
        if invalid_conns:
            self._notify('  - Exchange check: Invalid connections:')
            for ex, err_msg in invalid_conns.items():
                self._notify(f"    {ex}: {err_msg}")
        elif notify_success:
            self._notify('  - Exchange check: All connections confirmed.')

        missing_configs = self.missing_configurations()
        if missing_configs:
            self._notify("  - Strategy check: Incomplete strategy configuration. The following values are missing.")
            for config in missing_configs:
                self._notify(f"    {config.key}")
        elif notify_success:
            self._notify('  - Strategy check: All required parameters confirmed.')
        if invalid_conns or missing_configs:
            return False

        if self.wallet is not None:
            # Only check node url when a wallet has been initialized
            eth_node_valid = check_web3(global_config_map.get("ethereum_rpc_url").value)
            if not eth_node_valid:
                self._notify('  - Node check: Bad ethereum rpc url. '
                             'Please re-configure by entering "config ethereum_rpc_url"')
                return False
            elif notify_success:
                self._notify("  - Node check: Ethereum node running and current.")

            if self.wallet.network_status is NetworkStatus.CONNECTED:
                if self._trading_required:
                    has_minimum_eth = self.wallet.get_balance("ETH") > 0.01
                    if not has_minimum_eth:
                        self._notify("  - ETH wallet check: Not enough ETH in wallet. "
                                     "A small amount of Ether is required for sending transactions on "
                                     "Decentralized Exchanges")
                        return False
                    elif notify_success:
                        self._notify("  - ETH wallet check: Minimum ETH requirement satisfied")
            else:
                self._notify("  - ETH wallet check: ETH wallet is not connected.")

        loading_markets: List[MarketBase] = []
        for market in self.markets.values():
            if not market.ready:
                loading_markets.append(market)

        if len(loading_markets) > 0:
            self._notify(f"  - Exchange connectors check:  Waiting for exchange connectors " +
                         ",".join([m.name.capitalize() for m in loading_markets]) + f" to get ready for trading. \n"
                         f"                    Please keep the bot running and try to start again in a few minutes. \n")

            for market in loading_markets:
                market_status_df = pd.DataFrame(data=market.status_dict.items(), columns=["description", "status"])
                self._notify(
                    f"  - {market.display_name.capitalize()} connector status:\n" +
                    "\n".join(["     " + line for line in market_status_df.to_string(index=False,).split("\n")]) +
                    "\n"
                )
            return False

        elif not all([market.network_status is NetworkStatus.CONNECTED for market in self.markets.values()]):
            offline_markets: List[str] = [
                market_name
                for market_name, market
                in self.markets.items()
                if market.network_status is not NetworkStatus.CONNECTED
            ]
            for offline_market in offline_markets:
                self._notify(f"  - Exchange connector check: {offline_market} is currently offline.")
            return False
        self.application_warning()
        self._notify(f"  - All checks: Confirmed.")
        return True
Exemplo n.º 3
0
    async def status_check_all(self,  # type: HummingbotApplication
                               notify_success=True,
                               live=False) -> bool:

        if self.strategy is not None:
            if live:
                await self.stop_live_update()
                self.app.live_updates = True
                while self.app.live_updates and self.strategy:
                    script_status = '\n Status from script would not appear here. ' \
                                    'Simply run the status command without "--live" to see script status.'
                    await self.cls_display_delay(
                        await self.strategy_status(live=True) + script_status + "\n\n Press escape key to stop update.", 1
                    )
                self._notify("Stopped live status display update.")
            else:
                self._notify(await self.strategy_status())
            return True

        # Preliminary checks.
        self._notify("\nPreliminary checks:")
        if self.strategy_name is None or self.strategy_file_name is None:
            self._notify('  - Strategy check: Please import or create a strategy.')
            return False

        if not Security.is_decryption_done():
            self._notify('  - Security check: Encrypted files are being processed. Please wait and try again later.')
            return False

        invalid_conns = await self.validate_required_connections()
        if invalid_conns:
            self._notify('  - Exchange check: Invalid connections:')
            for ex, err_msg in invalid_conns.items():
                self._notify(f"    {ex}: {err_msg}")
        elif notify_success:
            self._notify('  - Exchange check: All connections confirmed.')

        missing_configs = self.missing_configurations()
        if missing_configs:
            self._notify("  - Strategy check: Incomplete strategy configuration. The following values are missing.")
            for config in missing_configs:
                self._notify(f"    {config.key}")
        elif notify_success:
            self._notify('  - Strategy check: All required parameters confirmed.')
        if invalid_conns or missing_configs:
            return False

        if self.wallet is not None:
            # Only check node url when a wallet has been initialized
            eth_node_valid = check_web3(global_config_map.get("ethereum_rpc_url").value)
            if not eth_node_valid:
                self._notify('  - Node check: Bad ethereum rpc url. '
                             'Please re-configure by entering "config ethereum_rpc_url"')
                return False
            elif notify_success:
                self._notify("  - Node check: Ethereum node running and current.")

            if self.wallet.network_status is NetworkStatus.CONNECTED:
                if self._trading_required:
                    has_minimum_eth = self.wallet.get_balance("ETH") > 0.01
                    if not has_minimum_eth:
                        self._notify("  - ETH wallet check: Not enough ETH in wallet. "
                                     "A small amount of Ether is required for sending transactions on "
                                     "Decentralized Exchanges")
                        return False
                    elif notify_success:
                        self._notify("  - ETH wallet check: Minimum ETH requirement satisfied")
            else:
                self._notify("  - ETH wallet check: ETH wallet is not connected.")

        loading_markets: List[ConnectorBase] = []
        for market in self.markets.values():
            if not market.ready:
                loading_markets.append(market)

        if len(loading_markets) > 0:
            self._notify("  - Connectors check:  Waiting for connectors " +
                         ",".join([m.name.capitalize() for m in loading_markets]) + " to get ready for trading. \n"
                         "                    Please keep the bot running and try to start again in a few minutes. \n")

            for market in loading_markets:
                market_status_df = pd.DataFrame(data=market.status_dict.items(), columns=["description", "status"])
                self._notify(
                    f"  - {market.display_name.capitalize()} connector status:\n" +
                    "\n".join(["     " + line for line in market_status_df.to_string(index=False,).split("\n")]) +
                    "\n"
                )
            return False

        elif not all([market.network_status is NetworkStatus.CONNECTED for market in self.markets.values()]):
            offline_markets: List[str] = [
                market_name
                for market_name, market
                in self.markets.items()
                if market.network_status is not NetworkStatus.CONNECTED
            ]
            for offline_market in offline_markets:
                self._notify(f"  - Connector check: {offline_market} is currently offline.")
            return False

        # Paper trade mode is currently not available for connectors other than exchanges.
        # Todo: This check is hard coded at the moment, when we get a clearer direction on how we should handle this,
        # this section will need updating.
        if global_config_map.get("paper_trade_enabled").value:
            if "balancer" in required_exchanges and \
                    str(global_config_map.get("ethereum_chain_name").value).lower() != "kovan":
                self._notify("Error: Paper trade mode is not available on balancer at the moment.")
                return False
            if "binance_perpetual" in required_exchanges:
                self._notify("Error: Paper trade mode is not available on binance_perpetual at the moment.")
                return False

        self.application_warning()
        self._notify("  - All checks: Confirmed.")
        return True