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.
§Arguments
config- Configuration for the provider
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 fn determine_venue(
&self,
contract: &Contract,
contract_details: Option<&ContractDetails>,
) -> Venue
pub fn determine_venue( &self, contract: &Contract, contract_details: Option<&ContractDetails>, ) -> 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 is_filtered_sec_type(&self, sec_type: &str) -> bool
pub fn is_filtered_sec_type(&self, sec_type: &str) -> bool
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.
§Arguments
instrument_id- The instrument ID to look up
§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>>
Get an instrument by IB Contract.
This is equivalent to Python’s get_instrument method.
Supports BAG contracts by auto-loading legs.
§Arguments
client- The IB API clientcontract- The IB contract to get instrument for
§Returns
Returns the instrument if found, None otherwise.
§Errors
Returns an error if fetching fails.
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>
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>
Sourcepub async fn load_async(
&self,
client: &Client,
instrument_id: InstrumentId,
filters: Option<HashMap<String, String>>,
) -> Result<()>
pub async fn load_async( &self, client: &Client, instrument_id: InstrumentId, filters: Option<HashMap<String, String>>, ) -> Result<()>
Load a single instrument (does not return loaded IDs).
This is equivalent to Python’s load_async method.
§Arguments
client- The IB API clientinstrument_id- The instrument ID to loadforce_instrument_update- If true, force re-fetch even if already cached
§Errors
Returns an error if loading fails.
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>>
Load a single instrument and return the loaded instrument ID.
This is equivalent to Python’s load_with_return_async method.
§Arguments
client- The IB API clientinstrument_id- The instrument ID to loadforce_instrument_update- If true, force re-fetch even if already cached
§Returns
Returns the loaded instrument ID if successful, None otherwise.
§Errors
Returns an error if loading fails.
Sourcepub async fn load_ids_async(
&self,
client: &Client,
instrument_ids: Vec<InstrumentId>,
filters: Option<HashMap<String, String>>,
) -> Result<()>
pub async fn load_ids_async( &self, client: &Client, instrument_ids: Vec<InstrumentId>, filters: Option<HashMap<String, String>>, ) -> Result<()>
Load multiple instruments (does not return loaded IDs).
This is equivalent to Python’s load_ids_async method.
§Arguments
client- The IB API clientinstrument_ids- Vector of instrument IDs to loadforce_instrument_update- If true, force re-fetch even if already cached
§Errors
Returns an error if loading fails.
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>>
Load multiple instruments and return the loaded instrument IDs.
This is equivalent to Python’s load_ids_with_return_async method.
§Arguments
client- The IB API clientinstrument_ids- Vector of instrument IDs to loadforce_instrument_update- If true, force re-fetch even if already cached
§Returns
Returns a vector of successfully loaded instrument IDs.
§Errors
Returns an error if loading fails.
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.
§Arguments
client- The IB API clientspread_instrument_id- The spread instrument ID to fetchforce_instrument_update- If true, force re-fetch even if already cached
§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.
§Arguments
client- The IB API clientinstrument_ids- Optional vector of instrument IDs to loadcontracts- Optional vector of IB contracts to loadforce_instrument_update- If true, force re-fetch even if already cached
§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<()>
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>>
Batch load multiple instrument IDs.
This method fetches and caches contract details for multiple instrument IDs in parallel.
§Arguments
client- The IB API clientinstrument_ids- Vector of instrument IDs to loadfilters- Optional filters to apply (not yet implemented, reserved for future use)
§Returns
Returns a vector of successfully loaded instrument IDs.
§Errors
Returns an error if fetching fails.
Sourcepub async fn fetch_option_chain_by_range(
&self,
client: &Client,
underlying: &Contract,
expiry_min: Option<&str>,
expiry_max: 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>, ) -> 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.
§Arguments
client- The IB API clientunderlying- The underlying contractexpiry_min- Minimum expiry date string (YYYYMMDD format, can be None for no min)expiry_max- Maximum expiry date string (YYYYMMDD format, can be None for no max)
§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,
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, 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.
§Arguments
client- The IB API clientsymbol- The underlying symbolexchange- The exchange (use “” for all exchanges)currency- The currency (use USD as default)
§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.
§Arguments
client- The IB API clientbag_contract- The BAG contract with populated combo_legs
§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.
Sourcepub async fn save_cache(&self, cache_path: &str) -> Result<()>
pub async fn save_cache(&self, cache_path: &str) -> Result<()>
Sourcepub async fn load_cache(&self, cache_path: &str) -> Result<bool>
pub async fn load_cache(&self, cache_path: &str) -> Result<bool>
Trait Implementations§
Source§impl Clone for InteractiveBrokersInstrumentProvider
impl Clone for InteractiveBrokersInstrumentProvider
Source§fn clone(&self) -> InteractiveBrokersInstrumentProvider
fn clone(&self) -> InteractiveBrokersInstrumentProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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 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.impl DerefToPyAny for InteractiveBrokersInstrumentProvider
Auto Trait Implementations§
impl Freeze for InteractiveBrokersInstrumentProvider
impl !RefUnwindSafe for InteractiveBrokersInstrumentProvider
impl Send for InteractiveBrokersInstrumentProvider
impl Sync for InteractiveBrokersInstrumentProvider
impl Unpin for InteractiveBrokersInstrumentProvider
impl UnsafeUnpin for InteractiveBrokersInstrumentProvider
impl !UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§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,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
§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