trading_agent.devices.push_channel
¶
Pushes the events worth a phone notification to every phone running the Android app.
It listens to the event bus like the Telegram channel does and words most notifications with the same NotificationFormatter, so a fill reads the same on Telegram and on the phone. The user chooses the kinds in trading_agent.toml's [push] notifications list. Requests that need the user (a permission, a question or a plan) are pushed too, so the user can answer them in the app before they lapse.
Each notification carries the desk's name, so tapping it opens that desk's chat.
Typical usage example:
channel = PushChannel(store, sender, formatter, event_bus, ['fills', 'requests']) await channel.run()
NotificationSender
¶
Bases: Protocol
Anything that can send one notification to one phone, such as FirebaseSender.
send
async
¶
Sends one notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The phone's token. |
required |
title
|
str
|
The title. |
required |
body
|
str
|
The text. |
required |
data
|
dict[str, str]
|
Values the app reads when the notification is tapped. |
required |
Returns:
| Type | Description |
|---|---|
str
|
"sent", "unregistered" or "failed". |
Source code in src/trading_agent/devices/push_channel.py
PushChannel
¶
The worker that turns events into phone notifications.
Subscribes to the bus without sending anything yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
DeviceStore
|
The registered phones. |
required |
sender
|
NotificationSender
|
Sends to one phone. |
required |
formatter
|
NotificationFormatter
|
Words the events. |
required |
event_bus
|
EventBus
|
The bus to listen to. |
required |
notifications
|
Sequence[str]
|
The kinds to push, from [push] notifications; "requests" pushes questions, plans and permission requests. |
required |
Source code in src/trading_agent/devices/push_channel.py
run
async
¶
Pushes notifications as events arrive, until cancelled.
Source code in src/trading_agent/devices/push_channel.py
handle
async
¶
Pushes one event if it is worth a notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
published_event
|
Event
|
The event. |
required |
Source code in src/trading_agent/devices/push_channel.py
push
async
¶
Sends one notification to every registered phone, forgetting phones Firebase no longer knows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
The title. |
required |
body
|
str
|
The text. |
required |
data
|
dict[str, str]
|
Values the app reads when the notification is tapped. |
required |
Returns:
| Type | Description |
|---|---|
int
|
How many phones it was sent to. |
Source code in src/trading_agent/devices/push_channel.py
push_to
async
¶
Sends one notification to one phone, forgetting it when Firebase no longer knows it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
PhoneDevice
|
The phone. |
required |
title
|
str
|
The title. |
required |
body
|
str
|
The text. |
required |
data
|
dict[str, str]
|
Values the app reads when the notification is tapped. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when Firebase accepted the notification. |