Skip to content

Price Alert Endpoints

POST /price-alert

Create a price alert with webhook notification.

Cost: $0.04 USDC

Request Body

json
{
  "symbol": "ETH",
  "condition": "below",
  "target_price": 2400,
  "webhook_url": "https://your-bot.com/webhook",
  "agent_wallet": "0x...",
  "expires_in_hours": 24
}

Parameters

FieldTypeRequiredDescription
symbolstringYesToken symbol (uppercase, max 20 chars)
conditionstringYesabove, below, crosses_above, or crosses_below
target_pricefloatYesPrice threshold (must be positive)
webhook_urlstringYesCallback URL (must be HTTPS)
agent_walletstringNoEVM (0x...) or Solana wallet for tracking
expires_in_hoursintNoAlert lifetime in hours, 1–168 (default: 24, max: 168 = 7 days)

Conditions

ValueDescription
aboveTrigger when price rises above target
belowTrigger when price falls below target
crosses_aboveTrigger once when price crosses upward through target
crosses_belowTrigger once when price crosses downward through target

Request Example

javascript
const res = await fetchWithPayment("https://api.foursec.xyz/price-alert", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    symbol: "ETH",
    condition: "below",
    target_price: 2400,
    webhook_url: "https://your-bot.com/webhook",
    expires_in_hours: 24
  })
});
const alert = await res.json();

Response

json
{
  "alert_id": "alert_eth_1720447800_001",
  "symbol": "ETH",
  "condition": "below",
  "target_price": 2400,
  "status": "active",
  "created_at": "2026-07-08T15:30:00Z",
  "expires_at": "2026-07-09T15:30:00Z",
  "expires_in_hours": 24,
  "webhook_url": "https://your-bot.com/webhook",
  "trigger_count": 0,
  "delivery_attempts": 0,
  "message": "Alert created successfully"
}

GET /price-alert/:id

Check the status of an existing alert.

Cost: FREE

Request Example

bash
curl https://api.foursec.xyz/price-alert/alert_eth_1720447800_001

Response

json
{
  "alert_id": "alert_eth_1720447800_001",
  "symbol": "ETH",
  "condition": "below",
  "target_price": 2400,
  "status": "active",
  "created_at": "2026-07-08T15:30:00Z",
  "expires_at": "2026-07-09T15:30:00Z",
  "trigger_count": 0
}

DELETE /price-alert/:id

Cancel an active alert.

Cost: FREE

Request Example

bash
curl -X DELETE https://api.foursec.xyz/price-alert/alert_eth_1720447800_001

Response

json
{
  "alert_id": "alert_eth_1720447800_001",
  "status": "cancelled",
  "message": "Alert cancelled successfully"
}

GET /price-alerts

List all active price alerts.

Cost: FREE

Query Parameters

ParamTypeDescription
walletstringFilter by agent_wallet address
symbolstringFilter by token symbol

Request Example

bash
curl "https://api.foursec.xyz/price-alerts?symbol=ETH"

POST /price-alert/:id/extend

Extend the duration of an active alert.

Cost: $0.02 USDC

Request Body

json
{
  "add_hours": 24
}
FieldTypeDescription
add_hoursintHours to add (default: 24, max: 168)

Webhook Payload

When the condition is met, a POST request is sent to your webhook_url:

json
{
  "event": "price_alert",
  "alert_id": "alert_eth_1720447800_001",
  "symbol": "ETH",
  "severity": "medium",
  "data": {
    "triggered": true,
    "current_price": 2399.50,
    "target_price": 2400,
    "condition": "below",
    "condition_met": "ETH below $2400"
  },
  "timestamp": "2026-07-09T03:15:00Z"
}

Webhook Handler Example (Node.js)

javascript
import express from 'express';
import crypto from 'crypto';

const app = express();
app.use(express.raw({ type: 'application/json' }));

app.post('/webhook/price-alert', (req, res) => {
  const signature = req.headers['x-4sec-signature'];
  const expected = 'sha256=' + crypto
    .createHmac('sha256', process.env.WEBHOOK_SECRET)
    .update(req.body)
    .digest('hex');

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return res.status(401).send('Invalid signature');
  }

  const data = JSON.parse(req.body);
  console.log(`ALERT: ${data.symbol} — ${data.data.condition_met}`);
  console.log(`Current price: $${data.data.current_price}`);
  // Execute your trading logic here
  res.send('OK');
});

Security

Webhook payloads include an HMAC signature in the X-4SEC-Signature header (format: sha256=<hex>):

python
import hmac, hashlib

def verify_webhook(payload_bytes, signature_header, secret):
    expected = 'sha256=' + hmac.new(
        secret.encode(),
        payload_bytes,
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, signature_header)

Alert Lifecycle

  1. active — Alert is registered and being checked every 10 seconds
  2. triggered — Condition met, webhook called (1-minute cooldown before re-trigger)
  3. expired — Duration elapsed without trigger
  4. cancelled — Manually cancelled via DELETE endpoint

Error Responses

ErrorCauseFix
invalid_webhook_urlURL not HTTPSUse HTTPS webhook URL
invalid_conditionNot one of the 4 valid conditionsUse above, below, crosses_above, or crosses_below
expires_in_hours_too_longOver 168 hoursMax 168 hours (7 days)
symbol_not_foundUnsupported symbolCheck supported symbols list
alert_not_foundInvalid or expired alert IDVerify alert ID exists

TIP

Alerts check prices every 10 seconds with a 1-minute cooldown after each trigger. Use expires_in_hours to set duration (max 7 days). Extend anytime with POST /price-alert/:id/extend.

Built with x402 protocol on Base