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

# Cloud scheduler

# Cloud Scheduler Integration - Quick Reference

## What Changed?

Cortex Trader bot is now **automatically scheduled** to run every 5 minutes via GCP Cloud Scheduler instead of requiring manual startup.

## Key Files

| File                                              | Change      | Purpose                                   |
| ------------------------------------------------- | ----------- | ----------------------------------------- |
| `apphosting.yaml`                                 | ➕ 8 lines   | Added `cortex-trader-execution` job       |
| `src/app/api/cron/execute-cortex-trades/route.ts` | ➕ NEW       | Cloud Function endpoint to run Python bot |
| `src/app/home/automate/page.tsx`                  | ➕ 120 lines | Dashboard status display for scheduler    |
| `README.md`                                       | ➕ 3 lines   | Documentation links                       |

## Deployment

```bash theme={null}
npm run build
firebase deploy
```

## Verification

1. **Cloud Scheduler** (GCP Console)
   * Should show: `cortex-trader-execution` with status **ACTIVE**

2. **Trader Dashboard** (`/home/automate`)
   * Should display **Cloud Scheduler Status** card with execution details

3. **First Execution**
   * Happens within 5 minutes of deployment
   * Check status card for results

## How It Works

```
Every 5 minutes →
  Cloud Scheduler calls →
    /api/cron/execute-cortex-trades →
      Spawns cortex_trader.py →
        Executes Genesis trades →
          Logs to Firestore →
            Dashboard displays status
```

## Monitoring

**Dashboard** → `/home/automate` → **Cloud Scheduler Status** card shows:

* ✅ Status (completed/failed)
* ✅ Trades executed
* ✅ Last execution time
* ✅ Next execution time
* ❌ Errors (if any)

## Troubleshooting

| Problem                   | Solution                                         |
| ------------------------- | ------------------------------------------------ |
| Job shows INACTIVE        | Check `CRON_SECRET` env var in App Hosting       |
| Status stuck on "pending" | Wait 5+ min for first execution                  |
| cortex\_trader.py fails   | Check `cortex_trader.log` for Python errors      |
| Dashboard shows error     | Review Firestore: `_system/cortex_execution_log` |

## Environment Variables Needed

```bash theme={null}
CRON_SECRET=<your-secret-value>
# Set in Firebase App Hosting environment
```

## Documentation

* **Full Setup**: [CLOUD\_SCHEDULER\_SETUP.md](CLOUD_SCHEDULER_SETUP.md)
* **Deployment**: [DEPLOYMENT\_CHECKLIST.md](DEPLOYMENT_CHECKLIST.md)
* **Summary**: [CLOUD\_SCHEDULER\_SUMMARY.md](CLOUD_SCHEDULER_SUMMARY.md)

## Build Status

✅ **Compiles successfully** (13.1s)

## Commits

* `46e58f2` - Integrate Cortex Trader with Cloud Scheduler
* `baf2e10` - Add Cloud Scheduler documentation
* `77887c7` - Add deployment checklist
* `c084521` - Add integration summary

***

**Ready to deploy!** 🚀
