{
  "id": "nTt3ryZ7mIeGMnVv",
  "name": "AI Sonar-Pro Gold Market Tracker: Predict Prices from News and Economic Data",
  "tags": [],
  "nodes": [
    {
      "id": "b83c3eaf-eb99-4de6-bfb4-f572559f9960",
      "name": "Every 6 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        512,
        256
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 6
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c799a1dc-f452-4deb-b771-727c45e41a9e",
      "name": "Get Current Gold Price",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        -128
      ],
      "parameters": {
        "url": "https://api.metalpriceapi.com/v1/latest",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "queryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "api_key",
              "value": "={{ $credentials.apiKey }}"
            },
            {
              "name": "base",
              "value": "USD"
            },
            {
              "name": "currencies",
              "value": "XAU"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "722ee37a-298c-4c93-b5ed-55fe71bce92c",
      "name": "Fetch Financial News",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        64
      ],
      "parameters": {
        "url": "https://newsapi.org/v2/everything",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "queryAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "apiKey",
              "value": "={{ $credentials.apiKey }}"
            },
            {
              "name": "q",
              "value": "gold market OR precious metals OR inflation OR federal reserve"
            },
            {
              "name": "language",
              "value": "en"
            },
            {
              "name": "sortBy",
              "value": "publishedAt"
            },
            {
              "name": "pageSize",
              "value": "20"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "32d7a705-f003-4b3a-8487-88091161305e",
      "name": "Get Inflation Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        256
      ],
      "parameters": {
        "url": "https://api.stlouisfed.org/fred/series/observations",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "series_id",
              "value": "CPIAUCSL"
            },
            {
              "name": "api_key",
              "value": "={{ $credentials.apiKey }}"
            },
            {
              "name": "file_type",
              "value": "json"
            },
            {
              "name": "limit",
              "value": "12"
            },
            {
              "name": "sort_order",
              "value": "desc"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "9bc19922-62ed-43c9-8a2e-260ad222e0a4",
      "name": "Get Interest Rate Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        448
      ],
      "parameters": {
        "url": "https://api.stlouisfed.org/fred/series/observations",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "series_id",
              "value": "FEDFUNDS"
            },
            {
              "name": "api_key",
              "value": "={{ $credentials.apiKey }}"
            },
            {
              "name": "file_type",
              "value": "json"
            },
            {
              "name": "limit",
              "value": "12"
            },
            {
              "name": "sort_order",
              "value": "desc"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "24c0614a-458f-4c97-a699-658129e12af4",
      "name": "Get Employment Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        736,
        640
      ],
      "parameters": {
        "url": "https://api.stlouisfed.org/fred/series/observations",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "series_id",
              "value": "UNRATE"
            },
            {
              "name": "api_key",
              "value": "={{ $credentials.apiKey }}"
            },
            {
              "name": "file_type",
              "value": "json"
            },
            {
              "name": "limit",
              "value": "12"
            },
            {
              "name": "sort_order",
              "value": "desc"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8f69c836-908d-474c-b1af-e4a40dfb6133",
      "name": "Format Gold Price",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        -128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "gold_price",
              "name": "gold_price_usd",
              "type": "number",
              "value": "={{ $json.rates.XAU }}"
            },
            {
              "id": "timestamp",
              "name": "price_timestamp",
              "type": "string",
              "value": "={{ $json.timestamp }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e66ccf59-958b-48b2-8b9b-c810c43ac8bc",
      "name": "Format News Data",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "news_articles",
              "name": "news_summary",
              "type": "array",
              "value": "={{ $json.articles.map(a => ({ title: a.title, source: a.source.name, publishedAt: a.publishedAt, description: a.description, url: a.url })).slice(0, 10) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "698df7ed-3e8b-4fd0-b7c6-ca117c1e6fb7",
      "name": "Format Inflation",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        256
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "inflation_data",
              "name": "inflation_trend",
              "type": "array",
              "value": "={{ $json.observations.slice(0, 6).map(o => ({ date: o.date, value: parseFloat(o.value) })) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b2946653-aef5-4178-bada-1a45af0a4d51",
      "name": "Format Interest Rates",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        448
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "interest_rate",
              "name": "fed_funds_rate",
              "type": "array",
              "value": "={{ $json.observations.slice(0, 6).map(o => ({ date: o.date, value: parseFloat(o.value) })) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "54665285-1ff7-47c8-9804-241ae5a7cc81",
      "name": "Format Employment",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        640
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "unemployment",
              "name": "unemployment_rate",
              "type": "array",
              "value": "={{ $json.observations.slice(0, 6).map(o => ({ date: o.date, value: parseFloat(o.value) })) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e9acb270-2801-4b29-a837-4f0d20daf3a5",
      "name": "Merge All Data",
      "type": "n8n-nodes-base.merge",
      "position": [
        1184,
        -32
      ],
      "parameters": {
        "mode": "combine",
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "94f957c5-f758-430f-b126-64c2df6eab9c",
      "name": "Prepare AI Input",
      "type": "n8n-nodes-base.set",
      "position": [
        1344,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "combined_data",
              "name": "analysis_input",
              "type": "string",
              "value": "=Gold Price Data:\nCurrent Price (USD per oz): {{ $('Format Gold Price').item.json.gold_price_usd }}\nTimestamp: {{ $('Format Gold Price').item.json.price_timestamp }}\n\nRecent Financial News (Top 10):\n{{ $('Format News Data').item.json.news_summary.map((n, i) => `${i+1}. ${n.title} (${n.source}) - ${n.publishedAt}\\n   ${n.description}`).join('\\n\\n') }}\n\nMacroeconomic Indicators:\n\nInflation (CPI - Last 6 months):\n{{ $('Format Inflation').item.json.inflation_trend.map(d => `${d.date}: ${d.value}`).join('\\n') }}\n\nFederal Funds Rate (Last 6 months):\n{{ $('Format Interest Rates').item.json.fed_funds_rate.map(d => `${d.date}: ${d.value}%`).join('\\n') }}\n\nUnemployment Rate (Last 6 months):\n{{ $('Format Employment').item.json.unemployment_rate.map(d => `${d.date}: ${d.value}%`).join('\\n') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "65481686-817a-4113-8f5c-907eafa330ee",
      "name": "AI Agent - Gold Market Analysis",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1504,
        -32
      ],
      "parameters": {
        "text": "=You are an expert financial analyst specializing in precious metals markets and macroeconomic trends. Analyze the provided data comprehensively.\n\n{{ $json.analysis_input }}\n\nBased on this data, provide a detailed gold market analysis with the following structure:\n\n**EXECUTIVE SUMMARY** (2-3 sentences)\nProvide a concise overview of the current gold market state and outlook.\n\n**KEY DRIVERS** (List 5-7 main factors)\nIdentify and explain the primary factors currently influencing gold prices:\n- Factor name: Brief explanation of its impact (bullish/bearish/neutral)\n\n**SHORT-TERM PREDICTION (1-7 days)**\n- Price Direction: [Up/Down/Sideways]\n- Expected Range: $X,XXX - $X,XXX per oz\n- Confidence Score: X/10\n- Reasoning: 2-3 sentence justification\n\n**MEDIUM-TERM PREDICTION (2-4 weeks)**\n- Price Direction: [Up/Down/Sideways]\n- Expected Range: $X,XXX - $X,XXX per oz\n- Confidence Score: X/10\n- Reasoning: 2-3 sentence justification\n\n**WATCHLIST** (Upcoming Events)\nList 5-8 specific upcoming events or data releases that could significantly impact gold prices:\n- Event name (approximate date): Potential impact explanation\n\nBe specific, data-driven, and consider correlations between indicators. Use current date context for timing predictions.",
        "options": {
          "systemMessage": "You are a senior financial analyst with 15+ years of experience in commodity markets, specializing in gold and precious metals. You provide clear, actionable insights based on technical analysis, fundamental data, and macroeconomic indicators."
        }
      },
      "typeVersion": 1.7
    },
    {
      "id": "03892373-2f22-4e07-ae13-c0e46a50355e",
      "name": "Format Final Report",
      "type": "n8n-nodes-base.set",
      "position": [
        1808,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "analysis_report",
              "name": "final_report",
              "type": "string",
              "value": "={{ $json.output }}"
            },
            {
              "id": "generated_at",
              "name": "report_timestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "gold_price",
              "name": "current_gold_price",
              "type": "number",
              "value": "={{ $('Format Gold Price').item.json.gold_price_usd }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "04ff9645-e526-46be-a245-f4a43726bac3",
      "name": "Publish to WordPress",
      "type": "n8n-nodes-base.wordpress",
      "position": [
        1984,
        -32
      ],
      "parameters": {
        "title": "=Gold Market Analysis - {{ $now.format('MMM dd, yyyy HH:mm') }}",
        "additionalFields": {
          "status": "publish",
          "authorId": 1
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8d5b7ebd-f6d4-4026-b6e9-20b5ebf91e29",
      "name": "Send Slack Summary",
      "type": "n8n-nodes-base.slack",
      "position": [
        2208,
        -128
      ],
      "parameters": {
        "text": "=:bar_chart: *Gold Market Analysis Report Published*\n\n*Current Price:* ${{ $('Format Final Report').item.json.current_gold_price.toFixed(2) }} per oz\n*Generated:* {{ $now.format('MMM dd, yyyy HH:mm') }}\n\n{{ $('AI Agent - Gold Market Analysis').item.json.output.split('**EXECUTIVE SUMMARY**')[1].split('**KEY DRIVERS**')[0].trim() }}\n\n:link: Read full analysis: {{ $('Publish to WordPress').item.json.link }}",
        "otherOptions": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "e0243aba-6269-4ecb-b95b-fe27426a860c",
      "name": "Send Email Summary",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        2208,
        64
      ],
      "parameters": {
        "options": {},
        "subject": "=Gold Market Forecast - {{ $now.format('MMM dd, yyyy') }}",
        "toEmail": "user@example.com",
        "fromEmail": "user@example.com"
      },
      "typeVersion": 2.1
    },
    {
      "id": "986680b8-bdfc-4c03-af8f-24fb2c27a5a6",
      "name": "OpenRouter Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        1504,
        128
      ],
      "parameters": {
        "model": "perplexity/sonar-pro",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "49db7300-6578-4548-b743-53634988975f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        256
      ],
      "parameters": {
        "width": 912,
        "height": 208,
        "content": "## **Introduction**\nAutomates gold market tracking using AI forecasting by collecting live prices, financial news, and macro indicators (inflation, interest rates, employment) to produce real-time insights and trend predictions for analysts and investors.\n\n## **How It Works**\nEvery 6 hours, the system fetches market data and news \u2192 runs AI sentiment and trend analysis \u2192 generates a concise forecast report \u2192 publishes it to WordPress \u2192 and alerts users via Slack or email.\n\n\n\n\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9b10ec61-d430-4cf9-adf3-470b232f7bd7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2096,
        256
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 464,
        "content": "## Prerequisites\nn8n v1.0+, API keys, OAuth credentials, and internet access.\n\n## Use Cases\nInvestment forecasting, financial newsletter automation, or market monitoring dashboards.\n\n## Customization\nAdd cryptocurrency or stock tracking, modify AI prompts, or route summaries to Telegram, Notion, or Google Sheets.\n\n## Benefits\nSaves analyst time, ensures consistent insights, enhances accuracy, and delivers timely, AI-driven financial intelligence."
      },
      "typeVersion": 1
    },
    {
      "id": "066a76a3-86b6-4a9d-8f2d-b448296e3883",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        480
      ],
      "parameters": {
        "color": 3,
        "width": 912,
        "height": 416,
        "content": "## **Workflow Template**\n**Trigger \u2192 Fetch \u2192 Format \u2192 Merge \u2192 AI Analyze \u2192 Report \u2192 Publish \u2192 Notify**\n\n## **Workflow Steps**\n1. **Schedule:** Executes automatically every **6 hours** using a Cron trigger.\n2. **Fetch:** Retrieves **live gold prices (MetalPriceAPI)**, **financial headlines (NewsAPI)**, and **macroeconomic indicators (FRED)**.\n3. **Format & Merge:** Cleans, normalizes, and merges all data into a single structured dataset for AI analysis.\n4. **AI Analyze (OpenAI):** Performs **sentiment, trend, and correlation analysis** to forecast short-term gold price movements.\n5. **Report Generation:** Creates a concise **summary report** with forecasts, insights, and confidence metrics.\n6. **Publish & Notify:** Automatically **posts to WordPress** and sends **alerts via Slack and Email** to keep analysts updated.\n\n## **Setup**\n* Add API keys: **MetalPrice, NewsAPI, FRED, OpenAI, WordPress, Slack, Gmail**.\n* Configure **scheduling interval**, **API endpoints**, and **authentication** in **n8n**.\n* Predefine **WordPress post format** and **Slack message templates** for smooth automation.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "258c779e-78ef-493a-87ad-17e2938c37b8",
  "connections": {
    "Every 6 Hours": {
      "main": [
        [
          {
            "node": "Get Current Gold Price",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Financial News",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Inflation Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Interest Rate Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Employment Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Data": {
      "main": [
        [
          {
            "node": "Prepare AI Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format News Data": {
      "main": [
        [
          {
            "node": "Merge All Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Prepare AI Input": {
      "main": [
        [
          {
            "node": "AI Agent - Gold Market Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Gold Price": {
      "main": [
        [
          {
            "node": "Merge All Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Inflation Data": {
      "main": [
        [
          {
            "node": "Format Inflation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Final Report": {
      "main": [
        [
          {
            "node": "Publish to WordPress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Employment Data": {
      "main": [
        [
          {
            "node": "Format Employment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Financial News": {
      "main": [
        [
          {
            "node": "Format News Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Publish to WordPress": {
      "main": [
        [
          {
            "node": "Send Slack Summary",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Email Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Gold Market Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Current Gold Price": {
      "main": [
        [
          {
            "node": "Format Gold Price",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Interest Rate Data": {
      "main": [
        [
          {
            "node": "Format Interest Rates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Gold Market Analysis": {
      "main": [
        [
          {
            "node": "Format Final Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}