nautechsystems/nautilus_trader · error
invalid funding_rate_timestamp
Error message
invalid funding_rate_timestamp
What it means
When computing funding-rate intervals, the client parses each funding_rate_timestamp from Bybit's response as an i64 millisecond epoch. If the string is non-numeric or empty the parse fails and the code returns 'invalid funding_rate_timestamp' via anyhow::anyhow!. This guards against malformed/unexpected payloads from Bybit's funding-rate history endpoint before computing the interval between consecutive windows.
Source
Thrown at crates/adapters/bybit/src/http/client.rs:3903
{
break;
}
// Move end time backwards to get earlier data
current_end_ms = Some(earliest_funding_time - 1);
}
if let Some(limit_val) = limit {
raw_funding_rates.truncate(limit_val as usize);
}
let mut rates: Vec<FundingRateUpdate> = Vec::with_capacity(raw_funding_rates.len());
for window in raw_funding_rates.windows(2) {
let raw = &window[0];
let timestamp = raw
.funding_rate_timestamp
.parse::<i64>()
.map_err(|_| anyhow::anyhow!("invalid funding_rate_timestamp"))?;
let older_timestamp = window[1]
.funding_rate_timestamp
.parse::<i64>()
.map_err(|_| anyhow::anyhow!("invalid funding_rate_timestamp"))?;
let interval_millis = timestamp - older_timestamp;
let rate = parse_funding_rate(raw, &instrument, Some(interval_millis))?;
rates.push(rate);
}
if let Some(last_raw) = raw_funding_rates.last() {
let rate = parse_funding_rate(last_raw, &instrument, None)?;
rates.push(rate);
}
rates.reverse();
View on GitHub (pinned to 18893faf8b)
Solutions
- Upgrade the nautilus_bybit crate / Bybit adapter to a version matching the current Bybit v5 API schema
- Log or dump the raw funding-rate response to inspect the actual timestamp format returned
- Retry the request — transient malformed responses can occur; verify it reproduces consistently
- If the format changed, patch the parse site (crates/adapters/bybit/src/http/client.rs:3903) to handle the new format and report upstream
Example fix
// before
let timestamp = raw.funding_rate_timestamp.parse::<i64>()
.map_err(|_| anyhow::anyhow!("invalid funding_rate_timestamp"))?;
// after
let timestamp = raw.funding_rate_timestamp.parse::<i64>()
.with_context(|| format!("invalid funding_rate_timestamp: {:?}", raw.funding_rate_timestamp))?;
// or upgrade to the adapter version that matches the current Bybit schema Defensive patterns
Strategy: try-catch
Validate before calling
fn valid_millis_ts(s: &str) -> bool {
!s.is_empty() && s.chars().all(|c| c.is_ascii_digit())
}
// filter rows before use
let rows: Vec<_> = raw.iter().filter(|r| valid_millis_ts(&r.funding_rate_timestamp)).collect(); Type guard
fn parse_ts(s: &str) -> Option<i64> { s.parse::<i64>().ok() } Try / catch
match client.funding_rates(symbol, limit).await {
Ok(rates) => rates,
Err(e) if e.to_string().contains("invalid funding_rate_timestamp") => {
log::warn!("malformed funding rate payload: {e}; retrying");
client.funding_rates(symbol, limit).await
}
Err(e) => return Err(e),
} Prevention
- Keep the Bybit adapter updated to the current API schema
- Validate timestamp fields before arithmetic on intervals
- Log raw payloads on parse failures to speed diagnosis
When it happens
Trigger: Bybit returning a funding-rate history row whose funding_rate_timestamp is empty, null serialized as empty string, or format-changed (e.g. ISO datetime instead of millis); newer Bybit API versions altering the field; hitting testnet or an endpoint variant with a different schema.
Common situations: Bybit API schema changes breaking older client versions; proxy/mocked endpoints returning different timestamp formats; requesting funding rates for symbols/product types whose history rows lack the field.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- funding_interval_hour out of bounds
- Invalid funding_rate value: {e}
- Invalid funding_interval, cannot be negative
- Invalid scientific notation exponent '{exponent}': must be a
- {FAILED}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/fa404dbddb37a380.
Report an issue: GitHub.