Module Algostream_runtime.Snapshot

What the runtime publishes for observers.

Every value here is immutable and self-contained, so it can be read from any Domain via Atomic.get and serialized without touching the live strategy state. The runtime Domain is the only writer.

type lifecycle =
  1. | Running
  2. | Paused
    (*

    events still update market state; the strategy is not consulted and emits nothing

    *)
  3. | Stopped
val lifecycle_to_string : lifecycle -> string
type position = {
  1. symbol : string;
  2. quantity : float;
    (*

    signed

    *)
  3. average_price : float;
  4. market_value : float;
  5. unrealized_pnl : float;
}
type fill = {
  1. ts_ns : int64;
  2. order_id : string;
  3. client_order_id : string;
  4. symbol : string;
  5. side : Side.t;
  6. quantity : float;
  7. price : float;
  8. commission : float;
  9. liquidity : Trade.execution_type;
  10. tag : string;
}
type instance = {
  1. strategy_id : string;
  2. strategy_name : string;
  3. strategy_version : string;
  4. lifecycle : lifecycle;
  5. allocation : float;
    (*

    capital assigned to this instance

    *)
  6. nav : float;
  7. cash : float;
  8. realized_pnl : float;
  9. unrealized_pnl : float;
  10. gross_exposure : float;
  11. net_exposure : float;
  12. leverage : float;
  13. positions : position list;
  14. working_orders : int;
  15. n_events : int;
  16. n_actions : int;
  17. n_submitted : int;
  18. n_rejected_by_risk : int;
  19. n_fills : int;
  20. recent_fills : fill list;
    (*

    newest first, bounded

    *)
  21. diagnostics : (string * float) list;
    (*

    whatever Strategy.S.diagnostics reports

    *)
  22. params : (string * float) list;
  23. last_event_ts_ns : int64;
  24. risk : Risk_snapshot.t option;
}
type t = {
  1. ts_ns : int64;
  2. instances : instance list;
  3. total_nav : float;
  4. total_allocation : float;
  5. n_events : int;
  6. n_dropped_full_queue : int;
}
val empty : t
val to_assoc : t -> (string * float) list

Flat numeric view, prefixed per instance. Feeds the telemetry collector's provider interface.

val instance_to_string : instance -> string
val to_string : t -> string