Skip to content

trading_agent.tools.cancel_price_alert_tool

The cancel_price_alert tool: removes one of the desk's price alerts.

Typical usage example:

tool = CancelPriceAlertTool(store)

CancelPriceAlertArguments

Bases: BaseModel

The arguments of cancel_price_alert.

Attributes:

Name Type Description
alert_id str

The alert's id, as set_price_alert listed it.

CancelPriceAlertTool

CancelPriceAlertTool(store)

Bases: Tool

Removes a price alert.

Creates the tool.

Parameters:

Name Type Description Default
store PriceAlertStore

The desk's alerts.

required
Source code in src/trading_agent/tools/cancel_price_alert_tool.py
def __init__(self, store: price_alert_store_module.PriceAlertStore):
    """Creates the tool.

    Args:
        store (price_alert_store_module.PriceAlertStore): The desk's alerts.
    """
    self._store = store

run async

run(arguments)

Removes the alert.

Parameters:

Name Type Description Default
arguments CancelPriceAlertArguments

The alert's id.

required

Returns:

Type Description
ToolResult

A confirmation with the alerts left, or why nothing was removed.

Source code in src/trading_agent/tools/cancel_price_alert_tool.py
async def run(
    self, arguments: CancelPriceAlertArguments
) -> tool.ToolResult:
    """Removes the alert.

    Args:
        arguments (CancelPriceAlertArguments): The alert's id.

    Returns:
        tool.ToolResult: A confirmation with the alerts left, or why nothing was removed.
    """
    removed = self._store.remove(arguments.alert_id)
    remaining = self._store.alerts()
    listing = (
        '; '.join(
            f'{alert.alert_id}: {alert.describe()}' for alert in remaining
        )
        or 'none'
    )
    if removed is None:
        return tool.ToolResult.error(
            f'No alert {arguments.alert_id}. Active alerts: {listing}.'
        )
    return tool.ToolResult.success(
        f'Removed {removed.describe()}. Active alerts: {listing}.'
    )