Critical path

Exchange State Management Critical Path

Compact route for systems that track private exchange state, app-owned orders, pending confirmations, and DCA/TP/SL or similar managed slots.

Use exchange pages for exact SDK clients, request fields, private topics, product modes, and rejection codes.

Core agent manifest

/.well-known/agent-manifests/position-manager-core/latest.json

Core runtime kit

/.well-known/runtime-kits/position-manager-core/v1/index.json

Core runtime TypeScript contract

/.well-known/runtime-kits/position-manager-core/v1/types.ts

Core integration kit

/.well-known/integration-kits/position-manager-core/latest.json

Core conformance pack

/.well-known/conformance/position-manager-core/latest.json

Position Manager for Binance

/ai/position-manager/binance

Position Manager for Bybit

/ai/position-manager/bybit

1. Build path

Keep the first pass narrow and prove runtime behavior before optional strategy knobs.

  • Read the critical workflow.
  • Use the task manifest for generation.
  • Implement the runtime kit module contracts.
  • Generate tests from the required conformance pack.
  • Implement the smallest manager that passes the required behavior checks before adding features.
  • Use broad SDK docs only to verify method names and request shapes.

2. Architecture

Use order_position_state_machine with the simple ws_symbol_side_phase_gated lane for generated managers.

  • Private events ingest into accountstate immediately.
  • Dirty scopes are precise where possible and bounded where not.
  • A quiet-window scheduler runs one workflow pass after event bursts settle.
  • One workflow owner drains one symbol-side scope at a time.
  • Each pass submits at most one phase: recovery, cleanup, protective, DCA, noop, or blocked.
  • REST submission acceptance is pending coordination state, not trusted accountstate.

3. Not confirmations

These inputs can update local state, clear latches, or schedule work, but they do not prove that a protective slot is safely active.

  • REST place/amend/cancel acceptance: record or match pending confirmation. Transport or request success does not prove active open-order state.
  • Terminal order row: clear or terminalize the matching latch. Cancelled, rejected, filled, deactivated, triggered, or equivalent rows are not resting slot evidence.
  • Execution or fill row: update fills and dirty the affected scope. Fill evidence can change position/order state but does not confirm active open-order existence.
  • Private stream open or subscription event: update transport readiness only. Accountstate readiness still needs hydration, replay, and private account-state evidence.
  • Active DCA order for the current step: hold dependent DCA work. A resting DCA order is not permission to place the next DCA step.

4. Required checks

Start with this compact behavior set. Run the complete conformance pack before live-capable order paths.

  • startup_hydrated_position_queues_work_before_service_ready: REST-hydrated open positions queue work before service readiness.
  • private_event_marks_dirty_and_schedules_reconcile: Private event ingestion leads to scoped workflow scheduling.
  • private_event_burst_debounces_until_quiet_window: Accountstate ingestion is immediate while workflow execution waits for the burst to quiet.
  • opaque_custom_id_registry_routes_exchange_echoes: Exchange-visible custom IDs are lookup keys into one order-context store.
  • pending_confirmation_does_not_unlock_dependent_phase: Accepted mutation responses are provisional and cannot unlock dependent phases.
  • private_confirmation_before_rest_accept_is_consumed: A private confirmation can arrive before the REST promise resolves.
  • terminal_event_during_cancel_or_amend_is_benign_race: Terminal private evidence can make later missing-target cancel/amend errors benign.
  • reconnect_queues_known_scopes_for_recovery_even_when_quiet: Reconnect schedules recovery even without a later private event.
  • slot_filter_failures_are_blocked_not_silent_or_retried: Exchange filters and local sizing gates produce explicit blocks.
  • flat_position_cleans_app_owned_orders: A flat position cleans remaining managed orders.

5. Exchange overlay

Core lifecycle behavior stays reusable. Exchange pages add venue semantics.

  • Binance overlay owns newClientOrderId, clientAlgoId, SDK ID utilities, USD-M regular TP, Algo SL, and Binance rejection codes.
  • Bybit overlay owns orderLinkId, positionIdx, subscribeV5 private topics, retCode behavior, durable context default, and close-all linear SL request shape.
  • Shared behavior belongs in the core manifest, runtime kit, integration kit, and conformance pack.

6. Fallback sources

Use broad SDK docs and examples only after task-specific artifacts establish the runtime contract.

  • Use the manifest as the first executable artifact.
  • Use this critical path for compact workflow review.
  • Use SDK docs, endpoint maps, repository examples, SDK catalog, and llms-full only for unresolved method or request-shape details.

Runtime sequence

Module names can vary. These transitions should remain visible and testable.

  1. Load config and execution boundary.
  2. Hydrate filters, positions, open orders, fills/executions, wallet or margin state, and account mode.
  3. Load or initialize the order-context store.
  4. Subscribe to private order, execution, position, and wallet/account streams.
  5. Replay buffered private events into accountstate.
  6. Mark dirty scopes and schedule quiet-window reconcile.
  7. Select one phase and submit only that phase.
  8. Record pending confirmations for accepted mutations.
  9. Wait for private stream confirmation or scoped recovery before dependent phases.
Fixture casesReference

Use these behavior checks in local replay or fixture tests before live order paths are trusted.

CasePurposeExpected result
startup_hydrated_position_queues_work_before_service_readyREST-hydrated open positions queue work before service readiness.Hydration marks affected scopes dirty and a reconciliation pass runs before service_ready.
private_event_marks_dirty_and_schedules_reconcilePrivate event ingestion leads to scoped workflow scheduling.The event applies to accountstate, marks the precise or bounded scope dirty, and schedules reconciliation.
private_event_burst_debounces_until_quiet_windowAccountstate ingestion is immediate while workflow execution waits for the burst to quiet.Multiple related events produce one reconcile after quietWindowMs, bounded by maxDelayMs.
opaque_custom_id_registry_routes_exchange_echoesExchange-visible custom IDs are lookup keys into one order-context store.Private order echoes map to slot, scope, role, and pending action through the registry without parsing the ID string.
pending_confirmation_does_not_unlock_dependent_phaseAccepted mutation responses are provisional and cannot unlock dependent phases.Dependent phases wait for trusted private stream state or scoped recovery hydration.

Runtime invariants

  • Start implementation from the manifest and runtime kit.
  • Use the critical path for workflow review.
  • Keep core lifecycle behavior consistent across exchange overlays.
  • Use the conformance pack for the full behavior contract.
Prompt artifactReference

Use the linked prompt artifact when a coding agent needs the full handoff text.

/.well-known/prompts/position-manager-critical-path/latest.md

Open prompt artifact