Skip to content

Strategy Protocol: minimal external OnBars TCP/JSON backtest (empty orders) #703

Closed

Description

@rustyeddy

Goal — first small vertical slice after rollback #709

Prove that Trader can run an external strategy using the same existing onBars / OnBars execution path as an in-process strategy. Do the minimum needed for a real historical backtest where the worker receives bars and always returns no orders.

Do this increment only. Stop and open a PR for review when it works. We will decide the next feature after building and testing this one.

Scope

  • Inspect and reuse Trader's current strategy callback, marketdata.Bar, backtest loop, and domain types. Use OnBars semantics: one callback per availability instant, with the completed bars available then; no look-ahead.
  • Implement a small loopback TCP adapter that lets an external worker participate in that callback. Use standard Go encoding/json and simple explicit framing (e.g., a 4-byte length prefix so TCP message boundaries are unambiguous).
  • The adapter sends the existing bars as JSON and receives an empty order list [] (or a minimal typed response containing it). Reuse existing Go structs wherever they work.
  • Provide one small example external worker that accepts bars and returns no orders.
  • Wire this adapter to the existing historical backtest engine; do not create a second run loop or execution pipeline.
  • Test the actual end-to-end path with a small canonical historical fixture: multiple successive OnBars deliveries, empty responses, normal completion. Include a basic disconnect/error test so a dead worker does not hang the backtest.

Acceptance criteria

  • A real Trader backtest can drive the external example worker over loopback TCP.
  • Each OnBars call delivers the same completed bar group and timing as the in-process path.
  • Worker returns no orders; the backtest finishes with no trades.
  • Repeated frames and clean shutdown work; disconnected worker returns an error promptly.
  • Small focused integration tests pass, and make check passes.
  • PR documents how to run the example, and shows the test command/output.

Explicitly out of scope

  • New strategy.Order or any second order/intent lifecycle.
  • Custom JSON parser/codec, golden fixtures, generalized protocol framework, registration schema or negotiation.
  • RunID transport protocol, registry/catalog, subprocess launch/management, multiple clients, or remote-network security.
  • Order submission/execution, account/risk changes, position/fill feedback, journaling, results REST API.
  • Generalized studies, scanners, indicators, or pre-emptive future-proofing.

Keep the implementation small and readable. If the existing interface needs modification, explain the minimum change in the PR. Do not silently expand scope. Preserve Trader's authority over risk, sizing and execution per ADR-093.

Context: #690 / milestone #27. PR #709 removed the prior overbuilt strategy protocol. This issue replaces its former broad implementation scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions