use std::{
fmt::Debug,
ops::{Deref, DerefMut},
};
use nautilus_common::messages::execution::{
GenerateFillReports, GenerateOrderStatusReport, GenerateOrderStatusReports,
GeneratePositionStatusReports,
};
use nautilus_core::UnixNanos;
use nautilus_model::{
enums::OmsType,
identifiers::{
AccountId, ClientId, ClientOrderId, InstrumentId, StrategyId, Venue, VenueOrderId,
},
instruments::InstrumentAny,
reports::{ExecutionMassStatus, FillReport, OrderStatusReport, PositionStatusReport},
};
pub mod core;
use nautilus_common::clients::ExecutionClient;
pub struct ExecutionClientAdapter {
pub(crate) client: Box<dyn ExecutionClient>,
pub client_id: ClientId,
pub venue: Venue,
pub account_id: AccountId,
pub oms_type: OmsType,
}
impl Deref for ExecutionClientAdapter {
type Target = Box<dyn ExecutionClient>;
fn deref(&self) -> &Self::Target {
&self.client
}
}
impl DerefMut for ExecutionClientAdapter {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.client
}
}
impl Debug for ExecutionClientAdapter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!(ExecutionClientAdapter))
.field("client_id", &self.client_id)
.field("venue", &self.venue)
.field("account_id", &self.account_id)
.field("oms_type", &self.oms_type)
.finish()
}
}
impl ExecutionClientAdapter {
#[must_use]
pub fn new(client: Box<dyn ExecutionClient>) -> Self {
let client_id = client.client_id();
let venue = client.venue();
let account_id = client.account_id();
let oms_type = client.oms_type();
Self {
client,
client_id,
venue,
account_id,
oms_type,
}
}
pub async fn connect(&mut self) -> anyhow::Result<()> {
self.client.connect().await
}
pub async fn disconnect(&mut self) -> anyhow::Result<()> {
self.client.disconnect().await
}
pub async fn generate_order_status_report(
&self,
cmd: &GenerateOrderStatusReport,
) -> anyhow::Result<Option<OrderStatusReport>> {
self.client.generate_order_status_report(cmd).await
}
pub async fn generate_order_status_reports(
&self,
cmd: &GenerateOrderStatusReports,
) -> anyhow::Result<Vec<OrderStatusReport>> {
self.client.generate_order_status_reports(cmd).await
}
pub async fn generate_fill_reports(
&self,
cmd: GenerateFillReports,
) -> anyhow::Result<Vec<FillReport>> {
self.client.generate_fill_reports(cmd).await
}
pub async fn generate_position_status_reports(
&self,
cmd: &GeneratePositionStatusReports,
) -> anyhow::Result<Vec<PositionStatusReport>> {
self.client.generate_position_status_reports(cmd).await
}
pub async fn generate_mass_status(
&self,
lookback_mins: Option<u64>,
) -> anyhow::Result<Option<ExecutionMassStatus>> {
self.client.generate_mass_status(lookback_mins).await
}
pub fn on_instrument(&mut self, instrument: InstrumentAny) {
self.client.on_instrument(instrument);
}
pub fn register_external_order(
&self,
client_order_id: ClientOrderId,
venue_order_id: VenueOrderId,
instrument_id: InstrumentId,
strategy_id: StrategyId,
ts_init: UnixNanos,
) {
self.client.register_external_order(
client_order_id,
venue_order_id,
instrument_id,
strategy_id,
ts_init,
);
}
}