Strategy_Runtime.md 1.7 KB

Strategy Runtime

This is the canonical runtime / engine document for trader-mcp.

Overview

The system is split into:

  • strategy definition
  • persisted instance record
  • runtime execution
  • dashboard rendering

Instance identity

Immutable identity fields:

  • id
  • strategy_type
  • account_id
  • market_symbol
  • base_currency
  • counter_currency

These should stay stable and audit-friendly.

Mutable fields

  • mode (off, observe, active)
  • config
  • runtime state snapshots
  • stored Hermes policy metadata

State persistence

  • the engine owns snapshotting and restore
  • strategies only define state shape (STATE_SCHEMA)
  • persisted state is stored separately from config
  • state should be saved at lifecycle boundaries:
    • tick
    • pause
    • unload
    • reload/config change
    • clean shutdown

Mode semantics

  • off: not instantiated
  • observe: instantiated, ticks enabled, trading disabled
  • active: instantiated, ticks enabled, trading enabled
  • paused: runtime freeze, not persisted as a mode

Reconciliation

The engine reconciles DB records to runtime:

if record.mode != "off" and record.id not in running:
    load_instance(record)

if record.mode == "off" and record.id in running:
    unload_instance(record.id)

Reload semantics

Default behavior:

  • unload old runtime
  • restore state snapshot when available
  • load new runtime
  • reapply stored policy after instance creation

Selective state carryover is acceptable only through engine-managed persistence.

Dashboard responsibilities

The dashboard shows:

  • identity
  • config
  • mode
  • runtime status
  • rendered widgets
  • policy metadata when present

It does not own trading logic.