Beispiel #1
0
    async def start_market_making(
            self,  # type: HummingbotApplication
            strategy_name: str):
        start_strategy: Callable = get_strategy_starter_file(strategy_name)
        if strategy_name in 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:
                        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)
            if global_config_map["script_enabled"].value:
                script_file = global_config_map["script_file_path"].value
                folder = dirname(script_file)
                if folder == "":
                    script_file = 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.")

            if global_config_map[
                    "ethgasstation_gas_enabled"].value and ethereum_gas_station_required(
                    ):
                EthGasStationLookup.get_instance().start()

            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)
Beispiel #2
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:
                    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() + 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())
                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.")

        if ethereum_gas_station_required(
        ) and not global_config_map["ethgasstation_gas_enabled"].value:
            self._notify(
                f'  - ETH gas station check: Manual gas price is fixed at '
                f'{global_config_map["manual_gas_price"].value}.')

        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