Module Algostream_order_management.Routing

Smart order routing across multiple typed Venue.t snapshots.

Pure-function API: route takes an order and a list of venue_snapshot (best bid/ask + depth + monthly_volume per venue) and returns a routing_decision that the caller then turns into one or more bus Order_request events. No bus subscription, no state, no submission — testable end-to-end as data in / data out.

type venue_snapshot = {
  1. venue : Venue.t;
  2. best_bid : float;
  3. best_ask : float;
  4. bid_depth : float;
    (*

    cumulative shares available at or near the best bid

    *)
  5. ask_depth : float;
  6. monthly_volume : float;
    (*

    caller's trailing 30-day volume on this venue

    *)
}
type routing_strategy =
  1. | Cheapest_venue
    (*

    single-venue: lowest effective taker fee among eligible venues

    *)
  2. | Best_price
    (*

    single-venue: tightest price for the order's side

    *)
  3. | Smart_split
    (*

    split across venues sorted by effective cost; bottom-up until quantity is met

    *)
type allocation = {
  1. venue_name : string;
  2. quantity : float;
  3. expected_price : float;
  4. expected_fee_bps : float;
}
type routing_decision = {
  1. strategy : routing_strategy;
  2. allocations : allocation list;
  3. expected_avg_price : float;
  4. expected_cost_bps : float;
  5. unallocated : float;
    (*

    > 0 when total depth across eligible venues < order quantity

    *)
  6. rationale : string;
}
val route : order:Order.order -> venues:venue_snapshot list -> ?strategy:routing_strategy -> unit -> routing_decision