async def stop(self, skip_order_cancellation: bool = False):
        self.app.log("\nWinding down...")

        # Restore App Nap on macOS.
        if platform.system() == "Darwin":
            import appnope
            appnope.nap()

        if not skip_order_cancellation:
            # Remove the strategy from clock before cancelling orders, to
            # prevent race condition where the strategy tries to create more
            # orders during cancellation.
            self.clock.remove_iterator(self.strategy)
            success = await self._cancel_outstanding_orders()
            if success:
                # Only erase markets when cancellation has been successful
                self.markets = {}
        if self.reporting_module:
            self.reporting_module.stop()
        if self.strategy_task is not None and not self.strategy_task.cancelled(
        ):
            self.strategy_task.cancel()
        if self.strategy:
            self.strategy.stop()
        ExchangeRateConversion.get_instance().stop()
        self.stop_loss_tracker.stop()
        self.wallet = None
        self.strategy_task = None
        self.strategy = None
        self.market_pair = None
        self.clock = None
    def start(self, log_level: Optional[str] = None):
        is_valid = self.status()
        if not is_valid:
            return

        if log_level is not None:
            init_logging("hummingbot_logs.yml", override_log_level=log_level.upper())

        ExchangeRateConversion.get_instance().start()
        strategy_name = in_memory_config_map.get("strategy").value
        self.init_reporting_module()
        self.app.log(f"Status check complete. Starting '{strategy_name}' strategy...")
        asyncio.ensure_future(self.start_market_making(strategy_name))
 async def exit(self, force: bool = False):
     if self.strategy_task is not None and not self.strategy_task.cancelled(
     ):
         self.strategy_task.cancel()
     if self.strategy:
         self.strategy.stop()
     if force is False:
         success = await self._cancel_outstanding_orders()
         if not success:
             self.app.log(
                 'Wind down process terminated: Failed to cancel all outstanding orders. '
                 '\nYou may need to manually cancel remaining orders by logging into your chosen exchanges'
                 '\n\nTo force exit the app, enter "exit -f"')
             return
         # Freeze screen 1 second for better UI
         await asyncio.sleep(1)
     ExchangeRateConversion.get_instance().stop()
     self.app.exit()
    def start(self, log_level: Optional[str] = None):
        is_valid = self.status()
        if not is_valid:
            return

        if log_level is not None:
            init_logging("hummingbot_logs.yml",
                         override_log_level=log_level.upper())

        # If macOS, disable App Nap.
        if platform.system() == "Darwin":
            import appnope
            appnope.nope()

        # TODO add option to select data feed
        self.data_feed: DataFeedBase = CoinCapDataFeed.get_instance()

        ExchangeRateConversion.get_instance().start()
        strategy_name = in_memory_config_map.get("strategy").value
        self.init_reporting_module()
        self.app.log(
            f"\n  Status check complete. Starting '{strategy_name}' strategy..."
        )
        asyncio.ensure_future(self.start_market_making(strategy_name))
Esempio n. 5
0
    async def get_active_exchange_markets(cls) -> pd.DataFrame:
        """
        Returned data frame should have symbol as index and include usd volume, baseAsset and quoteAsset
        """
        client: aiohttp.ClientSession = cls.http_client()
        async with client.get(
                f"{MARKETS_URL}?include=ticker,stats") as response:
            response: aiohttp.ClientResponse = response
            if response.status != 200:
                raise IOError(
                    f"Error fetching active Radar Relay markets. HTTP status is {response.status}."
                )
            data = await response.json()
            data: List[Dict[str, any]] = [{
                **item,
                **{
                    "baseAsset": item["id"].split("-")[0],
                    "quoteAsset": item["id"].split("-")[1]
                }
            } for item in data]
            all_markets: pd.DataFrame = pd.DataFrame.from_records(data=data,
                                                                  index="id")

            weth_dai_price: float = float(
                all_markets.loc["WETH-DAI"]["ticker"]["price"])
            dai_usd_price: float = ExchangeRateConversion.get_instance(
            ).adjust_token_rate("DAI", weth_dai_price)
            usd_volume: List[float] = []
            quote_volume: List[float] = []
            for row in all_markets.itertuples():
                product_name: str = row.Index
                base_volume: float = float(row.stats["volume24Hour"])
                quote_volume.append(base_volume)
                if product_name.endswith("WETH"):
                    usd_volume.append(dai_usd_price * base_volume)
                else:
                    usd_volume.append(base_volume)

            all_markets.loc[:, "USDVolume"] = usd_volume
            all_markets.loc[:, "volume"] = quote_volume
            return all_markets.sort_values("USDVolume", ascending=False)
 def setUpClass(cls):
     ExchangeRateConversion.set_global_exchange_rate_config([
         ("WETH", 1.0, "None"),
         ("QETH", 0.95, "None"),
     ])