Algostream_strategy.SideThe one place trade direction gets converted.
Direction is represented three different ways in the domain layer, and any fill pipeline has to cross all three:
Algostream_domain_orders.Order.order_side — a nominal variant, Buy | SellAlgostream_domain_trades.Trade.side — a polymorphic variant, `Buy | `SellPosition.add_trade / Portfolio.add_trade — a signed float quantity, negative for sellsUnifying those three would ripple through most of the test suite, so the representations stay as they are and every conversion goes through this module instead. If a sign flips somewhere, it flipped here.
val of_trade_side : [ `Buy | `Sell ] -> tval to_trade_side : t -> [ `Buy | `Sell ]val sign : t -> floatBuy → 1.0, Sell → -1.0.
val signed : t -> qty:float -> floatsigned side ~qty applies sign to a positive quantity, producing the signed value Portfolio.add_trade expects. A negative qty is treated as its magnitude — the side argument is authoritative, so callers cannot accidentally double-negate.
val of_signed : float -> t optionRecover a side from a signed quantity. None at exactly zero, where there is no direction.
val to_string : t -> string