investfly.models.portfolio

Portfolio state, positions, balances, orders, and broker contracts.

class Broker(builtins.str, enum.Enum):

Broker Type Enum

class PositionType(builtins.str, enum.Enum):

PositionType Enum

class TradeType(builtins.str, enum.Enum):

Trade Type Enum

class OrderType(builtins.str, enum.Enum):

Order Type Enum

@dataclass
class TradeOrder:

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/SELL orders; SHORT/COVER are invalid.
  • FOREX and FUTURE support directional BUY/SELL orders. A short strategy opens with SELL and closes with BUY; it should not emit SHORT or COVER.
  • STOCK/ETF/OPTION support the full BUY/SELL/SHORT/COVER lifecycle labels.
def validate(self) -> None:

Validate that required fields are provided

class PositionEffect(builtins.str, enum.Enum):

Whether an order opens or closes a position.

@dataclass
class OptionPackageOrder:

One atomic option-combo ticket plus optional option-structure metadata.

@dataclass
class OrderStatus:

Trade Order Status

@dataclass
class PendingOrder(investfly.models.portfolio.TradeOrder):

A submitted order awaiting fill, cancellation, or rejection.

Inherited Members
TradeOrder
validate
@dataclass
class OpenPosition:

A currently held long or short position.

@dataclass
class ClosedPosition:

A position that has been fully closed.

@dataclass
class CompletedTrade:

A filled trade and its execution details.

@dataclass
class Balances:

Current account balances reported by a portfolio's broker.

class Portfolio:

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.
def findPosition( self, security: investfly.models.marketdata.Security, positionType: PositionType) -> OpenPosition | None:

Return the matching open position, or None when it is not held.

@dataclass
class PortfolioPerformance:

Aggregated profit, return, and risk measurements for a portfolio.

@dataclass
class OptionPositionGroup:

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.

@dataclass
class OptionContractSnapshot:

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.

class OptionStrategyTemplate(builtins.str, enum.Enum):

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.

class OptionLegAction(builtins.str, enum.Enum):

Whether an option leg opens or closes a long or short position.

class OptionLegRole(builtins.str, enum.Enum):

Semantic role of a leg within a multi-leg option structure.