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
  1. Idle: The default state. When the agent is idle and no cooldown is active, it triggers the report generation process.
  2. Generating Report: The agent selects a stock, performs web searches, and calls the Claude 3.5 Sonnet API.
  3. Cooldown: After a successful cycle, the agent enters a 10-minute cooldown period to prevent over-trading and allow for market shifts.

Data Flow

  1. Input: A pool of predefined xStocks (tokenized equities on Solana).
  2. Enrichment: Real-time news snippets fetched via Brave Search.
  3. Intelligence: Anthropic's Claude 3.5 Sonnet processes the context and generates a JSON report.
  4. Action: If the rating is BUY or SELL, the agent automatically executes the trade on-chain.
  5. Output: Reports are saved to data/reports.json and holdings are updated in data/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