1-Minute Market Hours Trigger

Create a Node-RED flow that triggers every minute during market hours, excluding weekends and holidays

Description

Use Gemini to get a Node-RED inject node that runs every minute M-F during market hours, excluding market holidays.

Enter Gemini Prompt Here

Navigate to gemini.google.com and enter the following prompt:

write a node red json flow that triggers every minute during market hours and avoiding market holidays

Gemini Response

To achieve a flow that triggers every minute while adhering to the US Stock Market schedule (NYSE/NASDAQ), the most efficient way is to use a standard Inject node set to an interval, followed by a Function node that acts as a gatekeeper.

The function logic below specifically accounts for the 2026 market holidays and the standard trading hours (9:30 AM – 4:00 PM ET).

The Node-RED JSON Flow

You can import this directly into Node-RED: Click the Hamburger MenuImport → Paste the code below.

[{"id":"market_timer_inject","type":"inject","z":"637c376f.42c1b8","name":"Every 1 Min","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["market_hours_filter"]]},{"id":"market_hours_filter","type":"function","z":"637c376f.42c1b8","name":"Market Hours & Holiday Filter","func":"// Set your local timezone adjustment if your server isn't in ET\n// This script uses America/New_York for calculation\nconst now = new Date(new Date().toLocaleString(\"en-US\", {timeZone: \"America/New_York\"}));\n\nconst day = now.getDay(); // 0 = Sunday, 6 = Saturday\nconst hour = now.getHours();\nconst minute = now.getMinutes();\nconst dateString = now.toISOString().split('T')[0]; // YYYY-MM-DD\n\n// 1. Check for Weekends\nif (day === 0 || day === 6) return null;\n\n// 2. Check for 2026 Market Holidays\nconst holidays = [\n    \"2026-01-01\", // New Year's\n    \"2026-01-19\", // MLK Day\n    \"2026-02-16\", // Presidents' Day\n    \"2026-04-03\", // Good Friday\n    \"2026-05-25\", // Memorial Day\n    \"2026-06-19\", // Juneteenth\n    \"2026-07-03\", // Independence Day (Observed)\n    \"2026-09-07\", // Labor Day\n    \"2026-11-26\", // Thanksgiving\n    \"2026-12-25\"  // Christmas\n];\n\nif (holidays.includes(dateString)) {\n    node.status({fill:\"red\",shape:\"dot\",text:\"Market Closed (Holiday)\"});\n    return null;\n}\n\n// 3. Check for Early Close (1:00 PM ET)\nconst earlyCloseDays = [\"2026-11-27\", \"2026-12-24\"];\nlet closingHour = 16;\nif (earlyCloseDays.includes(dateString)) {\n    closingHour = 13;\n}\n\n// 4. Check for Trading Hours (9:30 AM - 4:00 PM / 1:00 PM)\nconst isAfterOpen = (hour > 9) || (hour === 9 && minute >= 30);\nconst isBeforeClose = (hour < closingHour);\n\nif (isAfterOpen && isBeforeClose) {\n    node.status({fill:\"green\",shape:\"dot\",text:\"Market Open\"});\n    return msg;\n} else {\n    node.status({fill:\"yellow\",shape:\"ring\",text:\"Market Closed (After Hours)\"});\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":120,"wires":[["debug_output"]]},{"id":"debug_output","type":"debug","z":"637c376f.42c1b8","name":"Trigger Event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":120,"wires":[]}]

How It Works

Component Description
Inject Node Triggers every 60 seconds.
Function Node This is where the "intelligence" sits.
Timezone Correction It forces the date object to America/New_York so that it works correctly even if your Node-RED server is hosted on a different continent.
Weekend Check Blocks Saturday (6) and Sunday (0).
2026 Holiday List Specifically filters out the 10 major days the NYSE is closed.
Early Closings It automatically adjusts the closing time to 1:00 PM ET for the day after Thanksgiving and Christmas Eve.
Market Window It only passes the message through if the time is between 9:30 AM and 4:00 PM (or 1:00 PM on early days).

Pro-Tip: If you want to avoid hardcoding holidays every year, you can install the node-red-contrib-stock-market-clock node or use an API like AbstractAPI or Calendarific to fetch holidays dynamically. However, for a lightweight setup, the hardcoded list above is extremely reliable for 2026.

This is what your flow will look like in your instance once it's added

  • This is the complete flow.
  • image1
  • This is the Gemini code added to the function node.
  • image2