Skip to content

trading_agent.client.checkpoint_commands

The trading-agent checkpoints commands: list and restore a desk's snapshots.

Typical usage example:

exit_code = CheckpointCommands(checkpoints).run('list', None)

CheckpointCommands

CheckpointCommands(checkpoints, output=stdout)

Prints and restores one desk's checkpoints for the user.

Creates the commands.

Parameters:

Name Type Description Default
checkpoints Checkpoints

The desk's checkpoint repository.

required
output TextIO

Where to print.

stdout
Source code in src/trading_agent/client/checkpoint_commands.py
def __init__(
    self,
    checkpoints: checkpoints_module.Checkpoints,
    output: TextIO = sys.stdout,
):
    """Creates the commands.

    Args:
        checkpoints (checkpoints_module.Checkpoints): The desk's checkpoint repository.
        output (TextIO): Where to print.
    """
    self._checkpoints = checkpoints
    self._output = output

run

run(action, checkpoint_id, limit=20)

Runs one action.

Parameters:

Name Type Description Default
action str

"list" or "restore".

required
checkpoint_id str | None

The checkpoint to restore, for "restore".

required
limit int

The most checkpoints "list" prints.

20

Returns:

Type Description
int

0 on success, 1 when git failed or the checkpoint does not exist.

Source code in src/trading_agent/client/checkpoint_commands.py
def run(
    self,
    action: str,
    checkpoint_id: str | None,
    limit: int = 20,
) -> int:
    """Runs one action.

    Args:
        action (str): "list" or "restore".
        checkpoint_id (str | None): The checkpoint to restore, for "restore".
        limit (int): The most checkpoints "list" prints.

    Returns:
        int: 0 on success, 1 when git failed or the checkpoint does not exist.
    """
    try:
        if action == 'list':
            self._list(limit)
        elif action == 'restore':
            before = self._checkpoints.restore(checkpoint_id)
            self._print(
                f'Restored the desk files to checkpoint {checkpoint_id}. The files as they were just before are checkpoint {before}; restore that to undo this.'
            )
    except checkpoints_module.CheckpointError as error:
        self._print(str(error))
        return 1
    return 0