Docs
Open Studio

Guides

Typed data migration

On this page8

FinLab trading payloads are moving from implicit dict/list structures to formal typed interfaces. This page lists the new schemas and APIs, how they stay compatible with existing code, and the deprecation policy. Legacy APIs keep working and typed and dict APIs can coexist, so you can migrate one piece at a time.

Migration steps

Move data models to finlab.schemas dataclasses

Use the new public schemas below for positions, orders and portfolios.

Switch to typed APIs incrementally

For example from_entries, generate_order_entries, get_data_typed, one call site at a time.

Keep the dict fallback

Keep the dict APIs until your UI, DB and scheduler layers finish migration.

New public schemas

Import these dataclasses from finlab.schemas. All of them provide from_dict() / to_dict():

from finlab.schemas import (
    OrderEntry,
    PortfolioConfigData,
    PortfolioData,
    PositionEntry,
    StrategyPositionData,
)

Positions: Position

MethodDescription
Position.from_entries(entries)Build a Position from a list of entries
Position.to_entries()Convert to a list of entries
from finlab.online.order_executor import Position

position = Position({'AAPL': 10, 'MSFT': 5})

entries = position.to_entries()
position = Position.from_entries(entries)

rows = position.to_list()  # the legacy API still works

Legacy from_list() / to_list() are still supported, and typed and dict APIs can coexist during migration.

Orders: OrderExecutor

MethodDescription
OrderExecutor.generate_orders(..., as_entries=False, quantity_type='decimal')Default behavior is unchanged: still returns list[dict]
OrderExecutor.generate_order_entries(..., quantity_type='decimal')Returns typed entries

quantity_type supports decimal (default), float and string.

Portfolio sync: PortfolioSyncManager

MethodDescription
get_data(typed=False)Read the data
set_data(data, typed=False)Write the data
get_data_typed()Read typed data
set_data_typed(data)Write typed data
  • Internal storage (self.data) remains the same dict shape.
  • Typed conversion is done only at API boundaries, keeping to_path / to_local / to_cloud compatible.

Strategy reports: CloudReport and ReportExecution

CloudReport provides typed access to strategy reports:

MemberDescription
CloudReport.from_dict(report_dict, execution_dict)Construct from dicts
CloudReport.position_info2()Get position info
CloudReport.position_schedulersSchedulers and weights

ReportExecution wraps backtest execution config:

MemberDescription
ReportExecution.from_dict(d) / .to_dict()Convert from and to a dict
.weightsCurrent position weights (pd.Series)
.next_weightsNext-period position weights
.actionsStop-loss / take-profit actions
.configBacktest config (resample, stopLoss, takeProfit, etc.)
.current_rebalance_date / .next_rebalance_dateRebalance dates

symbol and stock_id compatibility policy

Current policy:

  • symbol is canonical.
  • stock_id remains a backward-compatible alias.
  • Conflicting values in both keys raise an error.

Recommendations:

  • Prefer symbol in new code.
  • Keep stock_id read compatibility in third-party integrations until a major-version removal plan is announced.

Planned direction (tentative):

VersionPlan
1.xstock_id stays fully supported as alias
2.x (not earlier than)Re-evaluate warning-only mode or alias removal

Next steps

↑↓ Move Enter Open Esc Close