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

import datetime
import decimal
import typing

import pandas as pd

from nautilus_trader import common
from nautilus_trader import core
from nautilus_trader import data
from nautilus_trader import execution
from nautilus_trader import model
from nautilus_trader import persistence
from nautilus_trader import portfolio
from nautilus_trader import risk
from nautilus_trader import trading

__all__ = [
    "AccountAdjustmentOutcome",
    "BacktestDataConfig",
    "BacktestEngine",
    "BacktestEngineConfig",
    "BacktestNode",
    "BacktestResult",
    "BacktestRunConfig",
    "BacktestVenueConfig",
    "CfdSwapModule",
    "CfdSwapRate",
    "FXRolloverInterestModule",
    "InterestRateRecord",
    "SimulationModule",
    "SimulationModuleContext",
]

@typing.final
class AccountAdjustmentOutcome:
    @property
    def applied(self) -> bool: ...
    @property
    def error(self) -> str | None: ...

@typing.final
class BacktestDataConfig:
    @property
    def data_type(self) -> str: ...
    @property
    def catalog_path(self) -> str: ...
    @property
    def instrument_id(self) -> model.InstrumentId | None: ...
    @property
    def catalog_fs_protocol(self) -> str | None: ...
    @property
    def catalog_fs_storage_option_keys(self) -> list[str] | None: ...
    @property
    def catalog_fs_rust_storage_option_keys(self) -> list[str] | None: ...
    @property
    def instrument_ids(self) -> list[model.InstrumentId] | None: ...
    @property
    def start_time(self) -> int | None: ...
    @property
    def end_time(self) -> int | None: ...
    @property
    def filter_expr(self) -> str | None: ...
    @property
    def client_id(self) -> model.ClientId | None: ...
    @property
    def metadata(self) -> dict[str, str] | None: ...
    @property
    def bar_spec(self) -> model.BarSpecification | None: ...
    @property
    def bar_types(self) -> list[str] | None: ...
    @property
    def optimize_file_loading(self) -> bool: ...
    def __new__(
        cls,
        data_type: str,
        catalog_path: str,
        catalog_fs_protocol: str | None = None,
        catalog_fs_storage_options: typing.Mapping[str, str] | None = None,
        catalog_fs_rust_storage_options: typing.Mapping[str, str] | None = None,
        instrument_id: model.InstrumentId | None = None,
        instrument_ids: typing.Sequence[model.InstrumentId] | None = None,
        start_time: int | str | datetime.datetime | pd.Timestamp | None = None,
        end_time: int | str | datetime.datetime | pd.Timestamp | None = None,
        filter_expr: str | None = None,
        client_id: model.ClientId | None = None,
        metadata: typing.Mapping[str, str] | None = None,
        bar_spec: model.BarSpecification | None = None,
        bar_types: typing.Sequence[str] | None = None,
        optimize_file_loading: bool | None = None,
    ) -> BacktestDataConfig: ...

@typing.final
class BacktestEngineConfig:
    @property
    def trader_id(self) -> model.TraderId: ...
    @property
    def load_state(self) -> bool: ...
    @property
    def save_state(self) -> bool: ...
    @property
    def shutdown_on_error(self) -> bool: ...
    @property
    def bypass_logging(self) -> bool: ...
    @property
    def run_analysis(self) -> bool: ...
    @property
    def timeout_connection(self) -> float: ...
    @property
    def timeout_reconciliation(self) -> float: ...
    @property
    def timeout_portfolio(self) -> float: ...
    @property
    def timeout_disconnection(self) -> float: ...
    @property
    def delay_post_stop(self) -> float: ...
    @property
    def timeout_shutdown(self) -> float: ...
    @property
    def logging(self) -> common.LoggerConfig: ...
    @property
    def instance_id(self) -> core.UUID4 | None: ...
    @property
    def cache(self) -> common.CacheConfig | None: ...
    @property
    def msgbus(self) -> common.MessageBusConfig | None: ...
    @property
    def data_engine(self) -> data.DataEngineConfig | None: ...
    @property
    def risk_engine(self) -> risk.RiskEngineConfig | None: ...
    @property
    def exec_engine(self) -> execution.ExecutionEngineConfig | None: ...
    @property
    def portfolio(self) -> portfolio.PortfolioConfig | None: ...
    @property
    def controller(self) -> trading.ImportableControllerConfig | None: ...
    @property
    def streaming(self) -> persistence.StreamingConfig | None: ...
    @property
    def catalogs(self) -> list[persistence.DataCatalogConfig]: ...
    def __new__(
        cls,
        trader_id: model.TraderId | None = None,
        load_state: bool | None = None,
        save_state: bool | None = None,
        shutdown_on_error: bool | None = None,
        bypass_logging: bool | None = None,
        run_analysis: bool | None = None,
        timeout_connection: int | None = None,
        timeout_reconciliation: int | None = None,
        timeout_portfolio: int | None = None,
        timeout_disconnection: int | None = None,
        delay_post_stop: int | None = None,
        timeout_shutdown: int | None = None,
        logging: common.LoggerConfig | None = None,
        instance_id: core.UUID4 | None = None,
        cache: common.CacheConfig | None = None,
        msgbus: common.MessageBusConfig | None = None,
        data_engine: data.DataEngineConfig | None = None,
        risk_engine: risk.RiskEngineConfig | None = None,
        exec_engine: execution.ExecutionEngineConfig | None = None,
        portfolio: portfolio.PortfolioConfig | None = None,
        controller: trading.ImportableControllerConfig | None = None,
        streaming: persistence.StreamingConfig | None = None,
        catalogs: typing.Sequence[persistence.DataCatalogConfig] | None = None,
    ) -> BacktestEngineConfig: ...

@typing.final
class BacktestNode:
    @property
    def configs(self) -> list[BacktestRunConfig]: ...
    def __new__(cls, configs: typing.Sequence[BacktestRunConfig]) -> BacktestNode: ...
    def build(self) -> None: ...
    def run(self) -> list[BacktestResult]: ...
    def dispose(self) -> None: ...
    def get_engine_cache(self, run_config_id: str) -> common.Cache: ...
    def get_engine_portfolio(self, run_config_id: str) -> portfolio.Portfolio: ...
    def generate_orders_report(self, run_config_id: str) -> typing.Any: ...
    def generate_order_fills_report(self, run_config_id: str) -> typing.Any: ...
    def generate_fills_report(self, run_config_id: str) -> typing.Any: ...
    def generate_positions_report(self, run_config_id: str) -> typing.Any: ...
    def generate_account_report(
        self,
        run_config_id: str,
        venue: model.Venue | None = None,
        account_id: model.AccountId | None = None,
    ) -> typing.Any: ...
    def add_actor(self, run_config_id: str, actor: typing.Any) -> None: ...
    def add_actor_from_config(
        self, run_config_id: str, config: common.ImportableActorConfig
    ) -> None: ...
    def add_strategy(self, run_config_id: str, strategy: typing.Any) -> None: ...
    def add_strategy_from_config(
        self, run_config_id: str, config: trading.ImportableStrategyConfig
    ) -> None: ...
    def add_exec_algorithm(self, run_config_id: str, exec_algorithm: typing.Any) -> None: ...
    def add_exec_algorithm_from_config(
        self, run_config_id: str, config: trading.ImportableExecutionAlgorithmConfig
    ) -> None: ...
    def add_builtin_strategy(
        self, run_config_id: str, type_name: str, config: typing.Any
    ) -> None: ...

@typing.final
class BacktestResult:
    @property
    def trader_id(self) -> str: ...
    @property
    def machine_id(self) -> str: ...
    @property
    def instance_id(self) -> core.UUID4: ...
    @property
    def run_config_id(self) -> str | None: ...
    @property
    def run_id(self) -> core.UUID4 | None: ...
    @property
    def run_started(self) -> int | None: ...
    @property
    def run_finished(self) -> int | None: ...
    @property
    def backtest_start(self) -> int | None: ...
    @property
    def backtest_end(self) -> int | None: ...
    @property
    def elapsed_time_secs(self) -> float: ...
    @property
    def iterations(self) -> int: ...
    @property
    def total_events(self) -> int: ...
    @property
    def total_orders(self) -> int: ...
    @property
    def total_positions(self) -> int: ...
    @property
    def summary(self) -> dict[str, str]: ...
    @property
    def stats_pnls(self) -> dict[str, dict[str, float]]: ...
    @property
    def stats_returns(self) -> dict[str, float]: ...
    @property
    def stats_general(self) -> dict[str, float]: ...
    @property
    def returns_series(self) -> dict[int, float]: ...

@typing.final
class BacktestRunConfig:
    @property
    def id(self) -> str: ...
    @property
    def venues(self) -> list[BacktestVenueConfig]: ...
    @property
    def data(self) -> list[BacktestDataConfig]: ...
    @property
    def engine(self) -> BacktestEngineConfig: ...
    @property
    def chunk_size(self) -> int | None: ...
    @property
    def raise_exception(self) -> bool: ...
    @property
    def dispose_on_completion(self) -> bool: ...
    @property
    def start(self) -> int | None: ...
    @property
    def end(self) -> int | None: ...
    def __new__(
        cls,
        venues: typing.Sequence[BacktestVenueConfig],
        data: typing.Sequence[BacktestDataConfig],
        engine: BacktestEngineConfig | None = None,
        id: str | None = None,
        chunk_size: int | None = None,
        raise_exception: bool | None = None,
        dispose_on_completion: bool | None = None,
        start: int | str | datetime.datetime | pd.Timestamp | None = None,
        end: int | str | datetime.datetime | pd.Timestamp | None = None,
    ) -> BacktestRunConfig: ...

@typing.final
class BacktestVenueConfig:
    @property
    def name(self) -> str: ...
    @property
    def oms_type(self) -> model.OmsType: ...
    @property
    def account_type(self) -> model.AccountType: ...
    @property
    def book_type(self) -> model.BookType: ...
    @property
    def starting_balances(self) -> list[str]: ...
    @property
    def routing(self) -> bool: ...
    @property
    def frozen_account(self) -> bool: ...
    @property
    def reject_stop_orders(self) -> bool: ...
    @property
    def support_gtd_orders(self) -> bool: ...
    @property
    def support_contingent_orders(self) -> bool: ...
    @property
    def use_position_ids(self) -> bool: ...
    @property
    def use_random_ids(self) -> bool: ...
    @property
    def use_reduce_only(self) -> bool: ...
    @property
    def bar_execution(self) -> bool: ...
    @property
    def trade_execution(self) -> bool: ...
    @property
    def bar_adaptive_high_low_ordering(self) -> bool: ...
    @property
    def use_market_order_acks(self) -> bool: ...
    @property
    def liquidity_consumption(self) -> bool: ...
    @property
    def allow_cash_borrowing(self) -> bool: ...
    @property
    def queue_position(self) -> bool: ...
    @property
    def oto_trigger_mode(self) -> model.OtoTriggerMode: ...
    @property
    def base_currency(self) -> model.Currency | None: ...
    @property
    def default_leverage(self) -> decimal.Decimal | None: ...
    @property
    def leverages(self) -> dict[model.InstrumentId, decimal.Decimal] | None: ...
    @property
    def margin_model(self) -> typing.Any | None: ...
    @property
    def modules(self) -> list[typing.Any]: ...
    @property
    def fill_model(self) -> typing.Any | None: ...
    @property
    def latency_model(self) -> typing.Any | None: ...
    @property
    def fee_model(self) -> typing.Any | None: ...
    @property
    def price_protection_points(self) -> int: ...
    @property
    def liquidation_enabled(self) -> bool: ...
    @property
    def liquidation_trigger_ratio(self) -> float: ...
    @property
    def liquidation_cancel_open_orders(self) -> bool: ...
    def __new__(
        cls,
        name: str,
        oms_type: model.OmsType | str,
        account_type: model.AccountType | str,
        starting_balances: typing.Sequence[str],
        book_type: model.BookType | str | None = None,
        routing: bool | None = None,
        frozen_account: bool | None = None,
        reject_stop_orders: bool | None = None,
        support_gtd_orders: bool | None = None,
        support_contingent_orders: bool | None = None,
        use_position_ids: bool | None = None,
        use_random_ids: bool | None = None,
        use_reduce_only: bool | None = None,
        bar_execution: bool | None = None,
        bar_adaptive_high_low_ordering: bool | None = None,
        trade_execution: bool | None = None,
        use_market_order_acks: bool | None = None,
        liquidity_consumption: bool | None = None,
        allow_cash_borrowing: bool | None = None,
        queue_position: bool | None = None,
        oto_trigger_mode: model.OtoTriggerMode | str | None = None,
        base_currency: model.Currency | None = None,
        default_leverage: decimal.Decimal | None = None,
        leverages: typing.Mapping[model.InstrumentId, decimal.Decimal] | None = None,
        margin_model: typing.Any | None = None,
        modules: typing.Sequence[typing.Any] | None = None,
        fill_model: typing.Any | None = None,
        latency_model: typing.Any | None = None,
        fee_model: typing.Any | None = None,
        price_protection_points: int | None = None,
        liquidation_enabled: bool | None = None,
        liquidation_trigger_ratio: float | None = None,
        liquidation_cancel_open_orders: bool | None = None,
    ) -> BacktestVenueConfig: ...

@typing.final
class CfdSwapModule(SimulationModule):
    def __new__(
        cls,
        rates: typing.Sequence[CfdSwapRate],
        rollover_hour: int = ...,
        rollover_minute: int = ...,
        triple_roll_weekday: int = ...,
    ) -> typing.Self: ...

@typing.final
class CfdSwapRate:
    @property
    def instrument_id(self) -> model.InstrumentId: ...
    @property
    def long_rate(self) -> decimal.Decimal: ...
    @property
    def short_rate(self) -> decimal.Decimal: ...
    def __new__(
        cls,
        instrument_id: model.InstrumentId,
        long_rate: decimal.Decimal,
        short_rate: decimal.Decimal,
    ) -> CfdSwapRate: ...

@typing.final
class FXRolloverInterestModule(SimulationModule):
    def __new__(cls, records: typing.Sequence[InterestRateRecord]) -> typing.Self: ...

@typing.final
class InterestRateRecord:
    def __new__(cls, location: str, time: str, value: float) -> InterestRateRecord: ...

@typing.final
class BacktestEngine:
    @property
    def trader_id(self) -> model.TraderId: ...
    @property
    def machine_id(self) -> str: ...
    @property
    def instance_id(self) -> core.UUID4: ...
    @property
    def iteration(self) -> int: ...
    @property
    def run_config_id(self) -> str | None: ...
    @property
    def run_id(self) -> core.UUID4 | None: ...
    @property
    def run_started(self) -> int | None: ...
    @property
    def run_finished(self) -> int | None: ...
    @property
    def backtest_start(self) -> int | None: ...
    @property
    def backtest_end(self) -> int | None: ...
    @property
    def cache(self) -> common.Cache: ...
    @property
    def portfolio(self) -> portfolio.Portfolio: ...
    def add_defi_data(
        self,
        data: typing.Sequence[model.DefiData],
        client_id: model.ClientId | None = None,
        sort: bool = True,
    ) -> None: ...
    def __new__(cls, config: BacktestEngineConfig) -> BacktestEngine: ...
    def add_venue(
        self,
        venue: model.Venue,
        oms_type: model.OmsType,
        account_type: model.AccountType,
        starting_balances: typing.Sequence[model.Money],
        base_currency: model.Currency | None = None,
        default_leverage: decimal.Decimal | None = None,
        leverages: typing.Mapping[model.InstrumentId, decimal.Decimal] | None = None,
        margin_model: typing.Any | None = None,
        fill_model: typing.Any | None = None,
        fee_model: typing.Any | None = None,
        latency_model: typing.Any | None = None,
        modules: typing.Sequence[typing.Any] | None = None,
        book_type: model.BookType = model.BookType.L1_MBP,
        routing: bool = False,
        reject_stop_orders: bool = True,
        support_gtd_orders: bool = True,
        support_contingent_orders: bool = True,
        use_position_ids: bool = True,
        use_random_ids: bool = False,
        use_reduce_only: bool = True,
        use_message_queue: bool = True,
        use_market_order_acks: bool = False,
        bar_execution: bool = True,
        bar_adaptive_high_low_ordering: bool = False,
        trade_execution: bool = True,
        liquidity_consumption: bool = False,
        queue_position: bool = False,
        allow_cash_borrowing: bool = False,
        frozen_account: bool = False,
        oto_trigger_mode: model.OtoTriggerMode = model.OtoTriggerMode.PARTIAL,
        price_protection_points: int | None = None,
        liquidation_enabled: bool = False,
        liquidation_trigger_ratio: float | None = None,
        liquidation_cancel_open_orders: bool = True,
    ) -> None: ...
    def change_fill_model(self, venue: model.Venue, fill_model: typing.Any) -> None: ...
    def add_data(
        self,
        data: typing.Sequence[typing.Any],
        client_id: model.ClientId | None = None,
        validate: bool = True,
        sort: bool = True,
    ) -> None: ...
    def add_instrument(self, instrument: typing.Any) -> None: ...
    def add_actor(self, actor: typing.Any) -> None: ...
    def add_actor_from_config(self, config: common.ImportableActorConfig) -> None: ...
    def add_strategy(self, strategy: typing.Any) -> None: ...
    def add_strategy_from_config(self, config: trading.ImportableStrategyConfig) -> None: ...
    def add_exec_algorithm(self, exec_algorithm: typing.Any) -> None: ...
    def add_exec_algorithm_from_config(
        self, config: trading.ImportableExecutionAlgorithmConfig
    ) -> None: ...
    def add_builtin_actor(self, type_name: str, config: typing.Any) -> None: ...
    def add_builtin_strategy(self, type_name: str, config: typing.Any) -> None: ...
    def add_native_exec_algorithm(self, type_name: str, config: typing.Any) -> None: ...
    def run(
        self,
        start: int | None = None,
        end: int | None = None,
        run_config_id: str | None = None,
        streaming: bool = False,
    ) -> None: ...
    def end(self) -> None: ...
    def reset(self) -> None: ...
    def dispose(self) -> None: ...
    def get_result(self) -> BacktestResult: ...
    def clear_data(self) -> None: ...
    def clear_actors(self) -> None: ...
    def clear_strategies(self) -> None: ...
    def clear_exec_algorithms(self) -> None: ...
    def add_actors_from_configs(
        self, configs: typing.Sequence[common.ImportableActorConfig]
    ) -> None: ...
    def add_strategies_from_configs(
        self, configs: typing.Sequence[trading.ImportableStrategyConfig]
    ) -> None: ...
    def add_exec_algorithms_from_configs(
        self, configs: typing.Sequence[trading.ImportableExecutionAlgorithmConfig]
    ) -> None: ...
    def add_actors(self, actors: typing.Sequence[typing.Any]) -> None: ...
    def add_strategies(self, strategies: typing.Sequence[typing.Any]) -> None: ...
    def add_exec_algorithms(self, exec_algorithms: typing.Sequence[typing.Any]) -> None: ...
    def sort_data(self) -> None: ...
    def list_venues(self) -> list[model.Venue]: ...
    def generate_orders_report(self) -> typing.Any: ...
    def generate_order_fills_report(self) -> typing.Any: ...
    def generate_fills_report(self) -> typing.Any: ...
    def generate_positions_report(self) -> typing.Any: ...
    def generate_account_report(
        self, venue: model.Venue | None = None, account_id: model.AccountId | None = None
    ) -> typing.Any: ...

class SimulationModule:
    def __new__(cls, *_args: typing.Any, **_kwargs: typing.Any) -> typing.Self: ...
    def pre_process(self, _data: typing.Any) -> None: ...
    def process(
        self, _ts_now: int, _context: SimulationModuleContext
    ) -> list[model.Money] | None: ...
    def acknowledge(self, _outcomes: typing.Any) -> None: ...
    def log_diagnostics(self) -> None: ...
    def reset(self) -> None: ...

@typing.final
class SimulationModuleContext:
    @property
    def venue(self) -> model.Venue: ...
    @property
    def base_currency(self) -> model.Currency | None: ...
    @property
    def instruments(self) -> list[typing.Any]: ...
    @property
    def order_books(self) -> list[model.OrderBook]: ...
    @property
    def positions(self) -> list[model.Position]: ...
