agent0.core.hyperdrive.interactive.chain ======================================== .. py:module:: agent0.core.hyperdrive.interactive.chain .. autoapi-nested-parse:: The chain objects that encapsulates a chain. .. !! processed by numpydoc !! Classes ------- .. autoapisummary:: agent0.core.hyperdrive.interactive.chain.Chain Module Contents --------------- .. py:class:: Chain(rpc_uri: str, config: Config | None = None) A class that represents a ethereum node. .. !! processed by numpydoc !! .. py:class:: Config The configuration for the chain object. .. !! processed by numpydoc !! .. py:attribute:: log_filename :type: str | None :value: None Path and name of the log file. Won't log to file if None. Defaults to None. .. !! processed by numpydoc !! .. py:attribute:: log_max_bytes :type: int | None :value: None Maximum size of the log file in bytes. Defaults to hyperlogs.DEFAULT_LOG_MAXBYTES. .. !! processed by numpydoc !! .. py:attribute:: log_level_threshold :type: int | None :value: None Threshold for log level in logging. Defaults to hyperlogs.DEFAULT_LOG_LEVEL. .. !! processed by numpydoc !! .. py:attribute:: delete_previous_logs :type: bool :value: False Whether to delete previous log file if it exists. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: log_to_stdout :type: bool :value: True Whether to log to standard output. Defaults to True. .. !! processed by numpydoc !! .. py:attribute:: log_format_string :type: str | None :value: None Log formatter object. Defaults to None. .. !! processed by numpydoc !! .. py:attribute:: keep_previous_handlers :type: bool :value: False Whether to keep previous handlers. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: exception_on_policy_error :type: bool :value: True When executing agent policies, whether to raise an exception if an error is encountered. Defaults to True. .. !! processed by numpydoc !! .. py:attribute:: exception_on_policy_slippage :type: bool :value: False When executing agent policies, whether to raise an exception if the slippage is too large. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: preview_before_trade :type: bool :value: False Whether to preview the position before executing a trade. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: crash_log_level :type: int :value: 40 The log level to log crashes at. Defaults to error. .. !! processed by numpydoc !! .. py:attribute:: crash_report_stdout_summary :type: bool :value: True Whether to print a summary of the crash report to stdout (if True), or print out the full report (if False). Defaults to True. .. !! processed by numpydoc !! .. py:attribute:: log_to_rollbar :type: bool :value: False Whether to log crash reports to rollbar. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: rollbar_log_level_threshold :type: int :value: 10 Threshold for log level in rollbar. Defaults to debug (i.e., log all to rollbar). .. !! processed by numpydoc !! .. py:attribute:: rollbar_log_prefix :type: str | None :value: None Additional prefix for this hyperdrive to log to rollbar. .. !! processed by numpydoc !! .. py:attribute:: rollbar_log_filter_func :type: Callable[[Exception], bool] | None :value: None A function that filters exceptions to log to rollbar. The function should return `True` for exceptions that should be filtered from rollbar logging. Defaults to logging all exceptions. .. !! processed by numpydoc !! .. py:attribute:: crash_report_additional_info :type: dict[str, Any] | None :value: None Additional information to include in the crash report. .. !! processed by numpydoc !! .. py:attribute:: always_execute_policy_post_action :type: bool :value: False Whether to execute the policy `post_action` function after non-policy trades. If True, the policy `post_action` function always be called after any agent trade. If False, the policy `post_action` function will only be called after `execute_policy_action`. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: log_anvil_state_dump :type: bool :value: False Whether to log the anvil state dump in crash reports. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: calc_pnl :type: bool :value: True Whether to calculate pnl. Defaults to True. .. !! processed by numpydoc !! .. py:attribute:: no_postgres :type: bool :value: False Don't launch postgres connection at all. Expect things to break if this is set to True. .. !! processed by numpydoc !! .. py:attribute:: use_existing_postgres :type: bool :value: False If True, will connect to a remote postgres instance using environmental variables (see env.sample). If False, will manage a local postgres instance. Defaults to False. .. !! processed by numpydoc !! .. py:attribute:: db_port :type: int :value: 5433 The port to bind for the postgres container. Will fail if this port is being used. Defaults to 5433. Not used if `use_existing_postgres` is True. .. !! processed by numpydoc !! .. py:attribute:: remove_existing_db_container :type: bool :value: True Whether to remove the existing container if it exists on container launch. Defaults to True. Not used if `use_existing_postgres` is True. .. !! processed by numpydoc !! .. py:attribute:: backfill_pool_info :type: bool :value: True Determines if we keep the pool info for every block in the database. Defaults to True. .. !! processed by numpydoc !! .. py:attribute:: rng_seed :type: int | None :value: None The seed for the random number generator. Defaults to None. .. !! processed by numpydoc !! .. py:attribute:: rng :type: numpy.random.Generator | None :value: None The experiment's stateful random number generator. Defaults to creating a generator from the provided random seed if not set. .. !! processed by numpydoc !! .. py:attribute:: txn_receipt_timeout :type: float | None :value: None The timeout for waiting for a transaction receipt in seconds. Defaults to 120. .. !! processed by numpydoc !! .. py:attribute:: gas_limit :type: int | None :value: None The maximum gas to use when executing transactions. This gas limit controls any transactions that are executed on the chain. NOTE: the policies `gas_limit` overwrites this value if it is set. .. !! processed by numpydoc !! .. py:attribute:: txn_signature :type: bytes | None :value: None The signature for transactions. Defaults to `0xa0`. .. !! processed by numpydoc !! .. py:attribute:: rpc_uri .. py:attribute:: docker_client :value: None .. py:attribute:: postgres_container :value: None .. py:attribute:: db_session :value: None .. py:attribute:: config :value: None .. py:method:: cleanup() General cleanup of resources of interactive hyperdrive. .. !! processed by numpydoc !! .. py:method:: block_number() -> eth_typing.BlockNumber Get the current block number on the chain. :returns: The current block number :rtype: int .. !! processed by numpydoc !! .. py:method:: block_data(block_identifier: web3.types.BlockIdentifier = 'latest') -> web3.types.BlockData Get the current block on the chain. :param block_identifier: The identifier of the block to get. Defaults to 'latest'. :returns: The current block number :rtype: int .. !! processed by numpydoc !! .. py:method:: block_time() -> web3.types.Timestamp Get the current block time on the chain. :returns: The current block number :rtype: int .. !! processed by numpydoc !! .. py:property:: is_local_chain :type: bool Returns if this object is a local chain. .. !! processed by numpydoc !! .. py:property:: name :type: str Returns the name of the chain, which is the base hostname of the rpc uri. .. !! processed by numpydoc !! .. py:property:: chain_id :type: int Returns the chain id of the chain. .. !! processed by numpydoc !! .. py:method:: init_agent(private_key: str | None = None, public_address: str | None = None, pool: agent0.core.hyperdrive.interactive.hyperdrive.Hyperdrive | None = None, policy: Type[agent0.core.hyperdrive.policies.HyperdriveBasePolicy] | None = None, policy_config: agent0.core.hyperdrive.policies.HyperdriveBasePolicy.Config | None = None, name: str | None = None) -> agent0.core.hyperdrive.interactive.hyperdrive_agent.HyperdriveAgent Initialize an agent object given a private key. .. note:: Due to the underlying bookkeeping, each agent object needs a unique private key. :param private_key: The private key of the associated account. Must be supplied to allow this agent to do any transactions. :type private_key: str, optional :param public_address: The public address of the associated account. This allows this agent to be used for analyzing data. Can't be used in conjunction with private_key. :type public_address: str | None, optional :param pool: An optional pool to set as the active pool. :type pool: LocalHyperdrive, optional :param policy: An optional policy to set as the active policy. :type policy: HyperdrivePolicy, optional :param policy_config: The configuration for the attached policy. :type policy_config: HyperdrivePolicy, optional :param name: The name of the agent. Defaults to the wallet address. :type name: str, optional :returns: The agent object for a user to execute trades with. :rtype: HyperdriveAgent .. !! processed by numpydoc !! .. py:method:: dump_db(save_dir: pathlib.Path) -> None Export the managed database to file. :param save_dir: The output directory to dump the data to. :type save_dir: Path .. !! processed by numpydoc !! .. py:method:: load_db(load_dir: pathlib.Path) -> None Import the managed database from file. :param load_dir: The directory that contains the exported database. :type load_dir: Path .. !! processed by numpydoc !!