Generated Models¶
The SDK includes 1,224 auto-generated Pydantic v2 models covering Fidelity Trader+'s complete type system — enums, API request/response DTOs, and internal domain models.
These are separate from the hand-written SDK models and provide the full wire-format type definitions.
Structure¶
src/fidelity_trader/models/generated/
├── enums/ 17 files — domain enums (order actions, statuses, strategies, ...)
├── api/ 14 files — API wire-format DTOs (requests + responses)
└── internal/ 17 files — internal domain models (position detail, balance detail, ...)
Enums¶
Generated enums use Python's IntEnum (for numeric C# enums) or str, Enum (for string-valued SmartEnums).
from fidelity_trader.models.generated.enums.orders import (
OrderActionType,
OrderStatusType,
OrderSecurityType,
)
# Use in type-safe comparisons
if action == OrderActionType.Buy:
...
# Full enum values
print(list(OrderActionType))
# [Buy=0, Sell=1, BuyToCover=2, SellShort=3, BuyToOpen=4, ...]
Available enum modules:
| Module | Key Enums |
|---|---|
enums.orders |
OrderActionType, OrderStatusType, OrderSecurityType, OrderType, SavedOrderSecurityType |
enums.trade |
Trade-specific enums and SmartEnums |
enums.mlo_trade |
Multi-leg option strategy types |
enums.positions |
Position and security type enums |
enums.quote |
Streaming quote enums (subscription types, connection states) |
enums.alerts |
Alert operators, types, categories, status codes (22 statuses) |
enums.nebula_core |
Core app enums (29 types — balances, caching, orders, scanner, trade) |
enums.chart |
Chart security types and bar scales |
enums.option_chain |
Option chain enums |
enums.option_summary |
Option summary display enums |
enums.short_insights |
Short insights enums |
enums.sirius |
Platform enums (12 types) |
API DTOs¶
API models match the exact JSON wire format of Fidelity's endpoints. All fields use Field(alias="camelCase") for correct serialization.
from fidelity_trader.models.generated.api.trade import (
PriceDetailResp,
OrderConfirmDetailResp,
CondOrderDetailResp,
)
# These models use Decimal for financial fields (matching C# decimal)
from decimal import Decimal
Available API modules:
| Module | Key Models | Description |
|---|---|---|
api.orders |
OrderSummaryV3, StatusDetailBase, SecurityDetailV3, PriceTypeDetail |
Order status and detail DTOs (145 types) |
api.trade |
OrderConfirmDetailResp, PriceDetailResp, CondOrderDetailResp, DollarValues |
Equity/option/conditional trade DTOs (163 types) |
api.mlo_trade |
MultiLegOrderConfirmDetail, AnalyticDetail, ComplexOrderDetailResponse |
Multi-leg option DTOs (39 types) |
api.balances |
BalanceDetail, AcctValDetail, BuyingPowerDetail, MarginDetail |
Balance DTOs (42 types) |
api.accounts |
AccountDetail, AccountResponse, GroupDetail |
Account DTOs (20 types) |
api.option_chain |
Option chain contract models (32 types) | |
api.financing |
Accruals and financing DTOs (34 types) | |
api.short_insights |
Short interest DTOs (21 types) | |
api.closed_positions |
Closed position/gain-loss DTOs (9 types) | |
api.beps |
BEPS streaming auth models (6 types) |
Internal Domain Models¶
Internal models represent the app's domain objects — richer than the wire-format DTOs, with computed fields and nested structures.
from fidelity_trader.models.generated.internal.positions import (
PositionDetailObject,
CurrentDayTradingDetail,
PositionOptionDetailObject,
)
Available internal modules:
| Module | Key Models | Description |
|---|---|---|
internal.positions |
PositionDetailObject, PriceDetailObject, CurrentDayTradingDetail |
Full position domain (110 types) |
internal.nebula |
Account, alert, analytics, balance, order, position, trade models | Central state hub (142 types) |
internal.balances |
BalanceDetail, BondDetail, ShortDetail, OptionsDetail |
Balance domain (42 types) |
internal.alerts |
Alert triggers, confirmation, request/response models | Alert domain (35 types) |
internal.account_history |
Transaction, security, and history detail models (31 types) | |
internal.closed_positions |
Closed position and lot detail models (28 types) | |
internal.option_summary |
Option summary detail models (24 types) | |
internal.watchlist |
Watchlist and notebook models (42 types) | |
internal.quote |
Streaming quote internal models (36 types) |
Financial Precision¶
Generated models use Python Decimal for all fields that are decimal in the C# source. This preserves 128-bit precision for financial amounts:
from fidelity_trader.models.generated.api.trade import PriceDetailResp
# Decimal fields have exact precision — no floating point rounding
detail = PriceDetailResp(price=Decimal("199.99"), bidPrice=Decimal("199.98"))
The hand-written SDK models use float for backwards compatibility. Use generated models when precision matters (e.g., order pricing, cost basis calculations).
Regenerating Models¶
The codegen pipeline can be re-run when the Fidelity Trader+ application updates:
# Generate all categories
python -m tools.codegen.run --category all
# Generate specific category
python -m tools.codegen.run --category enums
python -m tools.codegen.run --category api
python -m tools.codegen.run --category internal
# Preview without writing
python -m tools.codegen.run --category all --dry-run
# Verbose output (show errors, file details)
python -m tools.codegen.run --category all --verbose
The pipeline parses C# source definitions, maps types to Python (including decimal to Decimal, nullable to Optional, collections to list), and generates Pydantic v2 models with correct Field(alias=...) mappings. Full regeneration takes under 1 second.
Service Layer¶
Not Yet Exposed
Generated models are currently SDK-only. The REST service uses the hand-written models. Future work will integrate generated models into service response schemas for richer type information.