Skip to main content

hypercall_db/types/
orders.rs

1//! Order types.
2//!
3//! Domain records and input structs for orders, order actions, and fill
4//! side effects.
5
6use chrono::NaiveDateTime;
7use hypercall_types::{OrderStatus, Side, TimeInForce, WalletAddress};
8use rust_decimal::Decimal;
9use serde::{Deserialize, Serialize};
10
11/// Materialized order state: static order metadata merged with the latest
12/// status from the order update stream.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct OrderInfoRecord {
15    pub order_id: i64,
16    pub wallet_address: WalletAddress,
17    pub symbol: String,
18    pub side: Side,
19    pub price: Decimal,
20    pub size: Decimal,
21    pub tif: TimeInForce,
22    pub client_id: Option<String>,
23    pub is_perp: bool,
24    pub underlying: Option<String>,
25    pub reduce_only: Option<bool>,
26    pub nonce: Option<i64>,
27    pub signature: Option<String>,
28    pub mmp_enabled: bool,
29    /// Millisecond timestamp from the engine.
30    pub timestamp: i64,
31    pub status: OrderStatus,
32    pub filled_size: Decimal,
33    pub created_at: Option<NaiveDateTime>,
34    pub updated_at: NaiveDateTime,
35}
36
37/// Input for persisting static order info (upsert on order_id).
38/// The Diesel adapter converts enums to DB strings at the boundary.
39#[derive(Debug, Clone)]
40pub struct PersistOrderInfo {
41    pub order_id: i64,
42    pub wallet_address: WalletAddress,
43    pub symbol: String,
44    pub side: Side,
45    pub price: Decimal,
46    pub size: Decimal,
47    pub tif: TimeInForce,
48    pub client_id: Option<String>,
49    pub is_perp: bool,
50    pub underlying: Option<String>,
51    pub reduce_only: Option<bool>,
52    pub nonce: Option<i64>,
53    pub signature: Option<String>,
54    pub mmp_enabled: bool,
55    pub timestamp: i64,
56}
57
58/// Input for persisting an order action audit trail entry.
59/// The Diesel adapter converts enums to DB strings at the boundary.
60#[derive(Debug, Clone)]
61pub struct PersistOrderAction {
62    pub timestamp: i64,
63    pub wallet: WalletAddress,
64    pub action: String,
65    pub symbol: String,
66    pub price: Decimal,
67    pub size: Decimal,
68    pub side: Side,
69    pub tif: TimeInForce,
70    pub client_id: Option<String>,
71}
72
73/// Side effects for atomic fill persistence (fill + trade + ledger).
74#[derive(Debug, Clone)]
75pub struct FillSideEffects {
76    pub trade_id: u64,
77    pub taker_ledger_delta: Decimal,
78    pub maker_ledger_delta: Decimal,
79    pub taker_premium_delta: Decimal,
80    pub maker_premium_delta: Decimal,
81    pub underlying_notional: Option<Decimal>,
82}