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

import datetime
import enum
import typing

from nautilus_trader import model

__all__ = [
    "ContainerStatus",
    "DockerizedIBGateway",
    "DockerizedIBGatewayConfig",
    "HistoricalInteractiveBrokersClient",
    "InteractiveBrokersDataClientConfig",
    "InteractiveBrokersDataClientFactory",
    "InteractiveBrokersExecutionClientConfig",
    "InteractiveBrokersExecutionClientFactory",
    "InteractiveBrokersInstrumentProvider",
    "InteractiveBrokersInstrumentProviderConfig",
]

@typing.final
class DockerizedIBGateway:
    def __init__(self, config: DockerizedIBGatewayConfig) -> None: ...
    @property
    def container_name(self) -> str: ...
    @property
    def host(self) -> str: ...
    @property
    def port(self) -> int: ...
    def start(self, wait: int | None = ...) -> typing.Any: ...
    def start_blocking(self, wait: int | None = ...) -> None: ...
    def safe_start(self, wait: int | None = ...) -> typing.Any: ...
    def safe_start_blocking(self, wait: int | None = ...) -> None: ...
    def stop(self) -> typing.Any: ...
    def stop_blocking(self) -> None: ...
    def container_status(self) -> typing.Any: ...

class DockerizedIBGatewayConfig:
    def __init__(
        self,
        username: str | None = None,
        password: str | None = None,
        trading_mode: TradingMode | None = None,
        read_only_api: bool | None = None,
        timeout: int | None = None,
        container_image: str | None = None,
        vnc_port: int | None = None,
    ) -> None: ...
    @property
    def username(self) -> str | None: ...
    @property
    def has_password(self) -> bool: ...
    @property
    def trading_mode(self) -> TradingMode: ...
    @property
    def read_only_api(self) -> bool: ...
    @property
    def timeout(self) -> int: ...
    @property
    def container_image(self) -> str: ...
    @property
    def vnc_port(self) -> int | None: ...

class HistoricalInteractiveBrokersClient:
    def __init__(
        self,
        instrument_provider: InteractiveBrokersInstrumentProvider,
        config: InteractiveBrokersDataClientConfig,
    ) -> None: ...
    def request_bars(
        self,
        bar_specifications: typing.Sequence[str],
        end_date_time: datetime.datetime,
        start_date_time: datetime.datetime | None = None,
        duration: str | None = None,
        contracts: list | None = None,
        instrument_ids: typing.Sequence[model.InstrumentId] | None = None,
        use_rth: bool = True,
        timeout: int = 60,
    ) -> typing.Any: ...
    def request_ticks(
        self,
        tick_type: IbHistoricalTickType,
        start_date_time: datetime.datetime,
        end_date_time: datetime.datetime,
        contracts: list | None = None,
        instrument_ids: typing.Sequence[model.InstrumentId] | None = None,
        use_rth: bool = True,
        timeout: int = 60,
        limit: int = 0,
    ) -> typing.Any: ...
    def request_instruments(
        self,
        instrument_ids: typing.Sequence[model.InstrumentId] | None = None,
        contracts: list | None = None,
    ) -> typing.Any: ...

class InteractiveBrokersDataClientConfig:
    def __init__(
        self,
        host: str | None = None,
        port: int | None = None,
        client_id: int | None = None,
        use_regular_trading_hours: bool | None = None,
        market_data_type: MarketDataType | None = None,
        ignore_quote_tick_size_updates: bool | None = None,
        connection_timeout: int | None = None,
        request_timeout: int | None = None,
        handle_revised_bars: bool | None = None,
        batch_quotes: bool | None = None,
        instrument_provider: InteractiveBrokersInstrumentProviderConfig | None = None,
        dockerized_gateway: DockerizedIBGatewayConfig | None = None,
    ) -> None: ...
    @property
    def host(self) -> str: ...
    @property
    def port(self) -> int: ...
    @property
    def client_id(self) -> int: ...
    @property
    def use_regular_trading_hours(self) -> bool: ...
    @property
    def market_data_type(self) -> MarketDataType: ...
    @property
    def ignore_quote_tick_size_updates(self) -> bool: ...
    @property
    def connection_timeout(self) -> int: ...
    @property
    def request_timeout(self) -> int: ...
    @property
    def handle_revised_bars(self) -> bool: ...
    @property
    def batch_quotes(self) -> bool: ...
    @property
    def instrument_provider(self) -> InteractiveBrokersInstrumentProviderConfig: ...
    @instrument_provider.setter
    def instrument_provider(
        self, instrument_provider: InteractiveBrokersInstrumentProviderConfig
    ) -> None: ...

@typing.final
class InteractiveBrokersDataClientFactory:
    def __init__(self) -> None: ...
    def name(self) -> str: ...

class InteractiveBrokersExecutionClientConfig:
    def __init__(
        self,
        host: str | None = None,
        port: int | None = None,
        client_id: int | None = None,
        account_id: str | None = None,
        connection_timeout: int | None = None,
        request_timeout: int | None = None,
        fetch_all_open_orders: bool | None = None,
        track_option_exercise_from_position_update: bool | None = None,
        instrument_provider: InteractiveBrokersInstrumentProviderConfig | None = None,
        dockerized_gateway: DockerizedIBGatewayConfig | None = None,
    ) -> None: ...
    @property
    def host(self) -> str: ...
    @property
    def port(self) -> int: ...
    @property
    def client_id(self) -> int: ...
    @property
    def account_id(self) -> str | None: ...
    @property
    def connection_timeout(self) -> int: ...
    @property
    def request_timeout(self) -> int: ...
    @property
    def fetch_all_open_orders(self) -> bool: ...
    @property
    def track_option_exercise_from_position_update(self) -> bool: ...
    @property
    def instrument_provider(self) -> InteractiveBrokersInstrumentProviderConfig: ...
    @instrument_provider.setter
    def instrument_provider(
        self, instrument_provider: InteractiveBrokersInstrumentProviderConfig
    ) -> None: ...

@typing.final
class InteractiveBrokersExecutionClientFactory:
    def __init__(self) -> None: ...
    def name(self) -> str: ...

@typing.final
class InteractiveBrokersInstrumentProvider:
    def __init__(self, config: InteractiveBrokersInstrumentProviderConfig) -> None: ...
    def find(self, instrument_id: model.InstrumentId) -> typing.Any | None: ...
    def find_by_contract_id(self, contract_id: int) -> typing.Any | None: ...
    def get_all(self) -> list: ...
    def count(self) -> int: ...
    def get_price_magnifier(self, instrument_id: model.InstrumentId) -> int: ...
    def fetch_contract_details(self) -> None: ...
    def determine_venue(self, contract: typing.Any) -> str: ...
    def instrument_id_to_ib_contract_details(
        self, instrument_id: model.InstrumentId
    ) -> typing.Any | None: ...
    def save_cache(self, cache_path: str) -> typing.Any: ...
    def load_cache(self, cache_path: str) -> typing.Any: ...

class InteractiveBrokersInstrumentProviderConfig:
    def __init__(
        self,
        symbology_method: SymbologyMethod | None = None,
        load_ids: set[model.InstrumentId] | None = None,
        load_contracts: list | None = None,
        min_expiry_days: int | None = None,
        max_expiry_days: int | None = None,
        build_options_chain: bool | None = None,
        build_futures_chain: bool | None = None,
        cache_validity_days: int | None = None,
        convert_exchange_to_mic_venue: bool | None = None,
        symbol_to_mic_venue: typing.Mapping[str, str] | None = None,
        filter_sec_types: set[str] | None = None,
        filter_callable: str | None = None,
        cache_path: str | None = None,
    ) -> None: ...
    @property
    def symbology_method(self) -> SymbologyMethod: ...
    @property
    def load_ids(self) -> set[model.InstrumentId]: ...
    @property
    def load_contracts(self) -> list: ...
    @property
    def min_expiry_days(self) -> int | None: ...
    @property
    def max_expiry_days(self) -> int | None: ...
    @property
    def build_options_chain(self) -> bool | None: ...
    @property
    def build_futures_chain(self) -> bool | None: ...
    @property
    def cache_validity_days(self) -> int | None: ...
    @property
    def convert_exchange_to_mic_venue(self) -> bool: ...
    @property
    def symbol_to_mic_venue(self) -> dict[str, str]: ...
    @property
    def filter_sec_types(self) -> list[str]: ...
    @property
    def filter_callable(self) -> str | None: ...
    @property
    def cache_path(self) -> str | None: ...
    @cache_path.setter
    def cache_path(self, cache_path: str | None) -> None: ...

@typing.final
class ContainerStatus(enum.Enum):
    NO_CONTAINER = ...
    CONTAINER_CREATED = ...
    CONTAINER_STARTING = ...
    CONTAINER_STOPPED = ...
    NOT_LOGGED_IN = ...
    READY = ...
    UNKNOWN = ...

@typing.final
class ErrorCategory(enum.Enum):
    CLIENT_ERROR = ...
    CONNECTIVITY_ERROR = ...
    SUBSCRIPTION_ERROR = ...
    ORDER_ERROR = ...
    MARKET_DATA_ERROR = ...
    UNKNOWN = ...

    def as_str(self) -> str: ...

@typing.final
class IbAction(enum.Enum):
    BUY = ...
    BOUGHT = ...
    SELL = ...
    SOLD = ...
    SELL_SHORT = ...
    SELL_LONG = ...

    def as_str(self) -> str: ...

@typing.final
class IbArticleType(enum.Enum):
    TEXT = ...
    BINARY = ...

    def as_i32(self) -> int: ...

@typing.final
class IbAuctionStrategy(enum.Enum):
    MATCH = ...
    IMPROVEMENT = ...
    TRANSPARENT = ...

    def as_i32(self) -> int: ...

@typing.final
class IbAuctionType(enum.Enum):
    OPENING = ...
    CLOSING = ...
    VOLATILITY = ...

    def as_i32(self) -> int: ...

@typing.final
class IbBondIdentifierKind(enum.Enum):
    CUSIP = ...
    ISIN = ...

    def as_str(self) -> str: ...

@typing.final
class IbBuilderTimeInForce(enum.Enum):
    DAY = ...
    GOOD_TILL_CANCEL = ...
    IMMEDIATE_OR_CANCEL = ...
    GOOD_TILL_DATE = ...
    FILL_OR_KILL = ...
    GOOD_TILL_CROSSING = ...
    DAY_TILL_CANCELED = ...
    AUCTION = ...
    OPENING_AUCTION = ...

    def as_str(self) -> str: ...

@typing.final
class IbComboLegOpenClose(enum.Enum):
    SAME = ...
    OPEN = ...
    CLOSE = ...
    UNKNOWN = ...

    def as_i32(self) -> int: ...

@typing.final
class IbConditionConjunction(enum.Enum):
    AND = ...
    OR = ...

    def as_str(self) -> str: ...
    def is_conjunction(self) -> bool: ...

@typing.final
class IbConditionKind(enum.Enum):
    PRICE = ...
    TIME = ...
    MARGIN = ...
    EXECUTION = ...
    VOLUME = ...
    PERCENT_CHANGE = ...

    def as_str(self) -> str: ...

@typing.final
class IbExerciseAction(enum.Enum):
    EXERCISE = ...
    LAPSE = ...

    def as_i32(self) -> int: ...

@typing.final
class IbFundAssetType(enum.Enum):
    NONE = ...
    OTHERS = ...
    MONEY_MARKET = ...
    FIXED_INCOME = ...
    MULTI_ASSET = ...
    EQUITY = ...
    SECTOR = ...
    GUARANTEED = ...
    ALTERNATIVE = ...

    def as_str(self) -> str: ...

@typing.final
class IbFundDistributionPolicyIndicator(enum.Enum):
    NONE = ...
    ACCUMULATION_FUND = ...
    INCOME_FUND = ...

    def as_str(self) -> str: ...

@typing.final
class IbHistoricalBarSize(enum.Enum):
    SEC = ...
    SEC5 = ...
    SEC10 = ...
    SEC15 = ...
    SEC30 = ...
    MIN = ...
    MIN2 = ...
    MIN3 = ...
    MIN5 = ...
    MIN10 = ...
    MIN15 = ...
    MIN20 = ...
    MIN30 = ...
    HOUR = ...
    HOUR2 = ...
    HOUR3 = ...
    HOUR4 = ...
    HOUR8 = ...
    DAY = ...
    WEEK = ...
    MONTH = ...

    def as_str(self) -> str: ...

@typing.final
class IbHistoricalTickType(enum.Enum):
    TRADES = ...
    BID_ASK = ...

    def as_str(self) -> str: ...

@typing.final
class IbHistoricalWhatToShow(enum.Enum):
    TRADES = ...
    MIDPOINT = ...
    BID = ...
    ASK = ...
    BID_ASK = ...
    HISTORICAL_VOLATILITY = ...
    OPTION_IMPLIED_VOLATILITY = ...
    FEE_RATE = ...
    SCHEDULE = ...
    ADJUSTED_LAST = ...

    def as_str(self) -> str: ...

@typing.final
class IbLegAction(enum.Enum):
    BUY = ...
    SELL = ...

    def as_str(self) -> str: ...

@typing.final
class IbLiquidity(enum.Enum):
    NONE = ...
    ADDED_LIQUIDITY = ...
    REMOVED_LIQUIDITY = ...
    LIQUIDITY_ROUTED_OUT = ...

    def as_i32(self) -> int: ...

@typing.final
class IbOcaType(enum.Enum):
    NONE = ...
    CANCEL_WITH_BLOCK = ...
    REDUCE_WITH_BLOCK = ...
    REDUCE_WITHOUT_BLOCK = ...

    def as_i32(self) -> int: ...

@typing.final
class IbOptionRight(enum.Enum):
    CALL = ...
    PUT = ...

    def as_str(self) -> str: ...

@typing.final
class IbOrderOpenClose(enum.Enum):
    OPEN = ...
    CLOSE = ...

    def as_str(self) -> str: ...

@typing.final
class IbOrderOrigin(enum.Enum):
    CUSTOMER = ...
    FIRM = ...

    def as_i32(self) -> int: ...

@typing.final
class IbOrderStatus(enum.Enum):
    API_PENDING = ...
    PENDING_SUBMIT = ...
    PRE_SUBMITTED = ...
    SUBMITTED = ...
    PENDING_CANCEL = ...
    API_CANCELLED = ...
    CANCELLED = ...
    FILLED = ...
    INACTIVE = ...

    def as_str(self) -> str: ...

@typing.final
class IbOrderType(enum.Enum):
    MARKET = ...
    MARKET_ON_CLOSE = ...
    LIMIT = ...
    LIMIT_ON_CLOSE = ...
    STOP = ...
    STOP_LIMIT = ...
    TRAILING_STOP = ...
    TRAILING_STOP_LIMIT = ...
    MARKET_IF_TOUCHED = ...
    LIMIT_IF_TOUCHED = ...
    MARKET_TO_LIMIT = ...
    MARKET_WITH_PROTECTION = ...
    STOP_WITH_PROTECTION = ...
    MIDPRICE = ...
    PEGGED_TO_MARKET = ...
    PEGGED_TO_STOCK = ...
    PEGGED_TO_MIDPOINT = ...
    PEGGED_TO_BENCHMARK = ...
    PEG_BEST = ...
    RELATIVE = ...
    PASSIVE_RELATIVE = ...
    VOLATILITY = ...
    BOX_TOP = ...
    RELATIVE_LIMIT_COMBO = ...
    RELATIVE_MARKET_COMBO = ...

    def as_str(self) -> str: ...

@typing.final
class IbRealtimeBarSize(enum.Enum):
    SEC5 = ...

    def as_str(self) -> str: ...

@typing.final
class IbRealtimeWhatToShow(enum.Enum):
    TRADES = ...
    MIDPOINT = ...
    BID = ...
    ASK = ...

    def as_str(self) -> str: ...

@typing.final
class IbReferencePriceType(enum.Enum):
    AVERAGE_OF_NBBO = ...
    NBBO = ...

    def as_i32(self) -> int: ...

@typing.final
class IbRiskAversion(enum.Enum):
    GET_DONE = ...
    AGGRESSIVE = ...
    NEUTRAL = ...
    PASSIVE = ...

    def as_str(self) -> str: ...

@typing.final
class IbRule80A(enum.Enum):
    INDIVIDUAL = ...
    AGENCY = ...
    AGENT_OTHER_MEMBER = ...
    INDIVIDUAL_PTIA = ...
    AGENCY_PTIA = ...
    AGENT_OTHER_MEMBER_PTIA = ...
    INDIVIDUAL_PT = ...
    AGENCY_PT = ...
    AGENT_OTHER_MEMBER_PT = ...

    def as_str(self) -> str: ...

@typing.final
class IbSecurityType(enum.Enum):
    STOCK = ...
    OPTION = ...
    FUTURE = ...
    CONTINUOUS_FUTURE = ...
    INDEX = ...
    FUTURES_OPTION = ...
    FOREX_PAIR = ...
    SPREAD = ...
    WARRANT = ...
    BOND = ...
    COMMODITY = ...
    NEWS = ...
    MUTUAL_FUND = ...
    CRYPTO = ...
    CFD = ...

    def as_str(self) -> str: ...

@typing.final
class IbShortSaleSlot(enum.Enum):
    NONE = ...
    BROKER = ...
    THIRD_PARTY = ...

    def as_i32(self) -> int: ...

@typing.final
class IbTickType(enum.Enum):
    UNKNOWN = ...
    BID_SIZE = ...
    BID = ...
    ASK = ...
    ASK_SIZE = ...
    LAST = ...
    LAST_SIZE = ...
    HIGH = ...
    LOW = ...
    VOLUME = ...
    CLOSE = ...
    BID_OPTION = ...
    ASK_OPTION = ...
    LAST_OPTION = ...
    MODEL_OPTION = ...
    OPEN = ...
    LOW13_WEEK = ...
    HIGH13_WEEK = ...
    LOW26_WEEK = ...
    HIGH26_WEEK = ...
    LOW52_WEEK = ...
    HIGH52_WEEK = ...
    AVG_VOLUME = ...
    OPEN_INTEREST = ...
    OPTION_HISTORICAL_VOL = ...
    OPTION_IMPLIED_VOL = ...
    OPTION_BID_EXCH = ...
    OPTION_ASK_EXCH = ...
    OPTION_CALL_OPEN_INTEREST = ...
    OPTION_PUT_OPEN_INTEREST = ...
    OPTION_CALL_VOLUME = ...
    OPTION_PUT_VOLUME = ...
    INDEX_FUTURE_PREMIUM = ...
    BID_EXCH = ...
    ASK_EXCH = ...
    AUCTION_VOLUME = ...
    AUCTION_PRICE = ...
    AUCTION_IMBALANCE = ...
    MARK_PRICE = ...
    BID_EFP_COMPUTATION = ...
    ASK_EFP_COMPUTATION = ...
    LAST_EFP_COMPUTATION = ...
    OPEN_EFP_COMPUTATION = ...
    HIGH_EFP_COMPUTATION = ...
    LOW_EFP_COMPUTATION = ...
    CLOSE_EFP_COMPUTATION = ...
    LAST_TIMESTAMP = ...
    SHORTABLE = ...
    FUNDAMENTAL_RATIOS = ...
    RT_VOLUME = ...
    HALTED = ...
    BID_YIELD = ...
    ASK_YIELD = ...
    LAST_YIELD = ...
    CUST_OPTION_COMPUTATION = ...
    TRADE_COUNT = ...
    TRADE_RATE = ...
    VOLUME_RATE = ...
    LAST_RTH_TRADE = ...
    RT_HISTORICAL_VOL = ...
    IB_DIVIDENDS = ...
    BOND_FACTOR_MULTIPLIER = ...
    REGULATORY_IMBALANCE = ...
    NEWS_TICK = ...
    SHORT_TERM_VOLUME3_MIN = ...
    SHORT_TERM_VOLUME5_MIN = ...
    SHORT_TERM_VOLUME10_MIN = ...
    DELAYED_BID = ...
    DELAYED_ASK = ...
    DELAYED_LAST = ...
    DELAYED_BID_SIZE = ...
    DELAYED_ASK_SIZE = ...
    DELAYED_LAST_SIZE = ...
    DELAYED_HIGH = ...
    DELAYED_LOW = ...
    DELAYED_VOLUME = ...
    DELAYED_CLOSE = ...
    DELAYED_OPEN = ...
    RT_TRD_VOLUME = ...
    CREDITMAN_MARK_PRICE = ...
    CREDITMAN_SLOW_MARK_PRICE = ...
    DELAYED_BID_OPTION = ...
    DELAYED_ASK_OPTION = ...
    DELAYED_LAST_OPTION = ...
    DELAYED_MODEL_OPTION = ...
    LAST_EXCH = ...
    LAST_REG_TIME = ...
    FUTURES_OPEN_INTEREST = ...
    AVG_OPT_VOLUME = ...
    DELAYED_LAST_TIMESTAMP = ...
    SHORTABLE_SHARES = ...
    DELAYED_HALTED = ...
    REUTERS2_MUTUAL_FUNDS = ...
    ETF_NAV_CLOSE = ...
    ETF_NAV_PRIOR_CLOSE = ...
    ETF_NAV_BID = ...
    ETF_NAV_ASK = ...
    ETF_NAV_LAST = ...
    ETF_FROZEN_NAV_LAST = ...
    ETF_NAV_HIGH = ...
    ETF_NAV_LOW = ...
    SOCIAL_MARKET_ANALYTICS = ...
    ESTIMATED_IPO_MIDPOINT = ...
    FINAL_IPO_LAST = ...
    DELAYED_YIELD_BID = ...
    DELAYED_YIELD_ASK = ...

    def as_i32(self) -> int: ...

@typing.final
class IbTimeInForce(enum.Enum):
    DAY = ...
    GOOD_TIL_CANCELED = ...
    IMMEDIATE_OR_CANCEL = ...
    GOOD_TIL_DATE = ...
    ON_OPEN = ...
    FILL_OR_KILL = ...
    DAY_TIL_CANCELED = ...
    AUCTION = ...

    def as_str(self) -> str: ...

@typing.final
class IbTradingHours(enum.Enum):
    REGULAR = ...
    EXTENDED = ...

    def use_rth(self) -> bool: ...

@typing.final
class IbTriggerMethod(enum.Enum):
    DEFAULT = ...
    DOUBLE_BID_ASK = ...
    LAST = ...
    DOUBLE_LAST = ...
    BID_ASK = ...
    LAST_OR_BID_ASK = ...
    MIDPOINT = ...

    def as_i32(self) -> int: ...

@typing.final
class IbTwapStrategyType(enum.Enum):
    MARKETABLE = ...
    MATCHING_MIDPOINT = ...
    MATCHING_SAME_SIDE = ...
    MATCHING_LAST = ...

    def as_str(self) -> str: ...

@typing.final
class IbVolatilityType(enum.Enum):
    DAILY = ...
    ANNUAL = ...

    def as_i32(self) -> int: ...

@typing.final
class InteractiveBrokersErrorKind(enum.Enum):
    CONNECTION = ...
    AUTHENTICATION = ...
    CONFIGURATION = ...
    REQUEST = ...
    PARSE = ...
    INSTRUMENT = ...
    ORDER = ...
    MARKET_DATA = ...
    IB_API = ...
    INTERNAL = ...

    def as_str(self) -> str: ...

@typing.final
class MarketDataType(enum.Enum):
    REALTIME = ...
    FROZEN = ...
    DELAYED = ...
    DELAYED_FROZEN = ...

@typing.final
class SymbologyMethod(enum.Enum):
    SIMPLIFIED = ...
    RAW = ...

@typing.final
class TradingMode(enum.Enum):
    PAPER = ...
    LIVE = ...
