position_store
PositionStore: in-memory store with indexed position access.
Classes:
-
PositionStore–Maintains positions with pre-built indices for filtered access.
PositionStore
PositionStore()
Maintains positions with pre-built indices for filtered access.
Methods:
-
add–Register a position and build secondary indices.
-
by_book–Return all positions in book_type.
-
by_instrument–Return all positions for instrument_id.
-
by_side–Return all positions with side.
-
by_status–Return all positions with status.
-
close–Set position status to CLOSED and rebuild its index entries.
-
get–Return the position for position_id; raise KeyError if absent.
-
open_positions–Shortcut for by_status(PositionStatus.OPEN).
-
query–Return positions matching all non-None filter parameters.
by_instrument
by_instrument(instrument_id: str) -> list[Position]
Return all positions for instrument_id.
close
close(position_id: str) -> None
Set position status to CLOSED and rebuild its index entries.
get
get(position_id: str) -> Position
Return the position for position_id; raise KeyError if absent.
query
query(
*,
book_type: BookType | None = None,
side: PositionSide | None = None,
status: PositionStatus | None = None,
instrument_type: InstrumentType | None = None,
measurement_basis: MeasurementBasis | None = None,
) -> list[Position]
Return positions matching all non-None filter parameters.