use std::{cell::RefCell, rc::Rc};
use async_trait::async_trait;
use nautilus_common::{
cache::Cache,
clients::ExecutionClient,
clock::{Clock, TestClock},
messages::execution::{
BatchCancelOrders, CancelAllOrders, CancelOrder, ModifyOrder, QueryAccount, QueryOrder,
SubmitOrder, SubmitOrderList,
},
};
use nautilus_core::UnixNanos;
use nautilus_model::{
accounts::AccountAny,
enums::OmsType,
identifiers::{AccountId, ClientId, Venue},
types::{AccountBalance, MarginBalance},
};
#[derive(Clone, Debug)]
#[allow(dead_code)]
pub struct StubExecutionClient {
client_id: ClientId,
account_id: AccountId,
venue: Venue,
oms_type: OmsType,
is_connected: bool,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
}
impl StubExecutionClient {
#[allow(dead_code)]
pub fn new(
client_id: ClientId,
account_id: AccountId,
venue: Venue,
oms_type: OmsType,
clock: Option<Rc<RefCell<dyn Clock>>>,
) -> Self {
Self {
client_id,
account_id,
venue,
oms_type,
is_connected: false,
clock: clock.unwrap_or_else(|| Rc::new(RefCell::new(TestClock::new()))),
cache: Rc::new(RefCell::new(Cache::new(None, None))),
}
}
}
#[async_trait(?Send)]
impl ExecutionClient for StubExecutionClient {
fn is_connected(&self) -> bool {
self.is_connected
}
fn client_id(&self) -> ClientId {
self.client_id
}
fn account_id(&self) -> AccountId {
self.account_id
}
fn venue(&self) -> Venue {
self.venue
}
fn oms_type(&self) -> OmsType {
self.oms_type
}
fn get_account(&self) -> Option<AccountAny> {
None }
fn generate_account_state(
&self,
_balances: Vec<AccountBalance>,
_margins: Vec<MarginBalance>,
_reported: bool,
_ts_event: UnixNanos,
) -> anyhow::Result<()> {
Ok(()) }
fn start(&mut self) -> anyhow::Result<()> {
self.is_connected = true;
Ok(())
}
fn stop(&mut self) -> anyhow::Result<()> {
self.is_connected = false;
Ok(())
}
fn submit_order(&self, _cmd: SubmitOrder) -> anyhow::Result<()> {
Ok(()) }
fn submit_order_list(&self, _cmd: SubmitOrderList) -> anyhow::Result<()> {
Ok(()) }
fn modify_order(&self, _cmd: ModifyOrder) -> anyhow::Result<()> {
Ok(()) }
fn cancel_order(&self, _cmd: CancelOrder) -> anyhow::Result<()> {
Ok(()) }
fn cancel_all_orders(&self, _cmd: CancelAllOrders) -> anyhow::Result<()> {
Ok(()) }
fn batch_cancel_orders(&self, _cmd: BatchCancelOrders) -> anyhow::Result<()> {
Ok(()) }
fn query_account(&self, _cmd: QueryAccount) -> anyhow::Result<()> {
Ok(()) }
fn query_order(&self, _cmd: QueryOrder) -> anyhow::Result<()> {
Ok(()) }
}