agent0.chainsync.analysis.db_to_analysis ======================================== .. py:module:: agent0.chainsync.analysis.db_to_analysis .. autoapi-nested-parse:: Functions to gather data from postgres, do analysis, and add back into postgres. .. !! processed by numpydoc !! Functions --------- .. autoapisummary:: agent0.chainsync.analysis.db_to_analysis.db_to_analysis agent0.chainsync.analysis.db_to_analysis.snapshot_positions_to_db Module Contents --------------- .. py:function:: db_to_analysis(db_session: sqlalchemy.orm.Session, interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], block_number: int, calc_pnl: bool = True) -> None Function to query postgres data tables and insert to analysis tables. Executes analysis on a batch of blocks, defined by start and end block. :param db_session: The initialized db session. :type db_session: Session :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param block_number: The block number to run analysis on. :type block_number: int :param calc_pnl: Whether to calculate pnl. Defaults to True. :type calc_pnl: bool, optional .. !! processed by numpydoc !! .. py:function:: snapshot_positions_to_db(interfaces: list[agent0.ethpy.hyperdrive.HyperdriveReadInterface], wallet_addr: str | None, calc_pnl: bool, db_session: sqlalchemy.orm.Session, block_number: int) Function to query the trade events table and takes a snapshot of the current positions and pnl. .. note:: This function does not scale well in simulation mode, as this table grows for all wallets, for all positions, for every snapshot period (currently set to every block). We can try to alleviate this by (1) increasing the snapshot period, and (2) removing duplicate entries of closed positions (since their `realized_value` never changes). This shouldn't be a problem for remote mode, as we limit this table to (1) only agents managed by agent0, and (2) only adds an entry for every explicit "get_all_positions" call. :param interfaces: A collection of Hyperdrive interface objects, each connected to a pool. :type interfaces: list[HyperdriveReadInterface] :param wallet_addr: The wallet address to query. If None, will not filter events by wallet addr. :type wallet_addr: str | None :param db_session: The database session. :type db_session: Session :param calc_pnl: Whether to calculate pnl. :type calc_pnl: bool :param block_number: The block number to snapshot positions on. :type block_number: int .. !! processed by numpydoc !!