| name | automation |
| description | Schedule cron jobs, manage webhooks, and automate recurring tasks |
| emoji | ⏰ |
Automation - Complete API Reference
Schedule recurring tasks with cron expressions, manage incoming webhooks, and automate workflows.
Chat Commands
Cron Jobs
/cron list # List all scheduled jobs
/cron add "0 9 * * *" "scan for arbs" # Add daily 9am job
/cron add "*/30 * * * *" "check prices" # Every 30 minutes
/cron remove <job-id> # Remove job
/cron enable <job-id> # Enable job
/cron disable <job-id> # Disable job
/cron run <job-id> # Run job now
/cron history <job-id> # View run history
Webhooks
/webhook list # List webhooks
/webhook add <name> <url> # Add webhook endpoint
/webhook remove <name> # Remove webhook
/webhook test <name> # Send test payload
/webhook logs <name> # View webhook logs
Heartbeat
/heartbeat config --interval 60 # Set heartbeat interval
/heartbeat status # View heartbeat status
/heartbeat enable # Enable heartbeats
/heartbeat disable # Disable heartbeats
TypeScript API Reference
Cron Scheduler
import { createCronScheduler } from 'clodds/automation';
const cron = createCronScheduler({
timezone: 'America/New_York',
autoStart: true,
});
const jobId = cron.addJob({
name: 'daily-arb-scan',
schedule: '0 9 * * *',
task: async () => {
console.log('Running arbitrage scan...');
},
enabled: true,
});
const jobs = cron.listJobs();
for (const job of jobs) {
console.log(`${job.id}: ${job.name} (${job.schedule})`);
console.log(` Next run: ${job.nextRun}`);
console.log(` Enabled: ${job.enabled}`);
}
cron.removeJob(jobId);
cron.enableJob(jobId);
cron.disableJob(jobId);
await cron.runJob(jobId);
const history = cron.getHistory(jobId, { limit: 10 });
for (const run of history) {
console.log(`${run.timestamp}: ${run.status} (${run.duration}ms)`);
}
Cron Expressions
| Expression | Description |
|---|
* * * * * | Every minute |
0 * * * * | Every hour |
0 9 * * * | Daily at 9am |
0 9 * * 1-5 | Weekdays at 9am |
*/15 * * * * | Every 15 minutes |
0 0 1 * * | First of month |
Webhook Manager
import { createWebhookManager } from 'clodds/automation';
const webhooks = createWebhookManager({
secret: process.env.WEBHOOK_SECRET,
validateSignatures: true,
});
webhooks.register({
name: 'trade-alerts',
handler: async (payload) => {
console.log('Received:', payload);
return { status: 'ok' };
},
validatePayload: (payload) => {
return payload.type && payload.data;
},
});
const url = webhooks.getUrl('trade-alerts');
console.log(`Webhook URL: ${url}`);
await webhooks.test('trade-alerts', {
type: 'test',
data: { message: 'Hello' },
});
const logs = webhooks.getLogs('trade-alerts', { limit: 10 });
for (const log of logs) {
console.log(`${log.timestamp}: ${log.status}`);
console.log(` Payload: ${JSON.stringify(log.payload)}`);
}
webhooks.remove('trade-alerts');
Heartbeat Service
import { createHeartbeatService } from 'clodds/automation';
const heartbeat = createHeartbeatService({
intervalMs: 60000,
endpoint: 'https://healthcheck.example.com/ping',
onFailure: (error) => {
console.error('Heartbeat failed:', error);
},
});
heartbeat.start();
const status = heartbeat.getStatus();
console.log(`Last ping: ${status.lastPing}`);
console.log(`Failures: ${status.failures}`);
console.log(`Uptime: ${status.uptime}%`);
heartbeat.stop();
Example Automations
Daily Arbitrage Scan
cron.addJob({
name: 'daily-arb',
schedule: '0 9,12,15,18 * * *',
task: async () => {
const opportunities = await opportunityFinder.scan();
if (opportunities.length > 0) {
await notify(`Found ${opportunities.length} arbitrage opportunities`);
}
},
});
Portfolio Snapshot
cron.addJob({
name: 'portfolio-snapshot',
schedule: '0 0 * * *',
task: async () => {
const portfolio = await trading.getPortfolio();
await database.saveSnapshot({
timestamp: Date.now(),
value: portfolio.totalValue,
positions: portfolio.positions.length,
});
},
});
Webhook for External Signals
webhooks.register({
name: 'external-signals',
handler: async (payload) => {
if (payload.signal === 'buy') {
await executor.marketBuy({
platform: 'polymarket',
marketId: payload.marketId,
side: 'YES',
size: 100,
});
}
return { executed: true };
},
});
Best Practices
- Use meaningful job names - Easy to identify later
- Set appropriate intervals - Don't spam APIs
- Handle failures gracefully - Add retry logic
- Monitor job history - Check for failures
- Validate webhook payloads - Prevent bad data
- Use heartbeats - Know when system is down