Skip to content

trading_agent.client.proposal_commands

The trading-agent proposals commands: list, show, accept and reject.

Typical usage example:

exit_code = ProposalCommands(store).run('list', None)

ProposalCommands

ProposalCommands(store, output=stdout)

Prints and changes proposals for the user.

Creates the commands.

Parameters:

Name Type Description Default
store ProposalStore

Where the proposals are.

required
output TextIO

Where to print.

stdout
Source code in src/trading_agent/client/proposal_commands.py
def __init__(
    self,
    store: proposal_store.ProposalStore,
    output: TextIO = sys.stdout,
):
    """Creates the commands.

    Args:
        store (proposal_store.ProposalStore): Where the proposals are.
        output (TextIO): Where to print.
    """
    self._store = store
    self._output = output

run

run(action, proposal_id)

Runs one action.

Parameters:

Name Type Description Default
action str

"list", "show", "accept" or "reject".

required
proposal_id str | None

The proposal, for every action except "list".

required

Returns:

Type Description
int

0 on success, 1 when the proposal does not exist or is not pending.

Source code in src/trading_agent/client/proposal_commands.py
def run(self, action: str, proposal_id: str | None) -> int:
    """Runs one action.

    Args:
        action (str): "list", "show", "accept" or "reject".
        proposal_id (str | None): The proposal, for every action except "list".

    Returns:
        int: 0 on success, 1 when the proposal does not exist or is not pending.
    """
    try:
        if action == 'list':
            self._list()
        elif action == 'show':
            self._show(proposal_id)
        elif action == 'accept':
            target = self._store.accept(proposal_id)
            self._print(
                f"Accepted {proposal_id}: {target} now holds the proposed text. The previous version is in the desk's proposals/replaced folder."
            )
        elif action == 'reject':
            self._store.reject(proposal_id)
            self._print(f'Rejected {proposal_id}. No file was changed.')
    except proposal_store.ProposalError as error:
        self._print(str(error))
        return 1
    return 0