pub fn register_custom_data_class(data_class: &Bound<'_, PyAny>) -> PyResult<()>Expand description
Registers a custom data type (class) with the catalog registry.
Use this when you prefer to pass the class instead of a sample instance. The class must have:
type_name_static()class method or__name__(used as type name in storage)from_json(data)class methoddecode_record_batch_py(metadata, batch)class method- Instances must have
ts_event,ts_init, andencode_record_batch_py(items).
§Arguments
data_class- The custom data class (e.g.MarketTickPythonormodule.MarketTickData)
§Errors
Returns a PyErr if the class lacks required methods or the type is already registered.
§Example
import json
from nautilus_trader.model import register_custom_data_class
class MarketTickPython:
ts_event = 0
ts_init = 0
def to_json(self):
return json.dumps(self.__dict__)
@classmethod
def from_json(cls, data):
instance = cls()
instance.__dict__.update(data)
return instance
def encode_record_batch_py(self, items):
raise NotImplementedError("Arrow encoding is not configured")
@classmethod
def decode_record_batch_py(cls, metadata, batch):
raise NotImplementedError("Arrow decoding is not configured")
register_custom_data_class(MarketTickPython)The Arrow methods may raise for a message-bus-only class, but must be implemented before catalog persistence is used.