nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
2.21k stars 506 forks source link

Databento futures instruments arrow deserialization can fail #2065

Open cjdsellers opened 5 days ago

cjdsellers commented 5 days ago

Bug Report

Expected Behavior

Databento instruments should deserialize without error.

Actual Behavior

As reported on Discord, sometimes a price_increment becomes zero during arrow deserialization.

Traceback (most recent call last):
  ...
line 659, in _handle_table_nautilus
    data = ArrowSerializer.deserialize(data_cls=data_cls, batch=table)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ck/PycharmProjects/nautilus/.venv/lib/python3.12/site-packages/nautilus_trader/serialization/arrow/serializer.py", line 257, in deserialize
    return delegate(batch)
           ^^^^^^^^^^^^^^^
  File "/home/ck/PycharmProjects/nautilus/.venv/lib/python3.12/site-packages/nautilus_trader/serialization/arrow/implementations/instruments.py", line 369, in deserialize
    return [Cls.from_dict(data) for data in maps]
            ^^^^^^^^^^^^^^^^^^^
  File "nautilus_trader/model/instruments/futures_contract.pyx", line 276, in nautilus_trader.model.instruments.futures_contract.FuturesContract.from_dict
  File "nautilus_trader/model/instruments/futures_contract.pyx", line 193, in nautilus_trader.model.instruments.futures_contract.FuturesContract.from_dict_c
  File "nautilus_trader/model/instruments/futures_contract.pyx", line 109, in nautilus_trader.model.instruments.futures_contract.FuturesContract.__init__
  File "nautilus_trader/model/instruments/base.pyx", line 192, in nautilus_trader.model.instruments.base.Instrument.__init__
  File "nautilus_trader/core/correctness.pyx", line 593, in nautilus_trader.core.correctness.Condition.positive
ValueError: 'price_increment' not a positive real, was 0.0

Intended solution

Review which fields are being used to provide this value, and probably use a reasonable fallback or default value in its absence.