trading_agent.scheduling.price_alert_store
¶
Keeps one desk's price alerts: wake me when this instrument trades above or below a price.
Alerts live in desks/<desk>/alerts.json. The market watcher checks them every cycle while the market is open, wakes the desk when one is crossed, and removes it, so each alert fires once.
Typical usage example:
store = PriceAlertStore(Path('workspace/desks/main/alerts.json')) store.add(alert)
PriceAlert
dataclass
¶
One price alert.
Attributes:
| Name | Type | Description |
|---|---|---|
alert_id |
str
|
A short identifier. |
instrument_id |
str
|
UBI's id for the instrument. |
exchange |
str
|
The instrument's exchange. |
segment |
str
|
Its segment. |
symbol |
str
|
Its symbol, for messages. |
condition |
str
|
"above" or "below". |
price |
float
|
The price that fires the alert. |
note |
str
|
What the desk wanted to do when it fires. |
created_at |
str
|
When it was set, as an ISO 8601 string. |
new
classmethod
¶
Creates an alert with a fresh identifier and creation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**fields
|
Any
|
The other fields. |
{}
|
Returns:
| Type | Description |
|---|---|
PriceAlert
|
The alert. |
Source code in src/trading_agent/scheduling/price_alert_store.py
is_crossed
¶
Says whether a price fires the alert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_price
|
float
|
The latest traded price. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the price is at or beyond the alert's price on its side. |
Source code in src/trading_agent/scheduling/price_alert_store.py
describe
¶
The alert in one line.
Returns:
| Type | Description |
|---|---|
str
|
Such as "INFY above 1,175.00 (sell half)". |
Source code in src/trading_agent/scheduling/price_alert_store.py
PriceAlertStore
¶
One desk's alerts file.
Describes the file without touching the disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The desk's alerts.json. |
required |
Source code in src/trading_agent/scheduling/price_alert_store.py
alerts
¶
Reads the alerts; a damaged entry is logged and left out.
Returns:
| Type | Description |
|---|---|
list[PriceAlert]
|
The alerts, oldest first. |
Source code in src/trading_agent/scheduling/price_alert_store.py
add
¶
remove
¶
Removes an alert.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alert_id
|
str
|
The alert's identifier. |
required |
Returns:
| Type | Description |
|---|---|
PriceAlert | None
|
The removed alert, or None when there was none with that id. |