nautechsystems/nautilus_trader · error
invalid `TimeInForce` enum string value, was '{value}'
Error message
invalid `TimeInForce` enum string value, was '{value}' What it means
`time_in_force_from_cstr` parses a C string into a `TimeInForce` enum at the FFI boundary. On any string that does not correspond to a `TimeInForce` variant (GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE, etc.) it panics inside `abort_on_panic`, aborting the process rather than returning an error. This enforces that only canonical enum serializations cross the C ABI.
Source
Thrown at crates/model/src/ffi/enums.rs:859
pub extern "C" fn time_in_force_to_cstr(value: TimeInForce) -> *const c_char {
str_to_cstr(value.as_ref())
}
/// Returns an enum from a C string.
///
/// # Safety
///
/// Assumes `ptr` is a valid C string pointer.
///
/// # Panics
///
/// Panics if the C string does not correspond to a valid `TimeInForce` variant.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn time_in_force_from_cstr(ptr: *const c_char) -> TimeInForce {
abort_on_panic(|| {
let value = unsafe { cstr_as_str(ptr) };
TimeInForce::from_str(value)
.unwrap_or_else(|_| panic!("invalid `TimeInForce` enum string value, was '{value}'"))
})
}
#[unsafe(no_mangle)]
pub extern "C" fn trading_state_to_cstr(value: TradingState) -> *const c_char {
str_to_cstr(value.as_ref())
}
/// Returns an enum from a C string.
///
/// # Safety
///
/// Assumes `ptr` is a valid C string pointer.
///
/// # Panics
///
/// Panics if the C string does not correspond to a valid `TradingState` variant.
#[unsafe(no_mangle)]View on GitHub (pinned to 18893faf8b)
Solutions
- Compare the failing string against the canonical `TimeInForce` variant names and correct the caller.
- Translate exchange/FIX TIF codes to nautilus `TimeInForce` variants in an adapter layer before crossing FFI.
- Use `time_in_force_to_cstr` on the enum to build valid input strings programmatically.
- Validate/whitelist TIF values in your config parsing before they reach the FFI call.
Example fix
// before
time_in_force_from_cstr(str_to_cstr("GoodTillCancelled"));
// after
time_in_force_from_cstr(str_to_cstr("GTC")); Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_tif(s: &str) -> bool {
TimeInForce::from_str(s).is_ok()
} Type guard
fn as_time_in_force(s: &str) -> Option<TimeInForce> {
TimeInForce::from_str(s).ok()
} Prevention
- Translate exchange/FIX TIF codes to canonical nautilus variants in adapters
- Validate TIF config values at startup, not at trade time
- Use enum objects (PyO3 class) in Python instead of raw strings
When it happens
Trigger: Calling `time_in_force_from_cstr(ptr)` with an unsupported or misspelled TIF string, such as "GTC " with trailing space, "GoodTillCancel", or a broker-specific value like "OPG" that the enum does not define.
Common situations: Mapping broker/exchange TIF codes (e.g. FIX tag 59 values) directly to nautilus strings without translation; adapters passing lowercase values; enum renamed between nautilus releases breaking persisted configs.
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
- invalid `AggressorSide` enum string value, was '{value}'
- invalid `AssetClass` enum string value, was '{value}'
- invalid `InstrumentClass` enum string value, was '{value}'
- invalid `BarAggregation` enum string value, was '{value}'
- invalid `BookAction` enum string value, was '{value}'
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/2ce79f5ba74be25b.
Report an issue: GitHub.