# This file is automatically generated by pyo3_stub_gen
# ruff: noqa: E501, F401

import datetime
import typing

import numpy
import numpy.typing

import akquant

class AssetType:
    Stock: typing.ClassVar["AssetType"]
    Futures: typing.ClassVar["AssetType"]
    Option: typing.ClassVar["AssetType"]
    Fund: typing.ClassVar["AssetType"]
    Crypto: typing.ClassVar["AssetType"]
    Forex: typing.ClassVar["AssetType"]
    Index: typing.ClassVar["AssetType"]
    Bond: typing.ClassVar["AssetType"]
    Unknown: typing.ClassVar["AssetType"]

class ExecutionMode:
    NextOpen: typing.ClassVar["ExecutionMode"]
    CurrentClose: typing.ClassVar["ExecutionMode"]
    NextAverage: typing.ClassVar["ExecutionMode"]

class OrderStatus:
    New: typing.ClassVar["OrderStatus"]
    Submitted: typing.ClassVar["OrderStatus"]
    Accepted: typing.ClassVar["OrderStatus"]
    Rejected: typing.ClassVar["OrderStatus"]
    PartiallyFilled: typing.ClassVar["OrderStatus"]
    Filled: typing.ClassVar["OrderStatus"]
    Cancelled: typing.ClassVar["OrderStatus"]
    Expired: typing.ClassVar["OrderStatus"]

class OrderSide:
    Buy: typing.ClassVar["OrderSide"]
    Sell: typing.ClassVar["OrderSide"]

class OrderType:
    Market: typing.ClassVar["OrderType"]
    Limit: typing.ClassVar["OrderType"]
    StopMarket: typing.ClassVar["OrderType"]
    StopLimit: typing.ClassVar["OrderType"]
    OCO: typing.ClassVar["OrderType"]
    Bracket: typing.ClassVar["OrderType"]
    StopTrail: typing.ClassVar["OrderType"]
    StopTrailLimit: typing.ClassVar["OrderType"]

class OrderRole:
    Standalone: typing.ClassVar["OrderRole"]
    Entry: typing.ClassVar["OrderRole"]
    StopLoss: typing.ClassVar["OrderRole"]
    TakeProfit: typing.ClassVar["OrderRole"]
    TrailStop: typing.ClassVar["OrderRole"]
    TrailStopLimit: typing.ClassVar["OrderRole"]

class TimeInForce:
    GTC: typing.ClassVar["TimeInForce"]
    IOC: typing.ClassVar["TimeInForce"]
    FOK: typing.ClassVar["TimeInForce"]
    GTD: typing.ClassVar["TimeInForce"]

class TradingSession:
    Normal: typing.ClassVar["TradingSession"]
    PreMarket: typing.ClassVar["TradingSession"]
    PostMarket: typing.ClassVar["TradingSession"]

class CorporateActionType:
    Split: typing.ClassVar["CorporateActionType"]
    Dividend: typing.ClassVar["CorporateActionType"]

class OptionType:
    Call: typing.ClassVar["OptionType"]
    Put: typing.ClassVar["OptionType"]

class SettlementType:
    Physical: typing.ClassVar["SettlementType"]
    Cash: typing.ClassVar["SettlementType"]

class ATR:
    r"""平均真实波幅 (ATR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ATR": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 ATR 值
        """
        ...

class AVGPRICE:
    r"""平均价格指标 (AVGPRICE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "AVGPRICE": ...
    def update(
        self, open: float, high: float, low: float, close: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param open: 开盘价
        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 AVGPRICE 值
        """
        ...

class TRANGE:
    r"""真实波幅 (TRANGE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "TRANGE": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 TRANGE 值
        """
        ...

class MEDPRICE:
    r"""中位价指标 (MEDPRICE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "MEDPRICE": ...
    def update(self, high: float, low: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :return: 当前 MEDPRICE 值
        """
        ...

class TYPPRICE:
    r"""典型价格指标 (TYPPRICE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "TYPPRICE": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 TYPPRICE 值
        """
        ...

class WCLPRICE:
    r"""加权收盘价指标 (WCLPRICE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "WCLPRICE": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 WCLPRICE 值
        """
        ...

class MIDPRICE:
    r"""中点价格指标 (MIDPRICE)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MIDPRICE": ...
    def update(self, high: float, low: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :return: 当前 MIDPRICE 值
        """
        ...

class BacktestResult:
    r"""
    回测结果.

    :ivar equity_curve: 权益曲线 [(timestamp, equity)]
    :ivar cash_curve: 现金曲线 [(timestamp, cash)]
    :ivar metrics: 绩效指标对象
    :ivar trade_metrics: 交易统计对象
    :ivar trades: 平仓交易列表
    :ivar snapshots: 每日持仓快照 [(timestamp, [snapshot])]
    :ivar orders: 订单列表
    :ivar executions: 成交列表
    """

    equity_curve: list[tuple[int, float]]
    cash_curve: list[tuple[int, float]]
    metrics: PerformanceMetrics
    trade_metrics: TradePnL
    trades: list[ClosedTrade]
    snapshots: list[tuple[int, list[PositionSnapshot]]]
    orders: list[Order]
    executions: list[Trade]
    metrics_df: typing.Any
    orders_df: typing.Any
    def get_trades_ipc(self) -> bytes:
        r"""Get trades as Arrow IPC bytes (Zero-Copy-ish to Python)."""
        ...

    def get_positions_ipc(self) -> bytes:
        r"""Get positions history as Arrow IPC bytes."""
        ...

    def get_trades_dict(self) -> typing.Any:
        r"""Get trades as a dictionary of columns for fast DataFrame creation."""
        ...

    def get_positions_dict(self) -> typing.Any:
        r"""Get positions history as a dictionary of columns."""
        ...

    def get_orders_dict(self) -> typing.Any:
        r"""Get orders as a dictionary of columns for fast DataFrame creation."""
        ...

class Bar:
    r"""
    K 线数据结构.

    :ivar timestamp: Unix 时间戳 (纳秒)
    :ivar open: 开盘价
    :ivar high: 最高价
    :ivar low: 最低价
    :ivar close: 收盘价
    :ivar volume: 成交量
    :ivar symbol: 标的代码
    """

    timestamp: int
    symbol: str
    extra: dict[str, float]
    open: float
    high: float
    low: float
    close: float
    volume: float
    timestamp_str: str
    def __new__(
        cls,
        timestamp: int,
        open: float,
        high: float,
        low: float,
        close: float,
        volume: float,
        symbol: str,
        extra: typing.Optional[dict[str, float]] = ...,
    ) -> "Bar": ...
    def set_open(self, value: float) -> None: ...
    def set_high(self, value: float) -> None: ...
    def set_low(self, value: float) -> None: ...
    def set_close(self, value: float) -> None: ...
    def set_volume(self, value: float) -> None: ...
    def __repr__(self) -> str: ...

class BarAggregator:
    r"""
    K 线合成器.

    用于将 Tick 数据合成为 K 线 (Bar) 数据。
    """

    def __new__(cls, feed: "DataFeed", interval_min: int = ...) -> "BarAggregator": ...
    def on_tick(
        self, symbol: str, price: float, volume: float, timestamp_ns: int
    ) -> None:
        r"""
        处理新的 Tick 数据.

        :param symbol: 标的代码
        :param price: 最新价
        :param volume: 累计成交量 (TotalVolume)
        :param timestamp_ns: 时间戳 (纳秒)
        """
        ...

class BollingerBands:
    r"""布林带 (Bollinger Bands)."""

    value: typing.Optional[tuple[float, float, float]]
    def __new__(cls, period: int, multiplier: float) -> "BollingerBands": ...
    def update(self, value: float) -> typing.Optional[tuple[float, float, float]]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: (上轨, 中轨, 下轨)
        """
        ...

class ClosedTrade:
    r"""
    平仓交易记录.

    :ivar symbol: 标的代码
    :ivar entry_time: 开仓时间戳 (纳秒)
    :ivar exit_time: 平仓时间戳 (纳秒)
    :ivar entry_price: 开仓价格
    :ivar exit_price: 平仓价格
    :ivar quantity: 交易数量
    :ivar side: 方向 ("long" 或 "short")
    :ivar pnl: 毛利 (扣除佣金前)
    :ivar net_pnl: 净利 (扣除佣金后)
    :ivar return_pct: 收益率 (如 0.05 表示 5%)
    :ivar commission: 佣金
    :ivar duration_bars: 持仓 K 线数
    :ivar duration: 持仓时长 (纳秒)
    :ivar mae: 最大不利变动 (MAE)
    :ivar mfe: 最大有利变动 (MFE)
    :ivar entry_tag: 开仓订单标签
    :ivar exit_tag: 平仓订单标签
    :ivar entry_portfolio_value: 开仓时账户权益
    :ivar max_drawdown_pct: 交易期间最大回撤 (%)
    """

    symbol: str
    entry_time: int
    exit_time: int
    entry_price: float
    exit_price: float
    quantity: float
    side: str
    pnl: float
    net_pnl: float
    return_pct: float
    commission: float
    duration_bars: int
    duration: int
    mae: float
    mfe: float
    entry_tag: str
    exit_tag: str
    entry_portfolio_value: float
    max_drawdown_pct: float
    def __repr__(self) -> str: ...

class CorporateAction:
    symbol: str
    date: datetime.date
    action_type: akquant.CorporateActionType
    value: float
    def __new__(
        cls,
        symbol: str,
        date: datetime.date,
        action_type: akquant.CorporateActionType,
        value: float,
    ) -> "CorporateAction": ...
    def set_value(self, value: float) -> None: ...

class DataFeed:
    r"""
    数据源管理器.

    负责管理历史数据和实时数据流。
    支持 CSV 文件读取、数组批量加载和实时数据推送。
    """

    def sort(self) -> None: ...
    def add_bars(self, bars: typing.Sequence[Bar]) -> None: ...
    def add_arrays(
        self,
        timestamps: numpy.ndarray,
        opens: numpy.ndarray,
        highs: numpy.ndarray,
        lows: numpy.ndarray,
        closes: numpy.ndarray,
        volumes: numpy.ndarray,
        symbol: str,
    ) -> None: ...
    def __new__(
        cls,
        start_date: typing.Optional[str] = ...,
        end_date: typing.Optional[str] = ...,
    ) -> "DataFeed": ...

class EMA:
    r"""指数移动平均线 (EMA)."""

    value: typing.Optional[float]
    is_ready: bool
    period: int
    def __new__(cls, period: int) -> "EMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 EMA 值
        """
        ...

class Engine:
    r"""
    主回测引擎.

    :ivar feed: 数据源
    :ivar portfolio: 投资组合
    :ivar orders: 订单列表
    :ivar trades: 成交列表
    """

    risk_manager: RiskManager
    orders: list[Order]
    trades: list[Trade]
    portfolio: Portfolio
    feed: DataFeed
    snapshots: list[tuple[int, list[PositionSnapshot]]]
    def __new__(cls) -> "Engine": ...
    def set_risk_config(self, config: RiskConfig) -> None:
        r"""
        设置风控配置.

        由于 PyO3 对嵌套结构体的属性访问可能返回副本，
        提供此方法以显式更新风控配置。

        :param config: 新的风控配置
        """
        ...

    def set_history_depth(self, depth: int) -> None:
        r"""
        设置历史数据长度.

        :param depth: 历史数据长度
        """
        ...

    def set_timezone(self, offset: int) -> None:
        r"""
        设置时区偏移 (秒).

        :param offset: 偏移秒数 (例如 UTC+8 为 28800)
        """
        ...

    def use_simulated_execution(self) -> None:
        r"""
        启用模拟执行 (回测模式).

        默认模式。在内存中撮合订单。
        """
        ...

    def use_realtime_execution(self) -> None:
        r"""
        启用实盘执行 (CTP/Broker 模式).

        模拟对接 CTP 或其他 Broker API。
        在此模式下，订单会被标记为 Submitted 并等待回调 (目前仅模拟发送)。
        """
        ...

    def register_custom_matcher(
        self, asset_type: akquant.AssetType, matcher: typing.Any
    ) -> None:
        r"""
        注册自定义撮合器 (Python).

        :param asset_type: 资产类型
        :param matcher: Python 撮合器对象 (需实现 match 方法)
        """
        ...

    def set_execution_mode(self, mode: akquant.ExecutionMode) -> None:
        r"""
        设置撮合模式.

        :param mode: 撮合模式 (ExecutionMode.CurrentClose 或 ExecutionMode.NextOpen)
        :type mode: ExecutionMode
        """
        ...

    def use_simple_market(self, commission_rate: float) -> None:
        r"""
        启用 SimpleMarket (7x24小时, T+0, 无税, 简单佣金).

        :param commission_rate: 佣金率
        """
        ...

    def use_china_market(self) -> None:
        r"""启用 ChinaMarket (支持 T+1/T+0, 印花税, 过户费, 交易时段等)."""
        ...

    def set_t_plus_one(self, enabled: bool) -> None:
        r"""
        启用/禁用 T+1 交易规则 (仅针对 ChinaMarket).

        :param enabled: 是否启用 T+1
        :type enabled: bool
        """
        ...

    def set_force_session_continuous(self, enabled: bool) -> None:
        r"""
        强制连续交易时段.

        :param enabled: 是否强制连续交易 (忽略午休等)
        """
        ...

    def add_corporate_action(self, action: CorporateAction) -> None:
        r"""
        添加公司行为 (除权除息).

        :param action: 公司行为对象
        """
        ...

    def use_china_futures_market(self) -> None:
        r"""
        启用中国期货市场默认配置.

        - 切换到 ChinaMarket
        - 设置 T+0
        - 保持当前交易时段配置 (需手动设置 set_market_sessions 以匹配特定品种)
        """
        ...

    def process_option_expiry(self, _local_date: datetime.date) -> None: ...
    def set_stock_fee_rules(
        self,
        commission_rate: float,
        stamp_tax: float,
        transfer_fee: float,
        min_commission: float,
    ) -> None:
        r"""
        设置股票费率规则 (按交易金额比例).

        :param commission_rate: 佣金率 (如 0.0003)
        :param stamp_tax: 印花税率 (如 0.001)
        :param transfer_fee: 过户费率 (如 0.00002)
        :param min_commission: 最低佣金 (如 5.0)
        """
        ...

    def set_future_fee_rules(self, commission_rate: float) -> None:
        r"""
        设置期货费率规则.

        :param commission_rate: 佣金率 (如 0.0001)
        """
        ...

    def set_fund_fee_rules(
        self, commission_rate: float, transfer_fee: float, min_commission: float
    ) -> None:
        r"""
        设置基金费率规则.

        :param commission_rate: 佣金率
        :param transfer_fee: 过户费率
        :param min_commission: 最低佣金
        """
        ...

    def set_option_fee_rules(self, commission_per_contract: float) -> None:
        r"""
        设置期权费率规则.

        :param commission_per_contract: 每张合约佣金 (如 5.0)
        """
        ...

    def set_crypto_fee_rules(self, commission_rate: float) -> None:
        r"""
        设置加密货币费率规则 (按金额比例).

        :param commission_rate: 佣金率 (如 0.001)
        """
        ...

    def set_forex_fee_rules(self, commission_rate: float) -> None:
        r"""
        设置外汇费率规则 (按金额比例).

        :param commission_rate: 佣金率 (如 0.00005)
        """
        ...

    def set_slippage(self, type_: str, value: float) -> None:
        r"""
        设置滑点模型.

        :param type: 滑点类型 ("fixed" 或 "percent")
        :param value: 滑点值 (固定金额 或 百分比如 0.001)
        """
        ...

    def set_volume_limit(self, limit: float) -> None:
        r"""
        设置成交量限制.

        :param limit: 限制比例 (0.0-1.0), 0.0 为不限制
        """
        ...

    def set_market_sessions(
        self, sessions: typing.Sequence[tuple[str, str, akquant.TradingSession]]
    ) -> None:
        r"""
        设置市场交易时段.

        :param sessions: 交易时段列表，每个元素为 (开始时间, 结束时间, 时段类型)
        :type sessions: List[Tuple[str, str, TradingSession]]

        示例::

        ```python
        engine.set_market_sessions([
            ("09:30:00", "11:30:00", TradingSession.Normal),
            ("13:00:00", "15:00:00", TradingSession.Normal)
        ])
        ```
        """
        ...

    def add_instrument(self, instrument: Instrument) -> None:
        r"""
        添加交易标的.

        :param instrument: 交易标的对象
        :type instrument: Instrument
        """
        ...

    def set_cash(self, cash: float) -> None:
        r"""
        设置初始资金.

        :param cash: 初始资金数额
        :type cash: float
        """
        ...

    def add_data(self, feed: DataFeed) -> None:
        r"""
        添加数据源.

        :param feed: 数据源对象
        :type feed: DataFeed
        """
        ...

    def add_bars(self, bars: typing.Sequence[Bar]) -> None:
        r"""
        批量添加 K 线数据.

        :param bars: K 线列表
        """
        ...

    def set_stream_callback(self, callback: typing.Any) -> None: ...
    def clear_stream_callback(self) -> None: ...
    def set_stream_options(
        self,
        progress_interval: int,
        equity_interval: int,
        batch_size: int,
        max_buffer: int,
        error_mode: str,
        stream_mode: str,
    ) -> None: ...
    def set_default_strategy_id(self, strategy_id: typing.Optional[str]) -> None: ...
    def get_default_strategy_id(self) -> typing.Optional[str]: ...
    def get_strategy_slot_ids(self) -> list[str]: ...
    def get_strategy_slots(self) -> list[str]: ...
    def get_active_strategy_slot(self) -> int: ...
    def set_strategy_slots(self, slot_ids: list[str]) -> None: ...
    def set_strategy_for_slot(self, slot_index: int, strategy: typing.Any) -> None: ...
    def clear_strategy_for_slot(self, slot_index: int) -> None: ...
    def set_strategy_max_order_value_limits(self, limits: dict[str, float]) -> None: ...
    def set_strategy_max_order_size_limits(self, limits: dict[str, float]) -> None: ...
    def set_strategy_max_position_size_limits(
        self, limits: dict[str, float]
    ) -> None: ...
    def set_strategy_max_daily_loss_limits(self, limits: dict[str, float]) -> None: ...
    def set_strategy_max_drawdown_limits(self, limits: dict[str, float]) -> None: ...
    def set_strategy_reduce_only_after_risk(self, flags: dict[str, bool]) -> None: ...
    def set_strategy_risk_cooldown_bars(self, bars: dict[str, int]) -> None: ...
    def set_strategy_priorities(self, priorities: dict[str, int]) -> None: ...
    def set_strategy_risk_budget_limits(self, limits: dict[str, float]) -> None: ...
    def set_portfolio_risk_budget_limit(
        self, limit: typing.Optional[float]
    ) -> None: ...
    def set_risk_budget_mode(self, mode: str) -> None: ...
    def set_risk_budget_reset_daily(self, enabled: bool) -> None: ...
    def run(self, strategy: typing.Any, show_progress: bool) -> str:
        r"""
        运行回测.

        :param strategy: 策略对象
        :param show_progress: 是否显示进度条
        :type strategy: object
        :type show_progress: bool
        :return: 回测结果摘要
        :rtype: str
        """
        ...

    def get_results(self) -> BacktestResult:
        r"""
        获取回测结果.

        :return: BacktestResult
        """
        ...

class Instrument:
    r"""
    交易标的.

    :ivar symbol: 代码
    :ivar asset_type: 资产类型
    :ivar multiplier: 合约乘数
    :ivar margin_ratio: 保证金比率
    :ivar tick_size: 最小变动价位
    """

    asset_type: akquant.AssetType
    symbol: str
    multiplier: float
    margin_ratio: float
    lot_size: float
    tick_size: float
    def __new__(
        cls,
        symbol: str,
        asset_type: AssetType,
        multiplier: float = ...,
        margin_ratio: float = ...,
        tick_size: float = ...,
        option_type: typing.Optional[OptionType] = ...,
        strike_price: typing.Optional[float] = ...,
        expiry_date: typing.Optional[int] = ...,
        lot_size: float = ...,
        underlying_symbol: typing.Optional[str] = ...,
        settlement_type: typing.Optional[SettlementType] = ...,
    ) -> "Instrument": ...

class MACD:
    r"""平滑异同移动平均线 (MACD)."""

    value: typing.Optional[tuple[float, float, float]]
    def __new__(
        cls, fast_period: int, slow_period: int, signal_period: int
    ) -> "MACD": ...
    def update(self, value: float) -> typing.Optional[tuple[float, float, float]]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: (DIF, DEA, MACD柱)
        """
        ...

class APO:
    r"""绝对价格震荡指标 (APO)."""

    value: typing.Optional[float]
    def __new__(cls, fast_period: int, slow_period: int) -> "APO": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 APO 值
        """
        ...

class PPO:
    r"""百分比价格震荡指标 (PPO)."""

    value: typing.Optional[float]
    def __new__(cls, fast_period: int, slow_period: int) -> "PPO": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 PPO 值
        """
        ...

class Order:
    r"""
    订单.

    :ivar id: 订单ID
    :ivar symbol: 标的代码
    :ivar side: 交易方向
    :ivar order_type: 订单类型
    :ivar quantity: 数量
    :ivar price: 价格 (限价单有效)
    :ivar time_in_force: 订单有效期
    :ivar trigger_price: 触发价格 (止损/止盈单)
    :ivar status: 订单状态
    :ivar filled_quantity: 已成交数量
    :ivar average_filled_price: 成交均价
    """

    id: str
    symbol: str
    side: akquant.OrderSide
    order_type: akquant.OrderType
    time_in_force: akquant.TimeInForce
    status: akquant.OrderStatus
    created_at: int
    updated_at: int
    tag: str
    reject_reason: str
    owner_strategy_id: typing.Optional[str]
    graph_id: typing.Optional[str]
    parent_order_id: typing.Optional[str]
    order_role: akquant.OrderRole
    trail_offset: typing.Optional[float]
    trail_reference_price: typing.Optional[float]
    commission: float
    quantity: float
    price: typing.Optional[float]
    trigger_price: typing.Optional[float]
    filled_quantity: float
    average_filled_price: typing.Optional[float]
    def __new__(
        cls,
        id: str,
        symbol: str,
        side: akquant.OrderSide,
        order_type: akquant.OrderType,
        quantity: float,
        price: typing.Optional[float] = ...,
        time_in_force: typing.Optional[akquant.TimeInForce] = ...,
        trigger_price: typing.Optional[float] = ...,
        created_at: int = ...,
        tag: str = ...,
        owner_strategy_id: typing.Optional[str] = ...,
        graph_id: typing.Optional[str] = ...,
        parent_order_id: typing.Optional[str] = ...,
        order_role: typing.Optional[akquant.OrderRole] = ...,
        trail_offset: typing.Optional[float] = ...,
        trail_reference_price: typing.Optional[float] = ...,
    ) -> "Order": ...
    def set_trail_offset(self, value: typing.Optional[float]) -> None: ...
    def set_trail_reference_price(self, value: typing.Optional[float]) -> None: ...
    def set_filled_quantity(self, value: float) -> None: ...
    def set_average_filled_price(self, value: typing.Optional[float]) -> None: ...
    def __repr__(self) -> str: ...

class PerformanceMetrics:
    r"""
    绩效指标.

    :ivar total_return: 总收益 (数值)
    :ivar annualized_return: 年化收益率
    :ivar max_drawdown: 最大回撤 (百分比, 如 0.15 表示 15%)
    :ivar max_drawdown_value: 最大回撤金额
    :ivar max_drawdown_pct: 最大回撤百分比 (如 15.0 表示 15%)
    :ivar sharpe_ratio: 夏普比率
    :ivar sortino_ratio: 索提诺比率
    :ivar calmar_ratio: 卡玛比率
    :ivar volatility: 年化波动率
    :ivar ulcer_index: 溃疡指数
    :ivar upi: 溃疡绩效指数 (UPI)
    :ivar equity_r2: 权益曲线 R^2 (拟合度)
    :ivar std_error: 标准误差
    :ivar win_rate: 胜率 (0.0-1.0)
    :ivar initial_market_value: 初始市值
    :ivar end_market_value: 结束市值
    :ivar total_return_pct: 总收益率 (%)
    :ivar start_time: 开始时间戳 (纳秒)
    :ivar end_time: 结束时间戳 (纳秒)
    :ivar duration: 持续时间 (纳秒)
    :ivar total_bars: 总 K 线数
    :ivar exposure_time_pct: 市场暴露时间百分比
    :ivar var_95: 95% VaR (在风险价值)
    :ivar var_99: 99% VaR
    :ivar cvar_95: 95% CVaR (条件在风险价值)
    :ivar cvar_99: 99% CVaR
    """

    total_return: float
    annualized_return: float
    max_drawdown: float
    max_drawdown_value: float
    max_drawdown_pct: float
    sharpe_ratio: float
    sortino_ratio: float
    calmar_ratio: float
    volatility: float
    ulcer_index: float
    upi: float
    equity_r2: float
    std_error: float
    win_rate: float
    initial_market_value: float
    end_market_value: float
    total_return_pct: float
    start_time: int
    end_time: int
    duration: int
    total_bars: int
    exposure_time_pct: float
    var_95: float
    var_99: float
    cvar_95: float
    cvar_99: float
    def __repr__(self) -> str: ...
    def __getitem__(self, key: str) -> typing.Any: ...

class Portfolio:
    r"""
    投资组合管理.

    :ivar cash: 当前现金余额
    :ivar positions: 当前持仓 (symbol -> quantity)
    :ivar available_positions: 可用持仓 (symbol -> quantity)
    :ivar total_equity: 总权益 (动态计算)
    """

    cash: float
    positions: dict[str, float]
    available_positions: dict[str, float]

    def __new__(cls, cash: float) -> "Portfolio": ...
    def get_cash(self) -> float: ...
    def get_positions(self) -> dict[str, float]: ...
    def get_available_positions(self) -> dict[str, float]: ...
    def get_position(self, symbol: str) -> float: ...
    def get_available_position(self, symbol: str) -> float: ...
    def __repr__(self) -> str: ...

class PositionSnapshot:
    r"""
    每日持仓快照.

    :ivar symbol: 标的代码
    :ivar quantity: 持仓数量
    :ivar entry_price: 开仓均价
    :ivar long_shares: 多头持仓数量
    :ivar short_shares: 空头持仓数量
    :ivar close: 收盘价
    :ivar equity: 账户权益
    :ivar market_value: 市值
    :ivar margin: 保证金
    :ivar unrealized_pnl: 未实现盈亏
    """

    symbol: str
    quantity: float
    entry_price: float
    long_shares: float
    short_shares: float
    close: float
    equity: float
    market_value: float
    margin: float
    unrealized_pnl: float
    def __repr__(self) -> str: ...

class RSI:
    r"""相对强弱指数 (RSI)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "RSI": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点 (通常是收盘价)
        :return: 当前 RSI 值
        """
        ...

class ROC:
    r"""变化率指标 (ROC)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ROC": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ROC 值
        """
        ...

class ROCP:
    r"""变化率百分比指标 (ROCP)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ROCP": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ROCP 值
        """
        ...

class ROCR:
    r"""变化率比值指标 (ROCR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ROCR": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ROCR 值
        """
        ...

class ROCR100:
    r"""变化率比值指标 (ROCR100)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ROCR100": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ROCR100 值
        """
        ...

class MOM:
    r"""动量指标 (MOM)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MOM": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MOM 值
        """
        ...

class CMO:
    r"""钱德动量摆动指标 (CMO)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "CMO": ...
    def update(self, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param close: 收盘价
        :return: 当前 CMO 值
        """
        ...

class OBV:
    r"""能量潮指标 (OBV)."""

    value: typing.Optional[float]
    def __new__(cls) -> "OBV": ...
    def update(self, close: float, volume: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param close: 收盘价
        :param volume: 成交量
        :return: 当前 OBV 值
        """
        ...

class AD:
    r"""蔡金累积/派发线 (AD)."""

    value: typing.Optional[float]
    def __new__(cls) -> "AD": ...
    def update(
        self, high: float, low: float, close: float, volume: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :param volume: 成交量
        :return: 当前 AD 值
        """
        ...

class ADOSC:
    r"""蔡金累积/派发振荡器 (ADOSC)."""

    value: typing.Optional[float]
    def __new__(cls, fast_period: int, slow_period: int) -> "ADOSC": ...
    def update(
        self, high: float, low: float, close: float, volume: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :param volume: 成交量
        :return: 当前 ADOSC 值
        """
        ...

class BOP:
    r"""均势指标 (BOP)."""

    value: typing.Optional[float]
    def __new__(cls) -> "BOP": ...
    def update(
        self, open: float, high: float, low: float, close: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param open: 开盘价
        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 BOP 值
        """
        ...

class DEMA:
    r"""双指数移动平均线 (DEMA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "DEMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 DEMA 值
        """
        ...

class TRIX:
    r"""三重指数平滑变动率 (TRIX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "TRIX": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TRIX 值
        """
        ...

class MFI:
    r"""资金流量指标 (MFI)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MFI": ...
    def update(
        self, high: float, low: float, close: float, volume: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :param volume: 成交量
        :return: 当前 MFI 值
        """
        ...

class TEMA:
    r"""三重指数移动平均线 (TEMA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "TEMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TEMA 值
        """
        ...

class KAMA:
    r"""考夫曼自适应均线 (KAMA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "KAMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 KAMA 值
        """
        ...

class NATR:
    r"""标准化真实波幅均值 (NATR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "NATR": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 NATR 值
        """
        ...

class STDDEV:
    r"""标准差指标 (STDDEV)."""

    value: typing.Optional[float]
    def __new__(cls, period: int, nbdev: float) -> "STDDEV": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 STDDEV 值
        """
        ...

class VAR:
    r"""方差指标 (VAR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int, nbdev: float) -> "VAR": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 VAR 值
        """
        ...

class SAR:
    r"""抛物线转向指标 (SAR)."""

    value: typing.Optional[float]
    def __new__(cls, acceleration: float, maximum: float) -> "SAR": ...
    def update(self, high: float, low: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :return: 当前 SAR 值
        """
        ...

class CCI:
    r"""顺势指标 (CCI)."""

    value: typing.Optional[float]
    def __new__(cls, period: int, c: float) -> "CCI": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 CCI 值
        """
        ...

class ADX:
    r"""平均趋向指标 (ADX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ADX": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 ADX 值
        """
        ...

class DX:
    r"""动向指数 (DX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "DX": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 DX 值
        """
        ...

class ADXR:
    r"""平均趋向指标评分 (ADXR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "ADXR": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 ADXR 值
        """
        ...

class PLUS_DI:
    r"""正向动向指标 (+DI)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "PLUS_DI": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 +DI 值
        """
        ...

class MINUS_DI:
    r"""负向动向指标 (-DI)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MINUS_DI": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 -DI 值
        """
        ...

class ULTOSC:
    r"""终极振荡器 (ULTOSC)."""

    value: typing.Optional[float]
    def __new__(cls, period1: int, period2: int, period3: int) -> "ULTOSC": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 ULTOSC 值
        """
        ...

class AROON:
    r"""阿隆指标 (AROON)."""

    value: typing.Optional[tuple[float, float]]
    def __new__(cls, period: int) -> "AROON": ...
    def update(self, high: float, low: float) -> typing.Optional[tuple[float, float]]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :return: (AroonDown, AroonUp)
        """
        ...

class AROONOSC:
    r"""阿隆振荡器 (AROONOSC)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "AROONOSC": ...
    def update(self, high: float, low: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :return: 当前 AROONOSC 值
        """
        ...

class LINEARREG:
    r"""线性回归端点值 (LINEARREG)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "LINEARREG": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LINEARREG 值
        """
        ...

class LINEARREG_SLOPE:
    r"""线性回归斜率 (LINEARREG_SLOPE)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "LINEARREG_SLOPE": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LINEARREG_SLOPE 值
        """
        ...

class LINEARREG_R2:
    r"""线性回归决定系数 (LINEARREG_R2)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "LINEARREG_R2": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LINEARREG_R2 值
        """
        ...

class HT_TRENDLINE:
    r"""希尔伯特趋势线 (HT_TRENDLINE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "HT_TRENDLINE": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 HT_TRENDLINE 值
        """
        ...

class LINEARREG_INTERCEPT:
    r"""线性回归截距 (LINEARREG_INTERCEPT)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "LINEARREG_INTERCEPT": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LINEARREG_INTERCEPT 值
        """
        ...

class LINEARREG_ANGLE:
    r"""线性回归角度 (LINEARREG_ANGLE)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "LINEARREG_ANGLE": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LINEARREG_ANGLE 值
        """
        ...

class TSF:
    r"""时间序列预测 (TSF)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "TSF": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TSF 值
        """
        ...

class CORREL:
    r"""相关系数指标 (CORREL)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "CORREL": ...
    def update(self, x: float, y: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param x: 第一个序列值
        :param y: 第二个序列值
        :return: 当前 CORREL 值
        """
        ...

class BETA:
    r"""贝塔系数指标 (BETA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "BETA": ...
    def update(self, x: float, y: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param x: 第一个序列值
        :param y: 第二个序列值
        :return: 当前 BETA 值
        """
        ...

class COVAR:
    r"""协方差指标 (COVAR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "COVAR": ...
    def update(self, x: float, y: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param x: 第一个序列值
        :param y: 第二个序列值
        :return: 当前 COVAR 值
        """
        ...

class STOCH:
    r"""随机指标 (STOCH)."""

    value: typing.Optional[tuple[float, float]]
    def __new__(
        cls, fastk_period: int, slowk_period: int, slowd_period: int
    ) -> "STOCH": ...
    def update(
        self, high: float, low: float, close: float
    ) -> typing.Optional[tuple[float, float]]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 (slowk, slowd)
        """
        ...

class RiskConfig:
    r"""风控配置."""

    restricted_list: list[str]
    max_order_size: typing.Optional[float]
    max_order_value: typing.Optional[float]
    max_position_size: typing.Optional[float]
    max_position_pct: typing.Optional[float]
    active: bool
    check_cash: bool
    safety_margin: float
    def __new__(cls) -> "RiskConfig": ...

class RiskManager:
    config: RiskConfig
    def add_max_position_percent_rule(self, pct: float) -> None: ...
    def add_sector_concentration_rule(
        self, limit: float, sector_map: typing.Mapping[str, str]
    ) -> None: ...
    def add_max_drawdown_rule(self, limit: float) -> None: ...
    def add_max_daily_loss_rule(self, limit: float) -> None: ...
    def add_stop_loss_rule(self, threshold: float) -> None: ...

class SMA:
    r"""简单移动平均线 (SMA)."""

    value: typing.Optional[float]
    is_ready: bool
    def __new__(cls, period: int) -> "SMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SMA 值 (如果数据不足则返回 None)
        """
        ...

class WMA:
    r"""加权移动平均线 (WMA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "WMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 WMA 值
        """
        ...

class TRIMA:
    r"""三角移动平均线 (TRIMA)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "TRIMA": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TRIMA 值
        """
        ...

class MIDPOINT:
    r"""中点指标 (MIDPOINT)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MIDPOINT": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MIDPOINT 值
        """
        ...

class MAX:
    r"""滚动最大值指标 (MAX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MAX": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MAX 值
        """
        ...

class MIN:
    r"""滚动最小值指标 (MIN)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MIN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MIN 值
        """
        ...

class MAXINDEX:
    r"""滚动最大值索引指标 (MAXINDEX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MAXINDEX": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MAXINDEX 值
        """
        ...

class MININDEX:
    r"""滚动最小值索引指标 (MININDEX)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "MININDEX": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 MININDEX 值
        """
        ...

class MINMAXINDEX:
    r"""滚动最值索引双输出指标 (MINMAXINDEX)."""

    value: typing.Optional[tuple[float, float]]
    def __new__(cls, period: int) -> "MINMAXINDEX": ...
    def update(self, value: float) -> typing.Optional[tuple[float, float]]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 (MININDEX, MAXINDEX)
        """
        ...

class MINMAX:
    r"""滚动最值双输出指标 (MINMAX)."""

    value: typing.Optional[tuple[float, float]]
    def __new__(cls, period: int) -> "MINMAX": ...
    def update(self, value: float) -> typing.Optional[tuple[float, float]]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 (MIN, MAX)
        """
        ...

class SUM:
    r"""滚动求和指标 (SUM)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "SUM": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SUM 值
        """
        ...

class AVGDEV:
    r"""平均绝对偏差指标 (AVGDEV)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "AVGDEV": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 AVGDEV 值
        """
        ...

class RANGE:
    r"""滚动高低差指标 (RANGE)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "RANGE": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 RANGE 值
        """
        ...

class LN:
    r"""自然对数变换指标 (LN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "LN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LN 值
        """
        ...

class LOG10:
    r"""常用对数变换指标 (LOG10)."""

    value: typing.Optional[float]
    def __new__(cls) -> "LOG10": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 LOG10 值
        """
        ...

class SQRT:
    r"""平方根变换指标 (SQRT)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SQRT": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SQRT 值
        """
        ...

class CEIL:
    r"""向上取整变换指标 (CEIL)."""

    value: typing.Optional[float]
    def __new__(cls) -> "CEIL": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 CEIL 值
        """
        ...

class FLOOR:
    r"""向下取整变换指标 (FLOOR)."""

    value: typing.Optional[float]
    def __new__(cls) -> "FLOOR": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 FLOOR 值
        """
        ...

class SIN:
    r"""正弦变换指标 (SIN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SIN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SIN 值
        """
        ...

class COS:
    r"""余弦变换指标 (COS)."""

    value: typing.Optional[float]
    def __new__(cls) -> "COS": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 COS 值
        """
        ...

class TAN:
    r"""正切变换指标 (TAN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "TAN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TAN 值
        """
        ...

class ASIN:
    r"""反正弦变换指标 (ASIN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ASIN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ASIN 值
        """
        ...

class ACOS:
    r"""反余弦变换指标 (ACOS)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ACOS": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ACOS 值
        """
        ...

class ATAN:
    r"""反正切变换指标 (ATAN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ATAN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ATAN 值
        """
        ...

class SINH:
    r"""双曲正弦变换指标 (SINH)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SINH": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SINH 值
        """
        ...

class COSH:
    r"""双曲余弦变换指标 (COSH)."""

    value: typing.Optional[float]
    def __new__(cls) -> "COSH": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 COSH 值
        """
        ...

class TANH:
    r"""双曲正切变换指标 (TANH)."""

    value: typing.Optional[float]
    def __new__(cls) -> "TANH": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 TANH 值
        """
        ...

class EXP:
    r"""指数变换指标 (EXP)."""

    value: typing.Optional[float]
    def __new__(cls) -> "EXP": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 EXP 值
        """
        ...

class ABS:
    r"""绝对值变换指标 (ABS)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ABS": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 ABS 值
        """
        ...

class SIGN:
    r"""符号变换指标 (SIGN)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SIGN": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 SIGN 值
        """
        ...

class ADD:
    r"""逐元素加法指标 (ADD)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ADD": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 ADD 值
        """
        ...

class SUB:
    r"""逐元素减法指标 (SUB)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SUB": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 SUB 值
        """
        ...

class MULT:
    r"""逐元素乘法指标 (MULT)."""

    value: typing.Optional[float]
    def __new__(cls) -> "MULT": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 MULT 值
        """
        ...

class DIV:
    r"""逐元素除法指标 (DIV)."""

    value: typing.Optional[float]
    def __new__(cls) -> "DIV": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 DIV 值
        """
        ...

class MAX2:
    r"""逐元素最大值指标 (MAX2)."""

    value: typing.Optional[float]
    def __new__(cls) -> "MAX2": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 MAX2 值
        """
        ...

class MIN2:
    r"""逐元素最小值指标 (MIN2)."""

    value: typing.Optional[float]
    def __new__(cls) -> "MIN2": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 MIN2 值
        """
        ...

class CLIP:
    r"""逐元素截断指标 (CLIP)."""

    value: typing.Optional[float]
    def __new__(cls) -> "CLIP": ...
    def update(
        self, value: float, min_value: float, max_value: float
    ) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 输入值
        :param min_value: 下界
        :param max_value: 上界
        :return: 当前 CLIP 值
        """
        ...

class ROUND:
    r"""逐元素四舍五入指标 (ROUND)."""

    value: typing.Optional[float]
    def __new__(cls) -> "ROUND": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 输入值
        :return: 当前 ROUND 值
        """
        ...

class POW:
    r"""逐元素幂运算指标 (POW)."""

    value: typing.Optional[float]
    def __new__(cls) -> "POW": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 POW 值
        """
        ...

class MOD:
    r"""逐元素取模指标 (MOD)."""

    value: typing.Optional[float]
    def __new__(cls) -> "MOD": ...
    def update(self, left: float, right: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param left: 第一个序列值
        :param right: 第二个序列值
        :return: 当前 MOD 值
        """
        ...

class CLAMP01:
    r"""固定区间截断指标 (CLAMP01)."""

    value: typing.Optional[float]
    def __new__(cls) -> "CLAMP01": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 输入值
        :return: 当前 CLAMP01 值
        """
        ...

class SQ:
    r"""逐元素平方指标 (SQ)."""

    value: typing.Optional[float]
    def __new__(cls) -> "SQ": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 输入值
        :return: 当前 SQ 值
        """
        ...

class CUBE:
    r"""逐元素立方指标 (CUBE)."""

    value: typing.Optional[float]
    def __new__(cls) -> "CUBE": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 输入值
        :return: 当前 CUBE 值
        """
        ...

class T3:
    r"""三重指数平滑指标 (T3)."""

    value: typing.Optional[float]
    def __new__(cls, period: int, vfactor: float) -> "T3": ...
    def update(self, value: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 T3 值
        """
        ...

class MAMA:
    r"""自适应均线指标 (MAMA)."""

    value: typing.Optional[tuple[float, float]]
    def __new__(cls, fast_limit: float, slow_limit: float) -> "MAMA": ...
    def update(self, value: float) -> typing.Optional[tuple[float, float]]:
        r"""
        更新指标值.

        :param value: 新数据点
        :return: 当前 (MAMA, FAMA)
        """
        ...

class WILLR:
    r"""威廉指标 (WILLR)."""

    value: typing.Optional[float]
    def __new__(cls, period: int) -> "WILLR": ...
    def update(self, high: float, low: float, close: float) -> typing.Optional[float]:
        r"""
        更新指标值.

        :param high: 最高价
        :param low: 最低价
        :param close: 收盘价
        :return: 当前 WILLR 值
        """
        ...

class StrategyContext:
    r"""
    策略上下文.

    :ivar orders: 订单列表 (内部使用)
    :ivar cash: 当前现金
    :ivar positions: 当前持仓
    :ivar available_positions: 可用持仓
    :ivar session: 当前交易时段
    """

    orders: list[Order]
    canceled_order_ids: list[str]
    active_orders: list[Order]
    timers: list[Timer]
    session: akquant.TradingSession
    current_time: int
    recent_trades: list[Trade]
    risk_config: RiskConfig
    strategy_id: typing.Optional[str]
    last_closed_trade: typing.Optional[ClosedTrade]
    closed_trades: list[ClosedTrade]
    cash: float
    positions: dict[str, float]
    available_positions: dict[str, float]
    def __new__(
        cls,
        cash: typing.Any,
        positions: typing.Mapping[str, float],
        available_positions: typing.Mapping[str, float],
        session: typing.Optional[akquant.TradingSession],
        current_time: typing.Optional[int],
        active_orders: typing.Optional[typing.Sequence[Order]],
        closed_trades: typing.Optional[typing.Sequence[ClosedTrade]],
        recent_trades: typing.Optional[typing.Sequence[Trade]],
        risk_config: typing.Optional[RiskConfig],
    ) -> "StrategyContext": ...
    def history(
        self, symbol: str, field: str, count: int
    ) -> typing.Optional[numpy.typing.NDArray[numpy.float64]]:
        r"""
        获取历史数据.

        :param symbol: 标的代码
        :param field: 字段名 (open, high, low, close, volume)
        :param count: 获取的数据长度
        :return: numpy array or None
        """
        ...

    def schedule(self, timestamp: int, payload: str) -> None:
        r"""
        注册定时器.

        :param timestamp: 触发时间戳 (纳秒)
        :param payload: 携带的数据 (如回调函数名)
        """
        ...

    def cancel_order(self, order_id: str) -> None:
        r"""
        取消订单.

        :param order_id: 订单 ID
        """
        ...

    def buy(
        self,
        symbol: str,
        quantity: float,
        price: typing.Optional[float] = ...,
        time_in_force: typing.Optional[akquant.TimeInForce] = ...,
        trigger_price: typing.Optional[float] = ...,
        tag: str = ...,
        order_type: typing.Optional[akquant.OrderType] = ...,
        trail_offset: typing.Optional[float] = ...,
        trail_reference_price: typing.Optional[float] = ...,
    ) -> str:
        r"""
        买入下单.

        :param symbol: 标的代码
        :param quantity: 买入数量 (正数)
        :param price: 限价 (可选, 默认为 Market 单)
        :param time_in_force: 订单有效期 (可选, 默认 GTC)
        :param trigger_price: 触发价格 (可选, 用于止损/止盈单)
        :param tag: 订单标签 (可选)
        :return: 订单 ID
        """
        ...

    def sell(
        self,
        symbol: str,
        quantity: float,
        price: typing.Optional[float] = ...,
        time_in_force: typing.Optional[akquant.TimeInForce] = ...,
        trigger_price: typing.Optional[float] = ...,
        tag: str = ...,
        order_type: typing.Optional[akquant.OrderType] = ...,
        trail_offset: typing.Optional[float] = ...,
        trail_reference_price: typing.Optional[float] = ...,
    ) -> str:
        r"""
        卖出下单.

        :param symbol: 标的代码
        :param quantity: 卖出数量 (正数)
        :param price: 限价 (可选, 默认为 Market 单)
        :param time_in_force: 订单有效期 (可选, 默认 GTC)
        :param trigger_price: 触发价格 (可选, 用于止损/止盈单)
        :param tag: 订单标签 (可选)
        :return: 订单 ID
        """
        ...

    def get_position(self, symbol: str) -> float:
        r"""
        获取当前持仓数量.

        :param symbol: 标的代码
        :return: 持仓数量 (Long为正, Short为负)
        """
        ...

    def get_available_position(self, symbol: str) -> float:
        r"""
        获取当前可用持仓数量.

        :param symbol: 标的代码
        :return: 可用持仓数量
        """
        ...

class Tick:
    r"""
    Tick 数据结构.

    :ivar timestamp: Unix 时间戳 (纳秒)
    :ivar price: 最新价
    :ivar volume: 成交量
    :ivar symbol: 标的代码
    """

    timestamp: int
    symbol: str
    price: float
    volume: float
    timestamp_str: str
    def __new__(
        cls, timestamp: typing.Any, price: typing.Any, volume: typing.Any, symbol: str
    ) -> "Tick": ...
    def set_price(self, value: typing.Any) -> None: ...
    def set_volume(self, value: typing.Any) -> None: ...
    def __repr__(self) -> str: ...

class Timer:
    timestamp: int
    payload: str

class Trade:
    r"""
    成交记录.

    :ivar id: 成交ID
    :ivar order_id: 订单ID
    :ivar symbol: 标的代码
    :ivar side: 交易方向
    :ivar quantity: 成交数量
    :ivar price: 成交价格
    :ivar commission: 手续费
    :ivar timestamp: Unix 时间戳 (纳秒)
    """

    id: str
    order_id: str
    symbol: str
    side: akquant.OrderSide
    timestamp: int
    bar_index: int
    quantity: float
    price: float
    commission: float
    owner_strategy_id: typing.Optional[str]
    def __new__(
        cls,
        id: str,
        order_id: str,
        symbol: str,
        side: akquant.OrderSide,
        quantity: typing.Any,
        price: typing.Any,
        commission: typing.Any,
        timestamp: int,
        bar_index: int,
        owner_strategy_id: typing.Optional[str] = ...,
    ) -> "Trade": ...
    def __repr__(self) -> str: ...

class TradePnL:
    r"""
    交易盈亏统计 (FIFO).

    :ivar gross_pnl: 总毛利 (扣除佣金前)
    :ivar net_pnl: 总净利 (扣除佣金后)
    :ivar total_commission: 总佣金
    :ivar total_closed_trades: 总平仓交易次数
    :ivar won_count: 盈利次数
    :ivar lost_count: 亏损次数
    :ivar won_pnl: 盈利总额
    :ivar lost_pnl: 亏损总额
    :ivar win_rate: 胜率 (0.0-1.0)
    :ivar loss_rate: 亏损率 (0.0-1.0)
    :ivar unrealized_pnl: 未实现盈亏
    :ivar avg_pnl: 平均单笔盈亏
    :ivar avg_return_pct: 平均单笔收益率 (%)
    :ivar avg_trade_bars: 平均持仓 K 线数
    :ivar avg_profit: 平均单笔盈利
    :ivar avg_profit_pct: 平均单笔盈利百分比
    :ivar avg_winning_trade_bars: 平均盈利交易持仓 K 线数
    :ivar avg_loss: 平均单笔亏损
    :ivar avg_loss_pct: 平均单笔亏损百分比
    :ivar avg_losing_trade_bars: 平均亏损交易持仓 K 线数
    :ivar largest_win: 最大单笔盈利
    :ivar largest_win_pct: 最大单笔盈利百分比
    :ivar largest_win_bars: 最大单笔盈利持仓 K 线数
    :ivar largest_loss: 最大单笔亏损
    :ivar largest_loss_pct: 最大单笔亏损百分比
    :ivar largest_loss_bars: 最大单笔亏损持仓 K 线数
    :ivar max_wins: 最大连胜次数
    :ivar max_losses: 最大连败次数
    :ivar profit_factor: 盈亏比
    :ivar total_profit: 总盈利 (同 won_pnl)
    :ivar total_loss: 总亏损 (同 lost_pnl)
    :ivar sqn: 系统质量数 (System Quality Number)
    :ivar kelly_criterion: 凯利公式比例
    """

    gross_pnl: float
    net_pnl: float
    total_commission: float
    total_closed_trades: int
    won_count: int
    lost_count: int
    won_pnl: float
    lost_pnl: float
    win_rate: float
    loss_rate: float
    unrealized_pnl: float
    avg_pnl: float
    avg_return_pct: float
    avg_trade_bars: float
    avg_profit: float
    avg_profit_pct: float
    avg_winning_trade_bars: float
    avg_loss: float
    avg_loss_pct: float
    avg_losing_trade_bars: float
    largest_win: float
    largest_win_pct: float
    largest_win_bars: float
    largest_loss: float
    largest_loss_pct: float
    largest_loss_bars: float
    max_wins: int
    max_losses: int
    profit_factor: float
    total_profit: float
    total_loss: float
    sqn: float
    kelly_criterion: float
    def __repr__(self) -> str: ...

def from_arrays(
    timestamps: typing.Any,
    opens: typing.Any,
    highs: typing.Any,
    lows: typing.Any,
    closes: typing.Any,
    volumes: typing.Any,
    symbol: typing.Optional[str],
    symbols: typing.Optional[typing.Sequence[str]],
    extra: typing.Optional[typing.Mapping[str, typing.Any]],
) -> list[Bar]:
    r"""
    从数组批量创建 Bar 列表 (Python 优化用 - Zero Copy).

    :param timestamps: 时间戳数组
    :param opens: 开盘价数组
    :param highs: 最高价数组
    :param lows: 最低价数组
    :param closes: 收盘价数组
    :param volumes: 成交量数组
    :param symbol: 标的代码 (可选)
    :param symbols: 标的代码数组 (可选)
    :param extra: 额外数据 (可选)
    """
    ...
