agent0.core.hyperdrive.interactive.chain
The chain objects that encapsulates a chain.
Classes
A class that represents a ethereum node. |
Module Contents
- class agent0.core.hyperdrive.interactive.chain.Chain(rpc_uri: str, config: Config | None = None)
A class that represents a ethereum node.
- class Config
The configuration for the chain object.
- log_filename: str | None = None
Path and name of the log file. Won’t log to file if None. Defaults to None.
- log_max_bytes: int | None = None
Maximum size of the log file in bytes. Defaults to hyperlogs.DEFAULT_LOG_MAXBYTES.
- log_level_threshold: int | None = None
Threshold for log level in logging. Defaults to hyperlogs.DEFAULT_LOG_LEVEL.
- delete_previous_logs: bool = False
Whether to delete previous log file if it exists. Defaults to False.
- log_to_stdout: bool = True
Whether to log to standard output. Defaults to True.
- log_format_string: str | None = None
Log formatter object. Defaults to None.
- keep_previous_handlers: bool = False
Whether to keep previous handlers. Defaults to False.
- exception_on_policy_error: bool = True
When executing agent policies, whether to raise an exception if an error is encountered. Defaults to True.
- exception_on_policy_slippage: bool = False
When executing agent policies, whether to raise an exception if the slippage is too large. Defaults to False.
- preview_before_trade: bool = False
Whether to preview the position before executing a trade. Defaults to False.
- crash_log_level: int = 40
The log level to log crashes at. Defaults to error.
- crash_report_stdout_summary: bool = 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.
- log_to_rollbar: bool = False
Whether to log crash reports to rollbar. Defaults to False.
- rollbar_log_level_threshold: int = 10
Threshold for log level in rollbar. Defaults to debug (i.e., log all to rollbar).
- rollbar_log_prefix: str | None = None
Additional prefix for this hyperdrive to log to rollbar.
- rollbar_log_filter_func: Callable[[Exception], bool] | None = 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.
- crash_report_additional_info: dict[str, Any] | None = None
Additional information to include in the crash report.
- always_execute_policy_post_action: bool = 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.
- log_anvil_state_dump: bool = False
Whether to log the anvil state dump in crash reports. Defaults to False.
- calc_pnl: bool = True
Whether to calculate pnl. Defaults to True.
- no_postgres: bool = False
Don’t launch postgres connection at all. Expect things to break if this is set to True.
- use_existing_postgres: bool = 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.
- db_port: int = 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.
- remove_existing_db_container: bool = True
Whether to remove the existing container if it exists on container launch. Defaults to True. Not used if use_existing_postgres is True.
- backfill_pool_info: bool = True
Determines if we keep the pool info for every block in the database. Defaults to True.
- rng_seed: int | None = None
The seed for the random number generator. Defaults to None.
- rng: numpy.random.Generator | None = None
The experiment’s stateful random number generator. Defaults to creating a generator from the provided random seed if not set.
- txn_receipt_timeout: float | None = None
The timeout for waiting for a transaction receipt in seconds. Defaults to 120.
- gas_limit: int | None = 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.
- txn_signature: bytes | None = None
The signature for transactions. Defaults to 0xa0.
- rpc_uri
- docker_client = None
- postgres_container = None
- db_session = None
- config = None
- cleanup()
General cleanup of resources of interactive hyperdrive.
- block_number() eth_typing.BlockNumber
Get the current block number on the chain.
- Returns:
The current block number
- Return type:
int
- block_data(block_identifier: web3.types.BlockIdentifier = 'latest') web3.types.BlockData
Get the current block on the chain.
- Parameters:
block_identifier – The identifier of the block to get. Defaults to ‘latest’.
- Returns:
The current block number
- Return type:
int
- block_time() web3.types.Timestamp
Get the current block time on the chain.
- Returns:
The current block number
- Return type:
int
- property is_local_chain: bool
Returns if this object is a local chain.
- property name: str
Returns the name of the chain, which is the base hostname of the rpc uri.
- property chain_id: int
Returns the chain id of the chain.
- 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.
- Parameters:
private_key (str, optional) – The private key of the associated account. Must be supplied to allow this agent to do any transactions.
public_address (str | None, optional) – 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.
pool (LocalHyperdrive, optional) – An optional pool to set as the active pool.
policy (HyperdrivePolicy, optional) – An optional policy to set as the active policy.
policy_config (HyperdrivePolicy, optional) – The configuration for the attached policy.
name (str, optional) – The name of the agent. Defaults to the wallet address.
- Returns:
The agent object for a user to execute trades with.
- Return type:
- dump_db(save_dir: pathlib.Path) None
Export the managed database to file.
- Parameters:
save_dir (Path) – The output directory to dump the data to.
- load_db(load_dir: pathlib.Path) None
Import the managed database from file.
- Parameters:
load_dir (Path) – The directory that contains the exported database.