use std::{
any::Any,
fmt::{Debug, Display},
};
use indexmap::IndexMap;
use nautilus_core::{UUID4, UnixNanos};
use nautilus_model::{enums::TradingState, identifiers::TraderId};
use serde::{Deserialize, Serialize};
#[repr(C)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model", from_py_object)
)]
pub struct TradingStateChanged {
pub trader_id: TraderId,
pub state: TradingState,
pub config: IndexMap<String, String>,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
impl TradingStateChanged {
#[must_use]
pub fn new(
trader_id: TraderId,
state: TradingState,
config: IndexMap<String, String>,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> Self {
Self {
trader_id,
state,
config,
event_id,
ts_event,
ts_init,
}
}
pub fn as_any(&self) -> &dyn Any {
self
}
}
impl Display for TradingStateChanged {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}(trader_id={}, state={}, event_id={})",
stringify!(TradingStateChanged),
self.trader_id,
self.state,
self.event_id,
)
}
}