trading_agent.gateway.routes.schedule_routes
¶
Routes for each desk's scheduled jobs and price alerts.
GET /api/desks/{desk}/jobs the jobs, built-in ones included, with their next runs, and the recent runs POST /api/desks/{desk}/jobs create a job, as cron_create does DELETE /api/desks/{desk}/jobs/{job_id} delete a job; the built-in ones cannot be deleted here POST /api/desks/{desk}/jobs/{job_id}/run start a job now GET /api/desks/{desk}/alerts the desk's price alerts DELETE /api/desks/{desk}/alerts/{alert_id} remove an alert
Typical usage example:
application.include_router(ScheduleRoutes(guard, parts, scheduler).router())
JobRequest
¶
Bases: BaseModel
The body of a new job.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
A short name. |
schedule |
str | None
|
Five cron fields in India time, or None for a one-off job. |
run_at |
str | None
|
The ISO 8601 time of a one-off job, or None. |
instructions |
str | None
|
For an agent job, the message or the subagent's task. |
command |
str | None
|
For a command job instead, the shell command. |
target |
str
|
"desk" or "subagent: |
trading_days_only |
bool
|
Whether to skip weekends and exchange holidays. |
market_hours_only |
bool
|
Whether to run only while NSE equities trade. |
deliver_url |
str | None
|
An address to POST the result to, or None. |
ScheduleRoutes
¶
Bases: RouteGroup
The job and alert routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
AccessGuard
|
Checks the access token. |
required |
parts
|
Mapping[str, DeskParts]
|
Each desk's stores. |
required |
scheduler
|
CronScheduler
|
Works out next runs and starts jobs now. |
required |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
list_jobs
¶
The desk's jobs and recent runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Each job with its description, next three runs and last run, and the latest runs. |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
create_job
¶
Creates a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
request
|
JobRequest
|
The job. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The job, with its description and next runs. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The job is not valid (status 400). |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
delete_job
¶
Deletes a job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
job_id
|
str
|
The job. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The deleted job's description. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The job is built in (status 400) or unknown (status 404). |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
run_job
async
¶
Starts a job now.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
job_id
|
str
|
The job. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A confirmation; results arrive as events. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The desk or job is unknown (status 404). |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
list_alerts
¶
The desk's price alerts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The alerts, oldest first. |
Source code in src/trading_agent/gateway/routes/schedule_routes.py
delete_alert
¶
Removes a price alert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
alert_id
|
str
|
The alert. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The removed alert's description. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The alert is unknown (status 404). |