Automating a 24/7 Stock Trading Agent with GPT-6 Astra
Nate Herk | AI Automationgo watch the original →
the gist
The author configures a local AI agent to execute a seven-day trading strategy on Alpaca by chaining scheduled tasks that share a persistent chat thread and progress log for stateful continuity.
Agent Continuity and State Management
The author maintains agent state across stateless wakeups by using a shared progress log and a unified chat thread. Each scheduled task is instructed to read the previous handoff message, assess the current portfolio state via the Alpaca API, perform its assigned duty, and append a summary to the progress log. This ensures that subsequent agents possess the necessary context to continue the trading strategy without repeating actions or losing track of open positions.
Local Routine Configuration
The trading agent runs locally within the Codex environment to retain access to specific model settings and project files. The author defines six daily scheduled tasks, ranging from 7:45 a.m. to 2:45 p.m. Central Time, which handle news analysis, trade identification, position management, and end-of-day reporting. These tasks are configured to execute within a single project thread named "challenge thread" to prevent context bloat and ensure all actions are logged in one location.
Integration and Monitoring
To execute trades, the author connects the agent to an Alpaca brokerage account using API keys stored in a local .env file. The author utilizes a paid Alpaca subscription for real-time market data to improve decision-making accuracy. Notifications are routed to ClickUp via automated messages, allowing the author to monitor trade status and agent thoughts remotely. The author also uses the Codex remote feature to sync the desktop environment with a mobile device, enabling real-time oversight of the agent's activity from a phone.