RoundTripTrade

Documentation for eth_defi.hyperliquid.trade_history.RoundTripTrade Python class.

class RoundTripTrade

Bases: object

A round-trip trade from position open through close.

Groups individual fills from position-open to position-close with volume-weighted average entry/exit prices, funding costs, and PnL.

For positions that were already open before the data window, is_complete is False and entry_price may be unknown.

Attributes summary

coin

Asset symbol (e.g., "BTC", "ETH")

direction

Trade direction

is_open

Whether the position is still open

is_complete

Whether we have the full open→close lifecycle (False when position was already open before data window)

opened_at

Timestamp when the position was first opened (or earliest known fill)

closed_at

Timestamp when the position was closed (None if still open)

entry_price

Volume-weighted average entry price

exit_price

Volume-weighted average exit price (None if still open or no exits)

max_size

Maximum position size reached during the trade

current_size

Current position size (0 if closed)

realised_pnl

Realised PnL from fills (sum of closed_pnl)

funding_pnl

Total funding payments during this trade

total_fees

Total fees paid across all fills

net_pnl

Net PnL (realised_pnl + funding_pnl - total_fees)

unrealised_pnl

Unrealised PnL from clearinghouse state (open trades only)

fills

All fills belonging to this trade

funding_payments

All funding payments during this trade's lifetime

duration

Duration of the trade

fill_count

Number of fills

Methods summary

__init__(coin, direction, is_open, ...[, ...])

coin: str

Asset symbol (e.g., “BTC”, “ETH”)

direction: eth_defi.hyperliquid.position.PositionDirection

Trade direction

is_open: bool

Whether the position is still open

is_complete: bool

Whether we have the full open→close lifecycle (False when position was already open before data window)

opened_at: datetime.datetime

Timestamp when the position was first opened (or earliest known fill)

closed_at: datetime.datetime | None

Timestamp when the position was closed (None if still open)

entry_price: decimal.Decimal

Volume-weighted average entry price

exit_price: decimal.Decimal | None

Volume-weighted average exit price (None if still open or no exits)

max_size: decimal.Decimal

Maximum position size reached during the trade

current_size: decimal.Decimal

Current position size (0 if closed)

realised_pnl: decimal.Decimal

Realised PnL from fills (sum of closed_pnl)

funding_pnl: decimal.Decimal

Total funding payments during this trade

total_fees: decimal.Decimal

Total fees paid across all fills

net_pnl: decimal.Decimal

Net PnL (realised_pnl + funding_pnl - total_fees)

unrealised_pnl: decimal.Decimal | None

Unrealised PnL from clearinghouse state (open trades only)

fills: list[eth_defi.hyperliquid.position.Fill]

All fills belonging to this trade

funding_payments: list[eth_defi.hyperliquid.trade_history.FundingPayment]

All funding payments during this trade’s lifetime

duration: datetime.timedelta | None

Duration of the trade

fill_count: int

Number of fills

__init__(coin, direction, is_open, is_complete, opened_at, closed_at, entry_price, exit_price, max_size, current_size, realised_pnl, funding_pnl, total_fees, net_pnl, unrealised_pnl, fills=<factory>, funding_payments=<factory>, duration=None, fill_count=0, _entry_cost=Decimal('0'), _entry_size=Decimal('0'), _exit_cost=Decimal('0'), _exit_size=Decimal('0'))
Parameters
Return type

None