from decimal import Decimal from typing import Dict import pandas as pd from hummingbot.client.ui.interface_utils import format_df_for_printout from hummingbot.connector.connector_base import ConnectorBase from hummingbot.data_feed.amm_gateway_data_feed import AmmGatewayDataFeed from hummingbot.strategy.script_strategy_base import ScriptStrategyBase class AMMDataFeedExample(ScriptStrategyBase): amm_data_feed_pancakeswap = AmmGatewayDataFeed( connector_chain_network="pancakeswap_binance-smart-chain_mainnet", trading_pairs={"APE-USDT"}, order_amount_in_base=Decimal("1"), ) amm_data_feed_sushiswap = AmmGatewayDataFeed( connector_chain_network="sushiswap_binance-smart-chain_mainnet", trading_pairs={"APE-USDT"}, order_amount_in_base=Decimal("1"), ) markets = {"binance_paper_trade": {"APE-USDT"}} def __init__(self, connectors: Dict[str, ConnectorBase]): super().__init__(connectors) self.amm_data_feed_pancakeswap.start() self.amm_data_feed_sushiswap.start() def on_stop(self): self.amm_data_feed_pancakeswap.stop() self.amm_data_feed_sushiswap.stop() def on_tick(self): pass def format_status(self) -> str: if self.amm_data_feed_pancakeswap.is_ready() and self.amm_data_feed_sushiswap.is_ready(): lines = [] rows = [] rows.extend(dict(price) for token, price in self.amm_data_feed_pancakeswap.price_dict.items()) rows.extend(dict(price) for token, price in self.amm_data_feed_sushiswap.price_dict.items()) df = pd.DataFrame(rows) prices_str = format_df_for_printout(df, table_format="psql") lines.append(f"AMM Data Feed is ready.\n{prices_str}") return "\n".join(lines) else: return "AMM Data Feed is not ready."