pub fn py_calculate_reconciliation_price(
current_position_qty: Decimal,
current_position_avg_px: Option<Decimal>,
target_position_qty: Decimal,
target_position_avg_px: Option<Decimal>,
) -> Option<Decimal>Expand description
Calculate the price needed for a reconciliation order to achieve target position.
This is a pure function that calculates what price a fill would need to have to move from the current position state to the target position state with the correct average price, accounting for the netting simulation logic.
§Returns
Returns Some(Decimal) if a valid reconciliation price can be calculated, None otherwise.
§Notes
The function handles three scenarios:
- Flat to position: reconciliation_px = target_avg_px
- Position flip (sign change): reconciliation_px = target_avg_px (due to value reset in simulation)
- Accumulation/reduction: weighted average formula