Emit futures order process events
This commit is contained in:
@@ -2,7 +2,10 @@ use std::collections::BTreeMap;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
|
||||
use crate::events::{AccountEvent, FillEvent, OrderEvent, OrderSide, OrderStatus, PositionEvent};
|
||||
use crate::events::{
|
||||
AccountEvent, FillEvent, OrderEvent, OrderSide, OrderStatus, PositionEvent, ProcessEvent,
|
||||
ProcessEventKind,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum FuturesDirection {
|
||||
@@ -137,6 +140,7 @@ pub struct FuturesExecutionReport {
|
||||
pub fill_events: Vec<FillEvent>,
|
||||
pub position_events: Vec<PositionEvent>,
|
||||
pub account_events: Vec<AccountEvent>,
|
||||
pub process_events: Vec<ProcessEvent>,
|
||||
pub diagnostics: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -514,8 +518,32 @@ impl FuturesAccountState {
|
||||
) -> FuturesExecutionReport {
|
||||
let mut report = FuturesExecutionReport::default();
|
||||
let side = intent.side();
|
||||
push_futures_process_event(
|
||||
&mut report,
|
||||
date,
|
||||
ProcessEventKind::OrderPendingNew,
|
||||
order_id,
|
||||
&intent.symbol,
|
||||
side,
|
||||
format!(
|
||||
"requested_quantity={} direction={} effect={} reason={}",
|
||||
intent.quantity,
|
||||
intent.direction.as_str(),
|
||||
intent.effect.as_str(),
|
||||
intent.reason
|
||||
),
|
||||
);
|
||||
|
||||
if intent.quantity == 0 || !intent.price.is_finite() || intent.price <= 0.0 {
|
||||
push_futures_process_event(
|
||||
&mut report,
|
||||
date,
|
||||
ProcessEventKind::OrderCreationReject,
|
||||
order_id,
|
||||
&intent.symbol,
|
||||
side,
|
||||
"invalid futures order",
|
||||
);
|
||||
report.order_events.push(OrderEvent {
|
||||
date,
|
||||
order_id,
|
||||
@@ -611,6 +639,24 @@ impl FuturesAccountState {
|
||||
intent.effect.as_str()
|
||||
),
|
||||
});
|
||||
push_futures_process_event(
|
||||
&mut report,
|
||||
date,
|
||||
ProcessEventKind::OrderCreationPass,
|
||||
order_id,
|
||||
&intent.symbol,
|
||||
side,
|
||||
"futures order passed account checks",
|
||||
);
|
||||
push_futures_process_event(
|
||||
&mut report,
|
||||
date,
|
||||
ProcessEventKind::Trade,
|
||||
order_id,
|
||||
&intent.symbol,
|
||||
side,
|
||||
format!("filled_quantity={} price={}", intent.quantity, intent.price),
|
||||
);
|
||||
report.position_events.push(PositionEvent {
|
||||
date,
|
||||
symbol: intent.symbol.clone(),
|
||||
@@ -658,6 +704,15 @@ impl FuturesAccountState {
|
||||
});
|
||||
}
|
||||
Err(reason) => {
|
||||
push_futures_process_event(
|
||||
&mut report,
|
||||
date,
|
||||
ProcessEventKind::OrderCreationReject,
|
||||
order_id,
|
||||
&intent.symbol,
|
||||
side,
|
||||
reason.clone(),
|
||||
);
|
||||
report.order_events.push(OrderEvent {
|
||||
date,
|
||||
order_id,
|
||||
@@ -725,6 +780,7 @@ impl FuturesAccountState {
|
||||
combined.fill_events.extend(report.fill_events);
|
||||
combined.position_events.extend(report.position_events);
|
||||
combined.account_events.extend(report.account_events);
|
||||
combined.process_events.extend(report.process_events);
|
||||
combined.diagnostics.extend(report.diagnostics);
|
||||
}
|
||||
combined.diagnostics.push(format!(
|
||||
@@ -759,3 +815,22 @@ impl FuturesAccountState {
|
||||
cash_delta
|
||||
}
|
||||
}
|
||||
|
||||
fn push_futures_process_event(
|
||||
report: &mut FuturesExecutionReport,
|
||||
date: NaiveDate,
|
||||
kind: ProcessEventKind,
|
||||
order_id: Option<u64>,
|
||||
symbol: &str,
|
||||
side: OrderSide,
|
||||
detail: impl Into<String>,
|
||||
) {
|
||||
report.process_events.push(ProcessEvent {
|
||||
date,
|
||||
kind,
|
||||
order_id,
|
||||
symbol: Some(symbol.to_string()),
|
||||
side: Some(side),
|
||||
detail: detail.into(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user