Architecture
How OCSE Trader works under the hood
OCSE Trader operates as an autonomous state machine, continuously cycling through research, analysis, and execution phases.
The Agent Loop
The core logic resides in src/lib/agent-scheduler.ts. The agent polls its state every 5 seconds to determine the next action.
State Transitions
graph TD
Idle[Idle] --> Gen[Generating Report]
Gen --> Coold[Cooldown]
Coold --> Idle
Gen --> Error[Error State]
Error --> Idle
- Idle: The default state. When the agent is idle and no cooldown is active, it triggers the report generation process.
- Generating Report: The agent selects a stock, performs web searches, and calls the Claude 3.5 Sonnet API.
- Cooldown: After a successful cycle, the agent enters a 10-minute cooldown period to prevent over-trading and allow for market shifts.
Data Flow
- Input: A pool of predefined
xStocks(tokenized equities on Solana). - Enrichment: Real-time news snippets fetched via Brave Search.
- Intelligence: Anthropic's Claude 3.5 Sonnet processes the context and generates a JSON report.
- Action: If the rating is BUY or SELL, the agent automatically executes the trade on-chain.
- Output: Reports are saved to
data/reports.jsonand holdings are updated indata/holdings.json.
Technology Stack
- Framework: Next.js 14+ (Dashboard)
- Runtime: Node.js (Agent Loop)
- Language: TypeScript
- Blockchain: Solana (via @solana/web3.js)
- Trading API: SolanaTracker