Skip to main content

arrow_custom_data

Attribute Macro arrow_custom_data 

Source
#[arrow_custom_data]
Expand description

Adds Arrow schema, encoding, and decoding implementations to a custom data struct.

Apply this above #[nautilus_model::custom_data] for macro-generated model behavior, or use it alone when the model traits are implemented manually. Call nautilus_serialization::ensure_custom_data_registered::<T>() before catalog or streaming serialization.

Supported field types include InstrumentId, AccountId, Currency, BarType, Params, Price, Quantity, Decimal, optional prices and quantities, UnixNanos, f64, f32, bool, String, u64, i64, u32, i32, Vec<f64>, and Vec<u8>. Prices and quantities use nullable Decimal128(38, 16) columns. Vec<u8> is the deliberate opaque-byte escape hatch for custom schemas. Decimal values preserve their numeric value at scale 16, but not the source value’s trailing-zero scale. Use #[custom_data_field(native_enum)] on a native enum that implements Display and FromStr to encode it as a compact dictionary of display names. Use #[custom_data_field(serde)] on a field to store any Serde serializable field as a Serde JSON-backed Arrow Utf8 column. Python field access for such fields comes from nautilus_model’s custom_data macro, not this macro.

Use #[arrow_custom_data(pyo3)] to generate PyArrow encode_record_batch_py and decode_record_batch_py methods; this is independent from the model macro’s pyo3 option. Use stub_module = "nautilus_trader.<module>" with pyo3 to emit pyo3-stub-gen metadata.