nautechsystems/nautilus_trader · error · anyhow::Error
Unknown IB time in force: {value}
Error message
Unknown IB time in force: {value} What it means
IbTimeInForce::from_str in crates/adapters/interactive_brokers/src/common/enums/order.rs:540 rejects any string not matching a supported IB time-in-force code (DAY, GTC, IOC, GTD, OPG, FOK, DTC, AUC) via anyhow::bail!. Only exact wire codes are accepted.
Source
Thrown at crates/adapters/interactive_brokers/src/common/enums/order.rs:540
ibapi::orders::TimeInForce::Auction => Self::Auction,
}
}
}
impl FromStr for IbTimeInForce {
type Err = anyhow::Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"DAY" => Ok(Self::Day),
"GTC" => Ok(Self::GoodTilCanceled),
"IOC" => Ok(Self::ImmediateOrCancel),
"GTD" => Ok(Self::GoodTilDate),
"OPG" => Ok(Self::OnOpen),
"FOK" => Ok(Self::FillOrKill),
"DTC" => Ok(Self::DayTilCanceled),
"AUC" => Ok(Self::Auction),
_ => anyhow::bail!("Unknown IB time in force: {value}"),
}
}
}
impl Display for IbTimeInForce {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Day => "DAY",
Self::GoodTilCanceled => "GTC",
Self::ImmediateOrCancel => "IOC",
Self::GoodTilDate => "GTD",
Self::OnOpen => "OPG",
Self::FillOrKill => "FOK",
Self::DayTilCanceled => "DTC",
Self::Auction => "AUC",
})
}
}View on GitHub (pinned to 18893faf8b)
Solutions
- Use the exact IB code: "DAY", "GTC", "IOC", "GTD", "OPG", "FOK", "DTC", or "AUC".
- Normalize input with trim + to_ascii_uppercase before parsing.
- Verify the configured TIF is supported by this adapter, not just by IB in general.
- Extend the match arm list upstream if a new IB TIF code must be supported.
Example fix
// before let tif = "gtc ".parse::<IbTimeInForce>()?; // bail! // after let tif = "gtc ".trim().to_ascii_uppercase().parse::<IbTimeInForce>()?; // Ok(GoodTilCanceled)
Defensive patterns
Strategy: validation
Validate before calling
const IB_TIFS: &[&str] = &["DAY","GTC","IOC","GTD","OPG","FOK","DTC","AUC"];
fn is_valid_ib_tif(s: &str) -> bool {
IB_TIFS.contains(&s.trim().to_ascii_uppercase().as_str())
} Type guard
fn as_ib_time_in_force(s: &str) -> Option<IbTimeInForce> {
s.trim().to_ascii_uppercase().parse::<IbTimeInForce>().ok()
} Try / catch
match value.parse::<IbTimeInForce>() {
Ok(tif) => submit(tif),
Err(e) => return Err(anyhow::anyhow!("invalid time_in_force '{value}': {e}")),
} Prevention
- Use the enum variant directly in code instead of raw strings where possible.
- Normalize TIF strings (trim + uppercase) at the config boundary.
- Do not assume TIF codes from other brokers are valid for IB.
When it happens
Trigger: Parsing a time-in-force value that is not one of the listed codes: e.g. "Gtc", "day", "GTDAY", or a TIF from another adapter's vocabulary.
Common situations: Order config YAML/JSON with mixed-case TIF strings; users writing "GoodTilDate" or "good_til_date" instead of the IB code "GTD"; porting strategies from other brokers that use extended TIF names.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unknown IB option right: {value}
- Unknown IB historical tick type: {value}
- Unknown IB action: {value}
- Unknown IB order status: {value}
- Unknown IB order type: {value}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/18ea6c9381647b86.
Report an issue: GitHub.