use nautilus_core::Params;
use nautilus_model::{
identifiers::{ClientId, PositionId},
orders::OrderAny,
};
use crate::{BorrowedStr, OwnedBytes, PluginBuildId, PluginResult};
#[doc(hidden)]
pub const EXPERIMENTAL_COMPONENT_ABI_VERSION: u32 = 0;
#[doc(hidden)]
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct ComponentBuildId {
pub metadata: PluginBuildId,
pub package_fingerprint: BorrowedStr<'static>,
}
impl ComponentBuildId {
#[must_use]
pub const fn new(metadata: PluginBuildId, package_fingerprint: BorrowedStr<'static>) -> Self {
Self {
metadata,
package_fingerprint,
}
}
}
#[doc(hidden)]
#[repr(u32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ComponentRole {
DataActor = 1,
Strategy = 2,
ExecutionAlgorithm = 3,
}
impl ComponentRole {
#[must_use]
pub const fn as_u32(self) -> u32 {
self as u32
}
#[must_use]
pub const fn from_u32(value: u32) -> Option<Self> {
match value {
1 => Some(Self::DataActor),
2 => Some(Self::Strategy),
3 => Some(Self::ExecutionAlgorithm),
_ => None,
}
}
}
#[doc(hidden)]
#[repr(C)]
#[derive(Debug)]
pub struct ComponentHostContext {
_opaque: [u8; 0],
}
#[doc(hidden)]
#[repr(C)]
#[derive(Clone, Debug)]
pub struct SubmitOrderCall {
pub order: OrderAny,
pub position_id: Option<PositionId>,
pub client_id: Option<ClientId>,
pub params: Option<Params>,
}
impl SubmitOrderCall {
#[must_use]
pub const fn new(
order: OrderAny,
position_id: Option<PositionId>,
client_id: Option<ClientId>,
params: Option<Params>,
) -> Self {
Self {
order,
position_id,
client_id,
params,
}
}
}
#[doc(hidden)]
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct ComponentHostVTablePrefix {
pub abi_version: u32,
pub struct_size: usize,
pub role: u32,
}
#[doc(hidden)]
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct ComponentHostVTable {
pub abi_version: u32,
pub struct_size: usize,
pub role: u32,
pub build_id: ComponentBuildId,
pub actor_id: Option<
unsafe extern "C" fn(
ctx: *const ComponentHostContext,
generation: u64,
) -> PluginResult<OwnedBytes>,
>,
pub timestamp_ns: Option<
unsafe extern "C" fn(
ctx: *const ComponentHostContext,
generation: u64,
) -> PluginResult<u64>,
>,
pub submit_order: Option<
unsafe extern "C" fn(
ctx: *const ComponentHostContext,
generation: u64,
call: *const SubmitOrderCall,
) -> PluginResult<()>,
>,
}