trading_agent.devices.firebase_sender
¶
Sends one push notification to one phone through Firebase Cloud Messaging.
Firebase's HTTP v1 API needs a short-lived OAuth access token, which google-auth makes from the service-account key file the user downloaded from the Firebase console. The token lasts about an hour and is renewed when it runs out. The Firebase project is read from the same key file.
The notification's title and text pass through Google's servers on their way to the phone.
Typical usage example:
sender = FirebaseSender(Path('/home/pramod/.config/trading-agent/firebase.json')) outcome = await sender.send(token, 'scalper', 'COMPLETE buy 50 RELIANCE', {'desk': 'scalper'})
FirebaseSender
¶
Sends notifications with one Firebase project's key.
Reads the key file without contacting Google.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_account_file
|
Path
|
The service-account key JSON from the Firebase console. |
required |
client
|
AsyncClient | None
|
The HTTP client to send with; None makes one. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The file is not a service-account key. |
FileNotFoundError
|
The file does not exist. |
Source code in src/trading_agent/devices/firebase_sender.py
send
async
¶
Sends one notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The phone's Firebase Cloud Messaging token. |
required |
title
|
str
|
The notification's title, such as the desk's name. |
required |
body
|
str
|
The notification's text. |
required |
data
|
Mapping[str, str]
|
Values the app reads when the notification is tapped, such as the desk. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SENT, UNREGISTERED when Firebase says the token is no longer valid, or FAILED for any other problem. |