#![allow(unsafe_code)]
use std::ops::Deref;
use nautilus_core::Params;
use nautilus_model::{
identifiers::{ClientId, ClientOrderId},
types::{Price, Quantity},
};
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModifyOrderCommand {
pub client_order_id: ClientOrderId,
pub quantity: Option<Quantity>,
pub price: Option<Price>,
pub trigger_price: Option<Price>,
pub client_id: Option<ClientId>,
pub params: Option<Params>,
}
impl ModifyOrderCommand {
#[must_use]
pub const fn new(
client_order_id: ClientOrderId,
quantity: Option<Quantity>,
price: Option<Price>,
trigger_price: Option<Price>,
client_id: Option<ClientId>,
params: Option<Params>,
) -> Self {
Self {
client_order_id,
quantity,
price,
trigger_price,
client_id,
params,
}
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct ModifyOrderHandle(Box<ModifyOrderCommand>);
impl ModifyOrderHandle {
#[must_use]
pub fn new(command: ModifyOrderCommand) -> Self {
Self(Box::new(command))
}
#[must_use]
pub fn command(&self) -> &ModifyOrderCommand {
&self.0
}
#[must_use]
pub fn into_inner(self) -> ModifyOrderCommand {
*self.0
}
}
impl Deref for ModifyOrderHandle {
type Target = ModifyOrderCommand;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(test)]
mod tests {
use nautilus_model::identifiers::ClientOrderId;
use rstest::rstest;
use super::*;
#[rstest]
fn modify_order_handle_round_trips_command() {
let cmd = ModifyOrderCommand::new(
ClientOrderId::from("O-1"),
Some(Quantity::from("2.5")),
Some(Price::from("100.00")),
None,
None,
None,
);
let handle = ModifyOrderHandle::new(cmd.clone());
assert_eq!(handle.command(), &cmd);
assert_eq!(&*handle, &cmd);
assert_eq!(handle.into_inner(), cmd);
}
}