From 30aff27d1ee6d2e93e20a61b062ce6af6d41836e Mon Sep 17 00:00:00 2001 From: Filip Macek Date: Sat, 20 Apr 2024 23:09:48 +0200 Subject: [PATCH] Add from_str pyo3 method in identifier_for_python macro (#1599) --- nautilus_core/model/src/python/macros.rs | 6 ++++++ nautilus_trader/core/nautilus_pyo3.pyi | 26 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/nautilus_core/model/src/python/macros.rs b/nautilus_core/model/src/python/macros.rs index a341a1995018..dc02099a01f5 100644 --- a/nautilus_core/model/src/python/macros.rs +++ b/nautilus_core/model/src/python/macros.rs @@ -82,6 +82,12 @@ macro_rules! identifier_for_python { fn py_value(&self) -> String { self.to_string() } + + #[staticmethod] + #[pyo3(name = "from_str")] + fn py_from_str(value: &str) -> PyResult { + Self::from_str(value).map_err(to_pyvalue_err) + } } }; } diff --git a/nautilus_trader/core/nautilus_pyo3.pyi b/nautilus_trader/core/nautilus_pyo3.pyi index bdbe7bc6b46d..7f86aa4c525a 100644 --- a/nautilus_trader/core/nautilus_pyo3.pyi +++ b/nautilus_trader/core/nautilus_pyo3.pyi @@ -816,23 +816,33 @@ class LogColor(Enum): class AccountId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> AccountId: ... def value(self) -> str: ... class ClientId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> ClientId: ... def value(self) -> str: ... class ClientOrderId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> ClientOrderId: ... @property def value(self) -> str: ... class ComponentId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> ComponentId: ... def value(self) -> str: ... class ExecAlgorithmId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> ExecAlgorithmId: ... def value(self) -> str: ... class InstrumentId: @@ -847,35 +857,51 @@ class InstrumentId: class OrderListId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> OrderListId: ... def value(self) -> str: ... class PositionId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> PositionId: ... def value(self) -> str: ... class StrategyId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> StrategyId: ... def value(self) -> str: ... class Symbol: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> Symbol: ... @property def value(self) -> str: ... class TradeId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> TradeId: ... def value(self) -> str: ... class TraderId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> TraderId: ... def value(self) -> str: ... class Venue: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> Venue: ... def value(self) -> str: ... class VenueOrderId: def __init__(self, value: str) -> None: ... + @classmethod + def from_str(cls, value: str) -> VenueOrderId: ... def value(self) -> str: ... ### Orders