From f28db64dacc14cb262ba605ca31cb0c2d38ff1c6 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 31 May 2026 17:33:45 -0700 Subject: [PATCH] fix(ws): add trigger fields to BasicOrder updates --- src/ws/sub_structs.rs | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/ws/sub_structs.rs b/src/ws/sub_structs.rs index 4c3c94e..0b9382f 100644 --- a/src/ws/sub_structs.rs +++ b/src/ws/sub_structs.rs @@ -24,6 +24,78 @@ pub struct BookLevel { pub n: u64, } +#[cfg(test)] +mod tests { + use super::OrderUpdate; + + #[test] + fn deserialize_order_update_with_trigger_fields() { + let payload = r#"{ + "order": { + "coin": "ETH", + "side": "B", + "limitPx": "2500.0", + "sz": "1.5", + "oid": 42, + "timestamp": 1710000000000, + "triggerCondition": "PriceAbove", + "isTrigger": true, + "triggerPx": "2450.0", + "isPositionTpsl": true, + "reduceOnly": true, + "orderType": "Stop Market", + "origSz": "1.5", + "tif": "Gtc", + "cloid": "0xabc" + }, + "status": "open", + "statusTimestamp": 1710000000010 + }"#; + + let update: OrderUpdate = + serde_json::from_str(payload).expect("order update should deserialize"); + + assert!(update.order.is_trigger); + assert_eq!(update.order.trigger_condition, "PriceAbove"); + assert_eq!(update.order.trigger_px, "2450.0"); + assert!(update.order.is_position_tpsl); + assert!(update.order.reduce_only); + assert_eq!(update.order.order_type, "Stop Market"); + assert_eq!(update.order.tif.as_deref(), Some("Gtc")); + } + + #[test] + fn deserialize_order_update_with_null_tif() { + let payload = r#"{ + "order": { + "coin": "ETH", + "side": "A", + "limitPx": "2500.0", + "sz": "1.5", + "oid": 43, + "timestamp": 1710000000100, + "triggerCondition": "", + "isTrigger": false, + "triggerPx": "0.0", + "isPositionTpsl": false, + "reduceOnly": false, + "orderType": "Limit", + "origSz": "1.5", + "tif": null, + "cloid": null + }, + "status": "filled", + "statusTimestamp": 1710000000110 + }"#; + + let update: OrderUpdate = + serde_json::from_str(payload).expect("order update with null tif should deserialize"); + + assert_eq!(update.order.tif, None); + assert!(!update.order.is_trigger); + } +} + #[derive(Deserialize, Clone, Debug)] pub struct L2BookData { pub coin: String, @@ -129,7 +201,14 @@ pub struct BasicOrder { pub sz: String, pub oid: u64, pub timestamp: u64, + pub trigger_condition: String, + pub is_trigger: bool, + pub trigger_px: String, + pub is_position_tpsl: bool, + pub reduce_only: bool, + pub order_type: String, pub orig_sz: String, + pub tif: Option, pub cloid: Option, }