use std::ffi::c_char;
use nautilus_core::{UUID4, UnixNanos, ffi::string::cstr_to_ustr};
use ustr::Ustr;
use crate::{
identifiers::{AccountId, ClientOrderId, InstrumentId, StrategyId, TraderId, VenueOrderId},
types::Price,
};
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderDeniedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub reason: Ustr,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderEmulatedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderReleasedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub released_price: Price,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderSubmittedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub account_id: AccountId,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderAcceptedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub venue_order_id: VenueOrderId,
pub account_id: AccountId,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
pub reconciliation: u8,
}
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct OrderRejectedFfi {
pub trader_id: TraderId,
pub strategy_id: StrategyId,
pub instrument_id: InstrumentId,
pub client_order_id: ClientOrderId,
pub account_id: AccountId,
pub reason: Ustr,
pub event_id: UUID4,
pub ts_event: UnixNanos,
pub ts_init: UnixNanos,
pub reconciliation: u8,
pub due_post_only: u8,
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn order_denied_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
reason_ptr: *const c_char,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderDeniedFfi {
OrderDeniedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
reason: unsafe { cstr_to_ustr(reason_ptr) },
event_id,
ts_event,
ts_init,
}
}
#[unsafe(no_mangle)]
pub extern "C" fn order_emulated_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderEmulatedFfi {
OrderEmulatedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
event_id,
ts_event,
ts_init,
}
}
#[unsafe(no_mangle)]
pub extern "C" fn order_released_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
released_price: Price,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderReleasedFfi {
OrderReleasedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
released_price,
event_id,
ts_event,
ts_init,
}
}
#[unsafe(no_mangle)]
pub extern "C" fn order_submitted_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
account_id: AccountId,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
) -> OrderSubmittedFfi {
OrderSubmittedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
account_id,
event_id,
ts_event,
ts_init,
}
}
#[unsafe(no_mangle)]
pub extern "C" fn order_accepted_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
venue_order_id: VenueOrderId,
account_id: AccountId,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
reconciliation: u8,
) -> OrderAcceptedFfi {
OrderAcceptedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
venue_order_id,
account_id,
event_id,
ts_event,
ts_init,
reconciliation,
}
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn order_rejected_new(
trader_id: TraderId,
strategy_id: StrategyId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
account_id: AccountId,
reason_ptr: *const c_char,
event_id: UUID4,
ts_event: UnixNanos,
ts_init: UnixNanos,
reconciliation: u8,
due_post_only: u8,
) -> OrderRejectedFfi {
OrderRejectedFfi {
trader_id,
strategy_id,
instrument_id,
client_order_id,
account_id,
reason: unsafe { cstr_to_ustr(reason_ptr) },
event_id,
ts_event,
ts_init,
reconciliation,
due_post_only,
}
}