Module Algostream_strategy.Event

What a strategy observes.

Deliberately not Event_bus.Event.payload. The bus type carries transport concerns (sequence ids, priority bands, Raw of bytes) that a strategy has no business seeing, and the bus delivery path is asynchronous and only eventually consistent — unusable for a reproducible backtest. The backtest engine and a future live runner both translate into this type, which is what lets one Strategy.S serve both.

Every constructor carries ts_ns event time. Nothing here is derived from a clock.

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;
    (*

    always positive; direction is in side

    *)
  7. price : float;
  8. commission : float;
  9. liquidity : Trade.execution_type;
    (*

    Maker / Taker — drives which fee tier was charged

    *)
  10. venue : string;
}

A completed execution, reported back to the strategy after the inbound latency delay.

type order_reason =
  1. | Accepted
  2. | Rejected of string
  3. | Cancelled
  4. | Expired
  5. | Partially_filled
  6. | Filled
type t =
  1. | Tick of {
    1. symbol : string;
    2. ts_ns : int64;
    3. price : float;
    4. volume : float;
    5. bid : float option;
    6. ask : float option;
    }
  2. | Bar of Bar.t
  3. | Book of Order_book.order_book
  4. | Pair_snapshot of {
    1. snapshot : Algostream_pairs.Snapshot.t;
    2. y_symbol : string;
    3. x_symbol : string;
    }
    (*

    Emitted by the engine after driving Pairs.Per_pair inline. The engine deliberately bypasses Pairs.Processor — its Domain + SPSC queue + bus subscription are eventual-consistency machinery that would make a backtest irreproducible.

    Pair_id.t holds canonical symbols (BTC/USDT), but orders must be placed against raw exchange symbols (BTCUSDT). The engine configured the pair and therefore knows the mapping, so it carries it here rather than making every strategy re-derive it.

    *)
  5. | Fill of fill
  6. | Order_update of {
    1. order : Order.order;
    2. ts_ns : int64;
    3. reason : order_reason;
    }
  7. | Timer of {
    1. ts_ns : int64;
    2. tag : string;
    }
val ts_ns : t -> int64

Event time of any event — the strategy's only legitimate source of "now".

val symbol : t -> string option

The symbol an event concerns, where it concerns exactly one. Pair_snapshot and Timer return None.

val reason_to_string : order_reason -> string
val to_string : t -> string