pub struct InteractiveBrokersInstrumentProvider { /* private fields */ }Expand description
Interactive Brokers instrument provider.
This provider fetches contract details from Interactive Brokers using the rust-ibapi library
and converts them to NautilusTrader instruments.
Implementations§
Source§impl InteractiveBrokersInstrumentProvider
impl InteractiveBrokersInstrumentProvider
Sourcepub fn new(config: InteractiveBrokersInstrumentProviderConfig) -> Self
pub fn new(config: InteractiveBrokersInstrumentProviderConfig) -> Self
Create a new InteractiveBrokersInstrumentProvider.
Sourcepub async fn initialize(&self) -> Result<()>
pub async fn initialize(&self) -> Result<()>
Initialize the provider by loading cache if configured.
This is equivalent to Python’s provider.initialize() method.
It loads instruments from cache if cache_path is configured and cache is valid.
§Errors
Returns an error if cache loading fails.
Sourcepub async fn initialize_with_client(
&self,
client: &Client,
) -> Result<Vec<InstrumentId>>
pub async fn initialize_with_client( &self, client: &Client, ) -> Result<Vec<InstrumentId>>
Initializes the provider and resolves every configured startup input.
Successful initialization is idempotent. A failed attempt remains retryable.
§Errors
Returns an error if initialization fails or any configured input cannot be loaded.
Sourcepub fn add_cached_instruments<I>(&self, instruments: I) -> usizewhere
I: IntoIterator<Item = InstrumentAny>,
pub fn add_cached_instruments<I>(&self, instruments: I) -> usizewhere
I: IntoIterator<Item = InstrumentAny>,
Adds instruments already held by the Nautilus cache into the provider cache.
This mirrors the Python provider’s use of client._cache for venue resolution and for
recovering stored IB contract metadata from instrument.info["contract"].
Sourcepub fn determine_venue(
&self,
contract: &Contract,
contract_details: Option<&ContractDetails>,
) -> Venue
pub fn determine_venue( &self, contract: &Contract, contract_details: Option<&ContractDetails>, ) -> Venue
Determine venue from contract using provider configuration.
This is equivalent to Python’s determine_venue_from_contract method.
It uses the config’s symbol-to-venue mapping and exchange-to-venue conversion settings.
§Returns
The determined venue.
Sourcepub fn symbology_method(&self) -> SymbologyMethod
pub fn symbology_method(&self) -> SymbologyMethod
Get the symbology method from the provider configuration.
Sourcepub fn find_by_contract_id(&self, contract_id: i32) -> Option<InstrumentAny>
pub fn find_by_contract_id(&self, contract_id: i32) -> Option<InstrumentAny>
Sourcepub fn get_instrument_id_by_contract_id(
&self,
contract_id: i32,
) -> Option<InstrumentId>
pub fn get_instrument_id_by_contract_id( &self, contract_id: i32, ) -> Option<InstrumentId>
Sourcepub fn resolve_instrument_id_for_contract(
&self,
contract: &Contract,
) -> Result<InstrumentId>
pub fn resolve_instrument_id_for_contract( &self, contract: &Contract, ) -> Result<InstrumentId>
Resolve an instrument ID from an IB contract using provider symbology and venue rules.
This first checks the provider’s contract ID cache, then derives the instrument ID using the
configured symbology method and determine_venue.
§Errors
Returns an error if the contract cannot be converted to an instrument ID.
Sourcepub fn spread_instrument_id_for_contract(
&self,
contract: &Contract,
) -> Result<InstrumentId>
pub fn spread_instrument_id_for_contract( &self, contract: &Contract, ) -> Result<InstrumentId>
Returns the spread instrument ID of a BAG contract from its cached leg instruments.
§Errors
Returns an error if the contract has no combo legs, a leg is not cached, or a leg action is invalid.
Sourcepub fn is_filtered_sec_type(&self, sec_type: &str) -> bool
pub fn is_filtered_sec_type(&self, sec_type: &str) -> bool
Check if a security type should be filtered.
§Returns
Returns true if the security type should be filtered.
Sourcepub fn get_price_magnifier(&self, instrument_id: &InstrumentId) -> i32
pub fn get_price_magnifier(&self, instrument_id: &InstrumentId) -> i32
Get price magnifier for an instrument ID.
Price magnifier allows execution and strike prices to be reported consistently with market data and historical data.
This method first checks the dedicated price magnifier cache for fast lookup. If not found, it falls back to checking contract details. If still not found, it returns the default value of 1 and logs a warning if the instrument exists.
§Returns
Returns the price magnifier if found, otherwise 1.
Sourcepub async fn get_instrument(
&self,
client: &Client,
contract: &Contract,
) -> Result<Option<InstrumentAny>>
pub async fn get_instrument( &self, client: &Client, contract: &Contract, ) -> Result<Option<InstrumentAny>>
Sourcepub fn instrument_id_to_ib_contract_details(
&self,
instrument_id: &InstrumentId,
) -> Option<ContractDetails>
pub fn instrument_id_to_ib_contract_details( &self, instrument_id: &InstrumentId, ) -> Option<ContractDetails>
Convert an instrument ID to IB contract details.
This is equivalent to Python’s instrument_id_to_ib_contract_details method.
§Returns
Returns the contract details if found, None otherwise.
pub fn instrument_id_to_ib_contract( &self, instrument_id: &InstrumentId, ) -> Option<Contract>
pub fn resolve_contract_for_instrument( &self, instrument_id: InstrumentId, ) -> Result<Contract>
pub async fn resolve_contract_for_instrument_async( &self, client: &Client, instrument_id: InstrumentId, ) -> Result<Contract>
Sourcepub async fn load_with_return_async(
&self,
client: &Client,
instrument_id: InstrumentId,
filters: Option<HashMap<String, String>>,
) -> Result<Option<InstrumentId>>
pub async fn load_with_return_async( &self, client: &Client, instrument_id: InstrumentId, filters: Option<HashMap<String, String>>, ) -> Result<Option<InstrumentId>>
Sourcepub async fn load_ids_with_return_async(
&self,
client: &Client,
instrument_ids: Vec<InstrumentId>,
filters: Option<HashMap<String, String>>,
) -> Result<Vec<InstrumentId>>
pub async fn load_ids_with_return_async( &self, client: &Client, instrument_ids: Vec<InstrumentId>, filters: Option<HashMap<String, String>>, ) -> Result<Vec<InstrumentId>>
Sourcepub async fn fetch_spread_instrument(
&self,
client: &Client,
spread_instrument_id: InstrumentId,
force_instrument_update: bool,
filters: Option<HashMap<String, String>>,
) -> Result<bool>
pub async fn fetch_spread_instrument( &self, client: &Client, spread_instrument_id: InstrumentId, force_instrument_update: bool, filters: Option<HashMap<String, String>>, ) -> Result<bool>
Fetch a spread instrument by loading its individual legs.
This is equivalent to Python’s _fetch_spread_instrument method.
It parses the spread instrument ID to extract leg tuples, loads each leg,
and then creates the spread instrument.
§Returns
Returns true if the spread instrument was successfully loaded, false otherwise.
§Errors
Returns an error if parsing or loading fails.
Sourcepub async fn load_all_async(
&self,
client: &Client,
instrument_ids: Option<Vec<InstrumentId>>,
contracts: Option<Vec<Contract>>,
force_instrument_update: bool,
) -> Result<Vec<InstrumentId>>
pub async fn load_all_async( &self, client: &Client, instrument_ids: Option<Vec<InstrumentId>>, contracts: Option<Vec<Contract>>, force_instrument_update: bool, ) -> Result<Vec<InstrumentId>>
Load all instruments from provided IDs and contracts.
This is equivalent to Python’s load_all_async method.
Python version loads from config’s _load_ids_on_start and _load_contracts_on_start.
Rust version accepts these as parameters for flexibility.
§Errors
Returns an error if loading fails.
Source§impl InteractiveBrokersInstrumentProvider
impl InteractiveBrokersInstrumentProvider
Sourcepub async fn fetch_contract_details(
&self,
client: &Client,
instrument_id: InstrumentId,
force_instrument_update: bool,
filters: Option<HashMap<String, String>>,
) -> Result<()>
pub async fn fetch_contract_details( &self, client: &Client, instrument_id: InstrumentId, force_instrument_update: bool, filters: Option<HashMap<String, String>>, ) -> Result<()>
Fetch and cache contract details for an instrument ID using the provided IB client.
§Errors
Returns an error if fetching fails.
Sourcepub async fn batch_load(
&self,
client: &Client,
instrument_ids: Vec<InstrumentId>,
filters: Option<&[String]>,
) -> Result<Vec<InstrumentId>>
pub async fn batch_load( &self, client: &Client, instrument_ids: Vec<InstrumentId>, filters: Option<&[String]>, ) -> Result<Vec<InstrumentId>>
Sourcepub async fn fetch_option_chain_by_range(
&self,
client: &Client,
underlying: &Contract,
expiry_min: Option<&str>,
expiry_max: Option<&str>,
option_chain_exchange: Option<&str>,
) -> Result<usize>
pub async fn fetch_option_chain_by_range( &self, client: &Client, underlying: &Contract, expiry_min: Option<&str>, expiry_max: Option<&str>, option_chain_exchange: Option<&str>, ) -> Result<usize>
Fetch option chain for a given underlying contract with expiry filtering.
This is equivalent to Python’s get_option_chain_details_by_range.
It uses contract_details to fetch options with precise expiry filtering,
which is more flexible than the basic option_chain API.
§Returns
Returns the number of option instruments loaded.
§Errors
Returns an error if fetching fails.
Sourcepub async fn fetch_futures_chain(
&self,
client: &Client,
symbol: &str,
exchange: &str,
currency: &str,
trading_class: Option<&str>,
include_expired: bool,
min_expiry_days: Option<u32>,
max_expiry_days: Option<u32>,
) -> Result<usize>
pub async fn fetch_futures_chain( &self, client: &Client, symbol: &str, exchange: &str, currency: &str, trading_class: Option<&str>, include_expired: bool, min_expiry_days: Option<u32>, max_expiry_days: Option<u32>, ) -> Result<usize>
Fetch and cache futures chain (all futures contracts for a symbol).
This method fetches all futures contracts for a given underlying symbol and populates the cache with all individual futures instruments.
§Returns
Returns the number of futures instruments loaded.
§Errors
Returns an error if fetching fails.
Sourcepub async fn fetch_bag_contract(
&self,
client: &Client,
bag_contract: &Contract,
) -> Result<usize>
pub async fn fetch_bag_contract( &self, client: &Client, bag_contract: &Contract, ) -> Result<usize>
Fetch and cache a BAG (spread) contract.
This method fetches contract details for a spread contract by requesting contract details with a BAG contract. The BAG contract should have its combo_legs populated with the individual leg contract IDs.
§Returns
Returns the number of spread instruments loaded (0 or 1).
§Errors
Returns an error if fetching fails.
§Notes
This method now auto-loads all leg instruments from combo_legs and creates
a proper spread instrument, matching Python’s _load_bag_contract behavior.
Trait Implementations§
impl DerefToPyAny for InteractiveBrokersInstrumentProvider
Source§impl<'a, 'py> FromPyObject<'a, 'py> for InteractiveBrokersInstrumentProviderwhere
Self: Clone,
impl<'a, 'py> FromPyObject<'a, 'py> for InteractiveBrokersInstrumentProviderwhere
Self: Clone,
Source§impl<'py> IntoPyObject<'py> for InteractiveBrokersInstrumentProvider
impl<'py> IntoPyObject<'py> for InteractiveBrokersInstrumentProvider
Source§type Target = InteractiveBrokersInstrumentProvider
type Target = InteractiveBrokersInstrumentProvider
Source§type Output = Bound<'py, <InteractiveBrokersInstrumentProvider as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <InteractiveBrokersInstrumentProvider as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for InteractiveBrokersInstrumentProvider
impl PyClass for InteractiveBrokersInstrumentProvider
Source§impl PyClassImpl for InteractiveBrokersInstrumentProvider
impl PyClassImpl for InteractiveBrokersInstrumentProvider
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// Interactive Brokers instrument provider.
///
/// This provider fetches contract details from Interactive Brokers using the `rust-ibapi` library
/// and converts them to NautilusTrader instruments.
const RAW_DOC: &'static CStr = /// Interactive Brokers instrument provider. /// /// This provider fetches contract details from Interactive Brokers using the `rust-ibapi` library /// and converts them to NautilusTrader instruments.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<InteractiveBrokersInstrumentProvider as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<InteractiveBrokersInstrumentProvider>
type Layout = <<InteractiveBrokersInstrumentProvider as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<InteractiveBrokersInstrumentProvider>
Source§type ThreadChecker = ThreadCheckerImpl
type ThreadChecker = ThreadCheckerImpl
type Inventory = Pyo3MethodsInventoryForInteractiveBrokersInstrumentProvider
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
§fn dict_offset() -> Option<PyObjectOffset>
fn dict_offset() -> Option<PyObjectOffset>
§fn weaklist_offset() -> Option<PyObjectOffset>
fn weaklist_offset() -> Option<PyObjectOffset>
Source§impl PyClassNewTextSignature for InteractiveBrokersInstrumentProvider
impl PyClassNewTextSignature for InteractiveBrokersInstrumentProvider
const TEXT_SIGNATURE: &'static str = "(config)"
Source§impl PyStubType for InteractiveBrokersInstrumentProvider
impl PyStubType for InteractiveBrokersInstrumentProvider
Source§fn type_output() -> TypeInfo
fn type_output() -> TypeInfo
§fn type_input() -> TypeInfo
fn type_input() -> TypeInfo
Source§impl PyTypeInfo for InteractiveBrokersInstrumentProvider
impl PyTypeInfo for InteractiveBrokersInstrumentProvider
Source§const NAME: &str = <Self as ::pyo3::PyClass>::NAME
const NAME: &str = <Self as ::pyo3::PyClass>::NAME
prefer using ::type_object(py).name() to get the correct runtime value
Source§const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
prefer using ::type_object(py).module() to get the correct runtime value
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.Auto Trait Implementations§
impl !RefUnwindSafe for InteractiveBrokersInstrumentProvider
impl !UnwindSafe for InteractiveBrokersInstrumentProvider
impl Freeze for InteractiveBrokersInstrumentProvider
impl Send for InteractiveBrokersInstrumentProvider
impl Sync for InteractiveBrokersInstrumentProvider
impl Unpin for InteractiveBrokersInstrumentProvider
impl UnsafeUnpin for InteractiveBrokersInstrumentProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<'py, T> FromPyObjectOwned<'py> for Twhere
T: for<'a> FromPyObject<'a, 'py>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read more§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>where
Self: IntoPyObject<'py, Error = !>,
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>where
Self: IntoPyObject<'py, Error = !>,
self into a [Py<PyAny>] when the underlying conversion is infallible.§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more