architect_api/orderflow/
cancel.rs1use crate::OrderId;
2use chrono::{DateTime, Utc};
3use schemars::{JsonSchema, JsonSchema_repr};
4use serde::{Deserialize, Serialize};
5use serde_json::json;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7use serde_with::skip_serializing_none;
8use uuid::Uuid;
9
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
11pub struct Cancel {
12 #[serde(rename = "xid")]
13 pub cancel_id: Uuid,
14 #[serde(rename = "id")]
15 pub order_id: OrderId,
16 #[serde(rename = "ts")]
17 pub recv_time: i64,
18 #[serde(rename = "tn")]
19 pub recv_time_ns: u32,
20 #[serde(rename = "o")]
21 pub status: CancelStatus,
22 #[serde(rename = "r")]
23 pub reject_reason: Option<String>,
24}
25
26impl Cancel {
27 pub fn recv_time(&self) -> Option<DateTime<Utc>> {
28 DateTime::from_timestamp(self.recv_time, self.recv_time_ns)
29 }
30}
31
32#[derive(
33 Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq, JsonSchema_repr,
34)]
35#[serde(rename_all = "snake_case")]
36#[cfg_attr(feature = "juniper", derive(juniper::GraphQLEnum))]
37#[repr(u8)]
38pub enum CancelStatus {
39 Pending = 0,
40 Acked = 1,
41 Rejected = 2,
42 Out = 127,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
46#[cfg_attr(feature = "juniper", derive(juniper::GraphQLObject))]
47pub struct CancelReject {
48 #[serde(rename = "xid")]
49 pub cancel_id: Uuid,
50 #[serde(rename = "id")]
51 pub order_id: OrderId,
52 #[serde(rename = "rm", skip_serializing_if = "Option::is_none")]
53 pub message: Option<String>,
54}
55
56impl CancelReject {
57 pub fn to_error_string(&self) -> String {
58 format!(
59 "cancel {} rejected: {}",
60 self.cancel_id,
61 self.message.as_deref().unwrap_or("--")
62 )
63 }
64}
65
66#[skip_serializing_none]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct CancelUpdate {
69 pub cancel_id: Uuid,
70 pub order_id: OrderId,
71 pub timestamp: i64,
72 pub timestamp_ns: u32,
73 pub status: Option<CancelStatus>,
74 pub reject_reason: Option<String>,
75}
76
77impl CancelUpdate {
78 pub fn timestamp(&self) -> Option<DateTime<Utc>> {
79 DateTime::from_timestamp(self.timestamp, self.timestamp_ns)
80 }
81}