nautechsystems/nautilus_trader · error · anyhow::Error
Cannot cache futures spread: missing option instrument {call
Error message
Cannot cache futures spread: missing option instrument {call_instrument_id} What it means
`cache_futures_spread` builds a synthetic futures-spread price cache from a call/put option pair and a reference future. This error is raised when the call option instrument cannot be found in the cache, so the spread cannot be computed. It indicates the required instrument was never added to (or was dropped from) the `Cache`.
Source
Thrown at crates/common/src/greeks.rs:1056
/// Cache a futures spread derived from a call/put pair against a reference future.
///
/// # Errors
///
/// Returns an error if instruments or prices are missing or inconsistent.
pub fn cache_futures_spread(
&self,
call_instrument_id: InstrumentId,
put_instrument_id: InstrumentId,
futures_instrument_id: InstrumentId,
) -> anyhow::Result<Price> {
let cache = self.cache.borrow();
let call_instrument = cache.instrument(&call_instrument_id).cloned();
let put_instrument = cache.instrument(&put_instrument_id).cloned();
let reference_future_instrument = cache.instrument(&futures_instrument_id).cloned();
drop(cache);
let Some(call_instrument) = call_instrument else {
anyhow::bail!(
"Cannot cache futures spread: missing option instrument {call_instrument_id}"
);
};
let Some(put_instrument) = put_instrument else {
anyhow::bail!(
"Cannot cache futures spread: missing option instrument {put_instrument_id}"
);
};
let Some(reference_future_instrument) = reference_future_instrument else {
anyhow::bail!(
"Cannot cache futures spread: no reference futures instrument for {futures_instrument_id}"
);
};
if call_instrument.instrument_class() != InstrumentClass::Option
|| put_instrument.instrument_class() != InstrumentClass::Option
{
anyhow::bail!(View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure all option chain instruments are loaded and added to the cache before calling `cache_futures_spread`
- Log/verify the exact `call_instrument_id` string and compare against `cache.instrument_ids()`
- Fix the venue/symbol construction that produced the call instrument ID
Example fix
// before
greeks.cache_futures_spread(&call_id, &put_id, &future_id)?;
// after
if cache.instrument(&call_id).is_none() {
anyhow::bail!("call option {call_id} not in cache; load instruments first");
}
greeks.cache_futures_spread(&call_id, &put_id, &future_id)?; Defensive patterns
Strategy: validation
Validate before calling
fn ensure_cached(cache: &Cache, id: &InstrumentId) -> Result<(), String> {
if cache.instrument(id).is_some() { Ok(()) } else { Err(format!("{id} not in cache")) }
} Try / catch
match greeks.cache_futures_spread(&call_id, &put_id, &future_id) {
Ok(()) => (),
Err(e) if e.to_string().contains("missing option instrument") => {
tracing::warn!("{e}; reload option chain instruments");
return Ok(());
}
Err(e) => return Err(e),
} Prevention
- Load the complete option chain (calls and puts) into the cache at startup
- Validate all referenced instrument IDs exist in the cache before spread calculations
- Keep instrument definitions and market-data subscriptions in sync
When it happens
Trigger: Calling `cache_futures_spread(...)` with a `call_instrument_id` that has no instrument registered in the cache — e.g. the ID was constructed from a symbol string rather than a loaded instrument definition, or instruments were loaded for a different venue.
Common situations: Instrument definitions for the option chain not loaded at startup; typo or wrong venue in the instrument ID; cache cleared between load and calculation; tests constructing IDs without registering instruments first.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Cannot cache futures spread: missing option instrument {put_
- cannot rebuild Wallet reservations: no instrument found for
- DataActor {} must be registered before calling `cache()` - t
- Order {client_order_id} not found
- Position {position_id} not found
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/146ef5c90bdeb6cc.
Report an issue: GitHub.