{
  "name": "Send gold and WTI price alerts to Telegram with SiftingIO",
  "nodes": [
    {
      "parameters": {
        "content": "## Gold & WTI price alerts \u2014 SiftingIO \u2192 Telegram\n\nThis workflow checks **Gold (XAUUSD)** and **WTI crude oil (WTIUSD)** every 15 minutes and sends a Telegram message when a threshold is crossed.\n\n### Setup (about 3 minutes)\n1. Install the community node: `n8n-nodes-siftingio`\n2. Create a free SiftingIO API key:\n   https://sifting.io/register?utm_source=n8n&utm_medium=workflow_template&utm_campaign=commodity_price_alerts\n3. Open both SiftingIO nodes and select your **SiftingIO API** credential\n4. Open **Check alert thresholds**:\n   - keep `TEST_MODE = true` for the first manual test\n   - set your own `above` / `below` levels\n   - then change `TEST_MODE = false`\n5. Open **Send Telegram alert**, select your Telegram credential, and enter your chat ID\n6. Click **Execute workflow** once, then activate it\n\nThe workflow imports inactive and contains no API keys or secrets.",
        "height": 620,
        "width": 470
      },
      "id": "fb3332a1-bc87-4f77-958a-7d4d8354c8b8",
      "name": "Setup guide",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -800,
        -160
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "id": "4598b2c9-4691-479b-90f1-2e56bc02e19d",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -260,
        120
      ]
    },
    {
      "parameters": {
        "resource": "live",
        "operation": "getTrade",
        "venue": "commodities",
        "symbol": "XAUUSD"
      },
      "id": "c21a7091-8a9f-4314-816c-63f9f4a22f8a",
      "name": "Get gold price",
      "type": "n8n-nodes-siftingio.siftingIo",
      "typeVersion": 1,
      "position": [
        20,
        0
      ]
    },
    {
      "parameters": {
        "resource": "live",
        "operation": "getTrade",
        "venue": "commodities",
        "symbol": "WTIUSD"
      },
      "id": "3abf0175-786d-4400-9459-f1a72a0a2a83",
      "name": "Get WTI price",
      "type": "n8n-nodes-siftingio.siftingIo",
      "typeVersion": 1,
      "position": [
        20,
        240
      ]
    },
    {
      "parameters": {},
      "id": "4844f36d-7597-4dae-942a-189331e1521a",
      "name": "Wait for both prices",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        300,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "// First run: keep TEST_MODE = true so Telegram receives a test message.\n// After the test succeeds, set it to false and edit the thresholds below.\nconst TEST_MODE = true;\n\nconst thresholds = {\n  XAUUSD: { label: 'Gold', above: 4000, below: 2000 },\n  WTIUSD: { label: 'WTI crude oil', above: 120, below: 40 },\n};\n\nfunction readPrice(payload) {\n  const candidates = [\n    payload.p, payload.price, payload.last, payload.last_price,\n    payload.c, payload.close, payload.mid, payload.m\n  ];\n  for (const value of candidates) {\n    const n = Number(value);\n    if (Number.isFinite(n)) return n;\n  }\n\n  const bid = Number(payload.b ?? payload.bid);\n  const ask = Number(payload.a ?? payload.ask);\n  if (Number.isFinite(bid) && Number.isFinite(ask)) return (bid + ask) / 2;\n\n  throw new Error(`No numeric price found in response: ${JSON.stringify(payload)}`);\n}\n\nconst rows = [\n  { symbol: 'XAUUSD', payload: $('Get gold price').first().json },\n  { symbol: 'WTIUSD', payload: $('Get WTI price').first().json },\n];\n\nconst alerts = [];\nfor (const row of rows) {\n  const price = readPrice(row.payload);\n  const cfg = thresholds[row.symbol];\n\n  if (TEST_MODE) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `SiftingIO test alert\\n${cfg.label} (${row.symbol}): ${price}\\nUTC: ${new Date().toISOString()}`\n    });\n    continue;\n  }\n\n  if (price >= cfg.above) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `${cfg.label} alert\\n${row.symbol} is ${price}, at or above ${cfg.above}.\\nUTC: ${new Date().toISOString()}`\n    });\n  } else if (price <= cfg.below) {\n    alerts.push({\n      symbol: row.symbol,\n      price,\n      message: `${cfg.label} alert\\n${row.symbol} is ${price}, at or below ${cfg.below}.\\nUTC: ${new Date().toISOString()}`\n    });\n  }\n}\n\nreturn alerts.map((alert) => ({ json: alert }));"
      },
      "id": "253afbbe-6cf6-4443-8ab3-808dedd2a394",
      "name": "Check alert thresholds",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        120
      ]
    },
    {
      "parameters": {
        "operation": "sendMessage",
        "chatId": "REPLACE_WITH_YOUR_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "7ec73000-933e-46ae-b591-36de20551032",
      "name": "Send Telegram alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        760,
        120
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 1000
    }
  ],
  "connections": {
    "Every 15 minutes": {
      "main": [
        [
          {
            "node": "Get gold price",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get WTI price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get gold price": {
      "main": [
        [
          {
            "node": "Wait for both prices",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get WTI price": {
      "main": [
        [
          {
            "node": "Wait for both prices",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Wait for both prices": {
      "main": [
        [
          {
            "node": "Check alert thresholds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check alert thresholds": {
      "main": [
        [
          {
            "node": "Send Telegram alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}