group_fills_into_trades
Documentation for eth_defi.hyperliquid.trade_history.group_fills_into_trades function.
- group_fills_into_trades(events, fills=None)
Group position events into round-trip trades.
Processes position events chronologically and groups them into round-trip trades. Each trade tracks a position from open to close (or to the current state if still open).
When a position was already open before the data window (i.e. the earliest fill has a non-zero
start_position), the trade is marked asis_complete=False.- Parameters
events (Iterable[eth_defi.hyperliquid.position.PositionEvent]) – Position events from
reconstruct_position_history(). Must be in chronological order.fills (list[eth_defi.hyperliquid.position.Fill] | None) – Optional original fills list for detecting incomplete trades via
start_position.
- Returns
Tuple of
(closed_trades, open_trades).- Return type
tuple[list[eth_defi.hyperliquid.trade_history.RoundTripTrade], list[eth_defi.hyperliquid.trade_history.RoundTripTrade]]