trading_agent.channels.telegram_commands
¶
The Telegram commands answered by code, with no model.
These work even when every model is unavailable or a desk is paused, which is exactly when the user most needs them: what is happening, what is open, how much is made or lost, stop a desk, or stop everything. Any other message, including the desks' own slash commands such as /usage or /stop, goes to the chat's desk.
Typical usage example:
commands = TelegramCommands(desks, shared, pairing, 'dry_run') if commands.handles('/pnl'): reply = await commands.answer(chat, '/pnl')
TelegramCommands
¶
Answers the code-only commands of one gateway.
Creates the commands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desks
|
Mapping[str, DeskRuntime]
|
The running desks. |
required |
shared
|
SharedParts
|
The snapshot reader, risk engine, ledger and kill switch. |
required |
pairing
|
PairingStore
|
Where each chat's desk is kept. |
required |
mode
|
str
|
"dry_run" or "live". |
required |
clock
|
Callable[[], datetime] | None
|
Returns the current India time; None uses the system clock. |
None
|
request_store
|
UserRequestStore | None
|
The desks' requests, searched by /approve and /deny, or None. |
None
|
responder
|
UserRequestResponder | None
|
Decides permission requests for /approve and /deny, or None. |
None
|
Source code in src/trading_agent/channels/telegram_commands.py
handles
¶
Says whether a message is one of these commands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The message. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True for /start, /help, /desk, /status, /positions, /pnl, /pause, /resume, /kill, /approve and /deny. |
Source code in src/trading_agent/channels/telegram_commands.py
menu
¶
The command menu Telegram shows when the user types a slash.
Returns:
| Type | Description |
|---|---|
tuple[tuple[str, str], ...]
|
Each command as (name without the slash, description). |
Source code in src/trading_agent/channels/telegram_commands.py
answer
async
¶
Answers a command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chat
|
PairedChat
|
The paired chat that sent it. |
required |
text
|
str
|
The command and its argument. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The reply. |