investfly.models.portfolio
Portfolio state, positions, balances, orders, and broker contracts.
Broker Type Enum
PositionType Enum
Trade Type Enum
Order Type Enum
A class that represents a Trade Order.
For futures, if security is a product-level Security rather than a
specific Future contract, the engine automatically resolves it to the
earliest active contract outside the platform expiry buffer.
Action semantics are security-type specific:
- CRYPTO spot supports long-only
BUY/SELLorders;SHORT/COVERare invalid. - FOREX and FUTURE support directional
BUY/SELLorders. A short strategy opens withSELLand closes withBUY; it should not emitSHORTorCOVER. - STOCK/ETF/OPTION support the full
BUY/SELL/SHORT/COVERlifecycle labels.
Whether an order opens or closes a position.
One atomic option-combo ticket plus optional option-structure metadata.
Trade Order Status
A submitted order awaiting fill, cancellation, or rejection.
Inherited Members
A currently held long or short position.
A position that has been fully closed.
A filled trade and its execution details.
Current account balances reported by a portfolio's broker.
Current balances, positions, pending orders, and completed trades.
Attributes:
- portfolioId: Stable Investfly identifier for the portfolio.
- broker: Broker connected to the portfolio.
- balances: Current account balances.
- openPositions: Positions currently held by the portfolio.
- pendingOrders: Orders that have not reached a terminal state.
- completedTrades: Filled trades recorded for the portfolio.
Return the matching open position, or None when it is not held.
Aggregated profit, return, and risk measurements for a portfolio.
Group-level view used by strategy code (live + backtest).
Exit decisions (closeBeforeDte, profit/loss-based exits) are evaluated per-group rather than
per-leg. The runtime fills legs from Java's reconciled open-position-group endpoint, not
raw overlay table rows. Legs may include the underlying stock/ETF for buy-write structures
that were opened atomically.
Per-leg view derived from a live open position matched to a persisted group leg.
Java persists only grouping keys. Price, quantity, contract unit, expiry, and option-right fields come from the currently-open broker/paper position and option symbol parsing.
Templated option structures supported by the Phase-1 MVP automated options engine.
Naked short calls/puts and undefined-risk structures outside this list are rejected by validation. Each template prescribes a fixed leg count and action shape except CUSTOM_COMBO, where conservative validation reads the explicit leg specs.
Whether an option leg opens or closes a long or short position.
Semantic role of a leg within a multi-leg option structure.