trading_agent.gateway.routes.device_routes
¶
Routes for the phones that receive push notifications.
GET /api/devices whether push is on, and the registered phones POST /api/devices register this phone's Firebase token DELETE /api/devices/{device_id} remove a phone POST /api/devices/{device_id}/test send a test notification to a phone
The Firebase tokens themselves are never sent back, only the phones' ids and names.
Typical usage example:
application.include_router(DeviceRoutes(guard, store, channel, problem).router())
DeviceRegistration
¶
Bases: BaseModel
What the app sends to register a phone.
Attributes:
| Name | Type | Description |
|---|---|---|
token |
str
|
The phone's Firebase Cloud Messaging token. |
name |
str
|
The phone's name, such as "Samsung SM-M536B". |
DeviceRoutes
¶
Bases: RouteGroup
The device routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
AccessGuard
|
Checks the access token. |
required |
store
|
DeviceStore
|
The registered phones. |
required |
channel
|
PushChannel | None
|
The running push channel, or None when push is off. |
required |
problem
|
str
|
Why push is off, or an empty string when it is on. |
required |
Source code in src/trading_agent/gateway/routes/device_routes.py
devices
¶
Whether push is on, and the registered phones.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
"enabled", "problem" and "devices", each phone without its token. |
Source code in src/trading_agent/gateway/routes/device_routes.py
register
¶
Registers a phone, or renames it when its token is known.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registration
|
DeviceRegistration
|
The phone's token and name. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The phone, without its token. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The store is full (status 409). |
Source code in src/trading_agent/gateway/routes/device_routes.py
remove
¶
Removes a phone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
str
|
The phone's id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The phone that was removed, without its token. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
No phone has that id (status 404). |
Source code in src/trading_agent/gateway/routes/device_routes.py
test
async
¶
Sends a test notification to one phone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_id
|
str
|
The phone. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
"sent", whether Firebase accepted the notification. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
Push is off (status 409), or no phone has that id (status 404). |