nautechsystems/nautilus_trader · error · anyhow::Error
invalid close price: {e}
Error message
invalid close price: {e} What it means
The close price of a Hyperliquid candle fails `Price::from_decimal_dp(candle.close, price_precision)` during Bar conversion, wrapped as "invalid close price". The close value is unparsable or incompatible with the instrument's price precision.
Source
Thrown at crates/adapters/hyperliquid/src/data.rs:2080
bar_type: BarType,
price_precision: u8,
size_precision: u8,
) -> anyhow::Result<Bar> {
let ts_event = millis_to_nanos(candle.timestamp)?;
let close_boundary = candle
.end_timestamp
.checked_add(1)
.context("candle close boundary overflow")?;
let ts_init = millis_to_nanos(close_boundary)?;
let open = Price::from_decimal_dp(candle.open, price_precision)
.map_err(|e| anyhow::anyhow!("invalid open price: {e}"))?;
let high = Price::from_decimal_dp(candle.high, price_precision)
.map_err(|e| anyhow::anyhow!("invalid high price: {e}"))?;
let low = Price::from_decimal_dp(candle.low, price_precision)
.map_err(|e| anyhow::anyhow!("invalid low price: {e}"))?;
let close = Price::from_decimal_dp(candle.close, price_precision)
.map_err(|e| anyhow::anyhow!("invalid close price: {e}"))?;
let volume = Quantity::from_decimal_dp(candle.volume, size_precision)
.map_err(|e| anyhow::anyhow!("invalid volume: {e}"))?;
Ok(Bar::new(
bar_type, open, high, low, close, volume, ts_event, ts_init,
))
}
/// Request bars from HTTP API.
async fn request_bars_from_http(
http_client: HyperliquidHttpClient,
bar_type: BarType,
start: Option<Timestamp>,
end: Option<Timestamp>,
limit: Option<u32>,
instruments: Arc<AtomicMap<InstrumentId, InstrumentAny>>,
) -> anyhow::Result<Vec<Bar>> {
// Get instrument details for precisionView on GitHub (pinned to 18893faf8b)
Solutions
- Refresh instrument definitions to get the correct price_precision.
- Inspect the raw candle `close` value and fix the data source.
- Re-fetch the affected candle range.
- Round/normalize custom close prices to the instrument precision before conversion.
Example fix
// before
Candle { close: "0.123456789012".to_string(), .. } // precision = 6
// after
Candle { close: "0.123457".to_string(), .. } Defensive patterns
Strategy: validation
Validate before calling
fn candle_fits_precision(close: &str, price_precision: u8) -> bool {
rust_decimal::Decimal::from_str(close)
.map(|d| d.scale() <= price_precision as u32)
.unwrap_or(false)
} Try / catch
match result {
Err(e) if e.to_string().contains("invalid close price") => {
tracing::warn!("dropping candle with bad close: {e:#}");
}
r => r?,
} Prevention
- Round close prices to the instrument precision before conversion.
- Refresh instrument definitions periodically; precision can change.
- Validate candle payloads (all OHLCV fields parse as decimals) on ingestion.
When it happens
Trigger: Candle payload with a malformed `close` decimal, or a locally configured price_precision smaller than the decimals present in the close value when building the Bar.
Common situations: Outdated instrument definitions after a market precision change; corrupted candles from an aggregator; test data with arbitrary-precision decimals.
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
- invalid open price: {e}
- invalid high price: {e}
- invalid low price: {e}
- invalid volume: {e}
- invalid candle volume: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/7e5f3458137a28e2.
Report an issue: GitHub.