trading_agent.gateway.routes.webhook_routes
¶
The incoming webhook: POST /hooks/wake/
It lets TradingView alerts, or the user's own scripts, wake a desk. The body is the message: plain text, or JSON whose "text" or "message" field is used, and anything else as JSON text. The webhook token goes in a token query parameter, because TradingView cannot set headers, or in an X-Webhook-Token header. It is a separate token from the gateway's, so pasting it into another service never exposes the token that controls the gateway. Without a webhook token in .env, the route answers 404, as if it did not exist.
Typical usage example:
application.include_router(WebhookRoutes(desks, secrets.webhook_token).router())
WebhookRoutes
¶
Builds the /hooks/wake route.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desks
|
Mapping[str, DeskRuntime]
|
The running desks, keyed by name. |
required |
token
|
str
|
The webhook token, or an empty string to switch webhooks off. |
required |
Source code in src/trading_agent/gateway/routes/webhook_routes.py
router
¶
Builds the router.
Returns:
| Type | Description |
|---|---|
APIRouter
|
The router holding the webhook route. |
Source code in src/trading_agent/gateway/routes/webhook_routes.py
wake
async
¶
Queues the webhook's message for a desk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk to wake. |
required |
request
|
Request
|
The request, for its body and headers. |
required |
token
|
str
|
The webhook token from the query string, if given there. |
''
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The new trigger's identifier. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
Webhooks are off (404), the token is wrong (401), the desk does not exist (404), or the body is empty (400). |