use std::str::FromStr;
use nautilus_core::python::to_pyvalue_err;
use pyo3::{PyTypeInfo, prelude::*, types::PyType};
use strum::IntoEnumIterator;
use crate::common::enums::{
HyperliquidConditionalOrderType, HyperliquidProductType, HyperliquidTpSl,
HyperliquidTrailingOffsetType,
};
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl HyperliquidTpSl {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
fn __hash__(&self) -> isize {
*self as isize
}
fn __repr__(&self) -> String {
format!(
"<{}.{}: '{}'>",
stringify!(HyperliquidTpSl),
self.name(),
self.value(),
)
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> &str {
self.as_ref()
}
#[getter]
#[must_use]
pub fn value(&self) -> String {
self.to_string().to_lowercase()
}
#[staticmethod]
#[must_use]
fn variants() -> Vec<String> {
Self::iter().map(|x| x.to_string()).collect()
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: String = data.str()?.extract()?;
Self::from_str(&data_str).map_err(to_pyvalue_err)
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl HyperliquidConditionalOrderType {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
fn __hash__(&self) -> isize {
*self as isize
}
fn __repr__(&self) -> String {
format!(
"<{}.{}: '{}'>",
stringify!(HyperliquidConditionalOrderType),
self.name(),
self.value(),
)
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> &str {
self.as_ref()
}
#[getter]
#[must_use]
pub fn value(&self) -> String {
self.to_string().to_lowercase()
}
#[staticmethod]
#[must_use]
fn variants() -> Vec<String> {
Self::iter().map(|x| x.to_string()).collect()
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: String = data.str()?.extract()?;
Self::from_str(&data_str).map_err(to_pyvalue_err)
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl HyperliquidTrailingOffsetType {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
fn __hash__(&self) -> isize {
*self as isize
}
fn __repr__(&self) -> String {
format!(
"<{}.{}: '{}'>",
stringify!(HyperliquidTrailingOffsetType),
self.name(),
self.value(),
)
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> &str {
self.as_ref()
}
#[getter]
#[must_use]
pub fn value(&self) -> String {
self.to_string().to_lowercase()
}
#[staticmethod]
#[must_use]
fn variants() -> Vec<String> {
Self::iter().map(|x| x.to_string()).collect()
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: String = data.str()?.extract()?;
Self::from_str(&data_str).map_err(to_pyvalue_err)
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl HyperliquidProductType {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
fn __hash__(&self) -> isize {
*self as isize
}
fn __eq__(&self, other: &Self) -> bool {
self == other
}
fn __repr__(&self) -> String {
format!(
"<{}.{}: '{}'>",
stringify!(HyperliquidProductType),
self.name(),
self.value(),
)
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> &str {
self.as_ref()
}
#[getter]
#[must_use]
pub fn value(&self) -> String {
self.to_string()
}
#[staticmethod]
#[must_use]
fn variants() -> Vec<String> {
Self::iter().map(|x| x.to_string()).collect()
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_cls: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: String = data.str()?.extract()?;
Self::from_str(&data_str).map_err(to_pyvalue_err)
}
}