use std::str::FromStr;
use nautilus_core::python::to_pyvalue_err;
use pyo3::{PyTypeInfo, prelude::*, types::PyType};
use crate::{
defi::{
chain::Blockchain,
data::PoolLiquidityUpdateType,
dex::{AmmType, DexType},
},
python::common::EnumIterator,
};
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl Blockchain {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
const fn __hash__(&self) -> isize {
*self as isize
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn value(&self) -> u8 {
*self as u8
}
#[classmethod]
fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
EnumIterator::new::<Self>(py)
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: &str = data.extract()?;
let tokenized = data_str.to_uppercase();
Self::from_str(&tokenized).map_err(to_pyvalue_err)
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl AmmType {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
const fn __hash__(&self) -> isize {
*self as isize
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn value(&self) -> u8 {
*self as u8
}
#[classmethod]
fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
EnumIterator::new::<Self>(py)
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: &str = data.extract()?;
Self::from_str(data_str).map_err(to_pyvalue_err)
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl DexType {
const fn __hash__(&self) -> isize {
*self as isize
}
}
#[pymethods]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
impl PoolLiquidityUpdateType {
#[new]
fn py_new(py: Python<'_>, value: &Bound<'_, PyAny>) -> PyResult<Self> {
let t = Self::type_object(py);
Self::py_from_str(&t, value)
}
const fn __hash__(&self) -> isize {
*self as isize
}
fn __str__(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn name(&self) -> String {
self.to_string()
}
#[getter]
#[must_use]
pub fn value(&self) -> u8 {
*self as u8
}
#[classmethod]
fn variants(_: &Bound<'_, PyType>, py: Python<'_>) -> EnumIterator {
EnumIterator::new::<Self>(py)
}
#[classmethod]
#[pyo3(name = "from_str")]
fn py_from_str(_: &Bound<'_, PyType>, data: &Bound<'_, PyAny>) -> PyResult<Self> {
let data_str: &str = data.extract()?;
Self::from_str(data_str).map_err(to_pyvalue_err)
}
}