Skip to content

trading_agent.doctor.checks.telegram_pairing_check

Checks that a phone is paired, so alerts can reach the user away from the computer.

Typical usage example:

result = TelegramPairingCheck(enabled, store).run()

TelegramPairingCheck

TelegramPairingCheck(enabled, store)

Bases: DoctorCheck

Counts the paired Telegram chats.

Creates the check.

Parameters:

Name Type Description Default
enabled bool

Whether [telegram] is enabled.

required
store PairingStore

The pairing file.

required
Source code in src/trading_agent/doctor/checks/telegram_pairing_check.py
def __init__(self, enabled: bool, store: pairing_store_module.PairingStore):
    """Creates the check.

    Args:
        enabled (bool): Whether [telegram] is enabled.
        store (pairing_store_module.PairingStore): The pairing file.
    """
    self._enabled = enabled
    self._store = store

run

run()

Counts paired chats.

Returns:

Type Description
CheckResult

OK when Telegram is on with a paired chat; a warning otherwise, since going live without it is allowed but alerts then reach only the web page.

Source code in src/trading_agent/doctor/checks/telegram_pairing_check.py
def run(self) -> doctor_check.CheckResult:
    """Counts paired chats.

    Returns:
        doctor_check.CheckResult: OK when Telegram is on with a paired chat; a warning otherwise, since going live without it is allowed but alerts then reach only the web page.
    """
    chats = self._store.paired_chats()
    if self._enabled and chats:
        names = ', '.join(chat.name or str(chat.chat_id) for chat in chats)
        return doctor_check.CheckResult(
            doctor_check.CheckStatus.OK, f'Alerts go to {names}.'
        )
    return doctor_check.CheckResult(
        doctor_check.CheckStatus.WARNING,
        'No phone is paired, so fills, halts and the kill switch are seen only on the web page. See docs/telegram_setup.md.',
    )