nautechsystems/nautilus_trader · error · ValueError

Unexpected CSV header, was {header[:3]}

Error message

Unexpected CSV header, was {header[:3]}

What it means

Guard in TestInstrumentProvider.quotes_from_truefx_csv that rejects a TrueFX tick CSV whose first three columns are not exactly timestamp,bid,ask. It fires when a file with a different layout or an extra leading column is passed, before any row parsing begins.

Source

Thrown at python/nautilus_trader/testkit/providers.py:513

    @staticmethod
    def quotes_from_truefx_csv(
        instrument: CurrencyPair | PerpetualContract,
        csv_name: str,
        max_rows: int | None = None,
    ) -> list[QuoteTick]:
        """
        Build QuoteTicks from a TrueFX tick CSV file ('timestamp,bid,ask').
        """
        precision = instrument.price_precision
        size = Quantity.from_str("1000000")
        ticks: list[QuoteTick] = []

        with _open_test_data_text(csv_name) as f:
            reader = csv.reader(f)
            header = next(reader)
            if header[:3] != ["timestamp", "bid", "ask"]:
                raise ValueError(f"Unexpected CSV header, was {header[:3]}")

            for i, row in enumerate(reader):
                if max_rows is not None and i >= max_rows:
                    break
                ts_ns = _parse_iso_to_ns(row[0])
                ticks.append(
                    QuoteTick(
                        instrument_id=instrument.id,
                        bid_price=Price(float(row[1]), precision=precision),
                        ask_price=Price(float(row[2]), precision=precision),
                        bid_size=size,
                        ask_size=size,
                        ts_event=ts_ns,
                        ts_init=ts_ns,
                    ),
                )

        return ticks

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Point csv_name at a genuine TrueFX 'timestamp,bid,ask' tick export
  2. Verify the file was not transformed, reordered, or given a different delimiter before loading
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at python/nautilus_trader/testkit/providers.py:513 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/9891c46051bec2af. Report an issue: GitHub.