> ## Documentation Index
> Fetch the complete documentation index at: https://condor.hummingbot.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Global Routines

> Built-in routines available to all agents

Global routines in `~/condor/routines/` are available to all agents. Condor includes several built-in routines for common trading tasks.

## Built-in Routines

| Routine          | Type       | Description                                        |
| ---------------- | ---------- | -------------------------------------------------- |
| `hello_world`    | One-shot   | Simple example routine for testing                 |
| `market_scanner` | One-shot   | Scan markets for trading opportunities             |
| `bot_report`     | One-shot   | Generate performance reports for running bots      |
| `arb_check`      | One-shot   | Check for arbitrage opportunities across exchanges |
| `price_monitor`  | Continuous | Monitor price and alert on threshold changes       |

## Directory Structure

```
~/condor/routines/
├── __init__.py
├── base.py              # Routine discovery and base classes
├── hello_world.py       # Simple example routine
├── market_scanner.py    # Market scanning routine
├── bot_report.py        # Bot performance reports
├── arb_check.py         # Arbitrage checking
└── price_monitor.py     # Continuous price monitoring
```

## Hello World Example

The simplest routine to understand the structure:

```python theme={null}
# routines/hello_world.py
from pydantic import BaseModel, Field
from telegram.ext import ContextTypes


class Config(BaseModel):
    """Simple hello world example routine."""

    name: str = Field(default="World", description="Name to greet")
    repeat: int = Field(default=1, description="Number of times to repeat")
    uppercase: bool = Field(default=False, description="Use uppercase")


async def run(config: Config, context: ContextTypes.DEFAULT_TYPE) -> str:
    """Execute the routine."""
    greeting = f"Hello, {config.name}!"

    if config.uppercase:
        greeting = greeting.upper()

    return "\n".join([greeting] * config.repeat)
```

Run it from Telegram:

```
/routines → hello_world → Run

Output: Hello, World!
```

## Price Monitor (Continuous)

A continuous routine that monitors price and sends alerts:

```python theme={null}
# routines/price_monitor.py
from pydantic import BaseModel, Field
from telegram.ext import ContextTypes

# Mark as continuous routine
CONTINUOUS = True


class Config(BaseModel):
    """Live price monitor with configurable alerts."""

    connector: str = Field(default="binance", description="CEX connector name")
    trading_pair: str = Field(default="BTC-USDT", description="Trading pair to monitor")
    threshold_pct: float = Field(default=1.0, description="Alert threshold in %")
    interval_sec: int = Field(default=10, description="Check interval in seconds")


async def run(config: Config, context: ContextTypes.DEFAULT_TYPE) -> str:
    """Monitor price continuously until cancelled."""
    chat_id = context._chat_id
    client = await get_client(chat_id, context=context)

    initial_price = None
    last_price = None

    try:
        while True:
            prices = await client.market_data.get_prices(
                connector_name=config.connector,
                trading_pairs=config.trading_pair
            )
            current_price = prices["prices"].get(config.trading_pair)

            if initial_price is None:
                initial_price = current_price
                last_price = current_price

            # Check threshold and alert if triggered
            change = ((current_price - last_price) / last_price) * 100
            if abs(change) >= config.threshold_pct:
                await context.bot.send_message(
                    chat_id=chat_id,
                    text=f"{'📈' if change > 0 else '📉'} {config.trading_pair}: ${current_price:,.2f} ({change:+.2f}%)"
                )
                last_price = current_price

            await asyncio.sleep(config.interval_sec)

    except asyncio.CancelledError:
        return "Monitor stopped"
```

## Creating Custom Global Routines

Add your own routines to `~/condor/routines/`:

1. Create a Python file with `Config` class and `run` function
2. The routine is auto-discovered on next Condor start
3. Access via `/routines` in Telegram

<Note>
  Global routines are shared across all agents. For agent-specific routines, place them in the agent's `routines/` folder instead.
</Note>
