Skip to content

trading_agent.tools.schedule_wakeup_tool

The schedule_wakeup tool: wakes the desk once, later, with a message to itself.

Typical usage example:

tool = ScheduleWakeupTool(store)

ScheduleWakeupArguments

Bases: BaseModel

The arguments of schedule_wakeup.

Attributes:

Name Type Description
minutes int | None

Wake up this many minutes from now.

at str | None

Or wake up at this India time today, as HH:MM; tomorrow when it has passed.

message str

What to tell yourself when you wake, such as what to check.

ScheduleWakeupTool

ScheduleWakeupTool(store)

Bases: Tool

Adds a one-off job that messages the desk.

Creates the tool.

Parameters:

Name Type Description Default
store CronJobStore

The desk's jobs.

required
Source code in src/trading_agent/tools/schedule_wakeup_tool.py
def __init__(self, store: cron_job_store_module.CronJobStore):
    """Creates the tool.

    Args:
        store (cron_job_store_module.CronJobStore): The desk's jobs.
    """
    self._store = store

run async

run(arguments)

Stores the one-off job.

Parameters:

Name Type Description Default
arguments ScheduleWakeupArguments

When, and the message.

required

Returns:

Type Description
ToolResult

When the desk will wake.

Source code in src/trading_agent/tools/schedule_wakeup_tool.py
async def run(self, arguments: ScheduleWakeupArguments) -> tool.ToolResult:
    """Stores the one-off job.

    Args:
        arguments (ScheduleWakeupArguments): When, and the message.

    Returns:
        tool.ToolResult: When the desk will wake.
    """
    now = datetime.datetime.now(_INDIA)
    if arguments.minutes is not None:
        moment = now + datetime.timedelta(minutes=arguments.minutes)
    else:
        moment = datetime.datetime.combine(
            now.date(),
            datetime.time.fromisoformat(arguments.at),
            tzinfo=_INDIA,
        )
        if moment <= now:
            moment = moment + datetime.timedelta(days=1)
    job = cron_job_module.CronJob.new(
        name=f'Wake-up: {arguments.message[:40]}',
        kind=cron_job_module.AGENT,
        schedule=None,
        run_at=moment.isoformat(timespec='seconds'),
        text=arguments.message,
        trading_days_only=False,
        created_by='desk',
    )
    self._store.add(job)
    return tool.ToolResult.success(
        f'You will be woken at {moment:%a %d %b %H:%M} India time (job {job.job_id}).'
    )