#![allow(unsafe_code)]
use std::ops::Deref;
use nautilus_core::Params;
use nautilus_model::identifiers::{AccountId, ClientId, ClientOrderId};
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryAccountCommand {
pub account_id: AccountId,
pub client_id: Option<ClientId>,
pub params: Option<Params>,
}
impl QueryAccountCommand {
#[must_use]
pub const fn new(
account_id: AccountId,
client_id: Option<ClientId>,
params: Option<Params>,
) -> Self {
Self {
account_id,
client_id,
params,
}
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QueryAccountHandle(Box<QueryAccountCommand>);
impl QueryAccountHandle {
#[must_use]
pub fn new(command: QueryAccountCommand) -> Self {
Self(Box::new(command))
}
#[must_use]
pub fn command(&self) -> &QueryAccountCommand {
&self.0
}
#[must_use]
pub fn into_inner(self) -> QueryAccountCommand {
*self.0
}
}
impl Deref for QueryAccountHandle {
type Target = QueryAccountCommand;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[repr(C)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryOrderCommand {
pub client_order_id: ClientOrderId,
pub client_id: Option<ClientId>,
pub params: Option<Params>,
}
impl QueryOrderCommand {
#[must_use]
pub const fn new(
client_order_id: ClientOrderId,
client_id: Option<ClientId>,
params: Option<Params>,
) -> Self {
Self {
client_order_id,
client_id,
params,
}
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct QueryOrderHandle(Box<QueryOrderCommand>);
impl QueryOrderHandle {
#[must_use]
pub fn new(command: QueryOrderCommand) -> Self {
Self(Box::new(command))
}
#[must_use]
pub fn command(&self) -> &QueryOrderCommand {
&self.0
}
#[must_use]
pub fn into_inner(self) -> QueryOrderCommand {
*self.0
}
}
impl Deref for QueryOrderHandle {
type Target = QueryOrderCommand;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
fn query_account_handle_round_trips_command() {
let cmd = QueryAccountCommand::new(AccountId::from("BINANCE-001"), None, None);
let handle = QueryAccountHandle::new(cmd.clone());
assert_eq!(handle.command(), &cmd);
assert_eq!(&*handle, &cmd);
assert_eq!(handle.into_inner(), cmd);
}
#[rstest]
fn query_order_handle_round_trips_command() {
let cmd = QueryOrderCommand::new(ClientOrderId::from("O-1"), None, None);
let handle = QueryOrderHandle::new(cmd.clone());
assert_eq!(handle.command(), &cmd);
assert_eq!(&*handle, &cmd);
assert_eq!(handle.into_inner(), cmd);
}
}