obrewin_data_structures/
order.rs1use serde::{Deserialize, Serialize};
2
3use crate::market::{Price, Quantity};
4use crate::misc::DateTimeUTC;
5
6pub type OrderID = String;
8
9pub type Symbol = String;
11
12#[derive(Clone, Serialize)]
14pub enum OrderContent {
15 NewDirect { price: Price, quantity: Quantity },
18
19 NewMarket { quantity: Quantity },
22
23 Cancel { original_client_order_id: OrderID },
25}
26
27#[derive(Clone, Serialize)]
29pub enum TimeInForce {
30 GTC { expiration_time: DateTimeUTC },
32 IoC,
34 FoK,
36}
37
38#[derive(Clone, Serialize)]
40pub struct OrderRequest {
41 pub content: OrderContent,
43 pub symbol: Symbol,
45 pub client_order_id: OrderID,
47}
48
49#[derive(Clone, Deserialize)]
51pub enum OrderResponseStatus {
52 Ok,
53 Filled {
54 executed_price: Price,
55 executed_quantity: Quantity,
56 },
57 Rejected {
58 code: Option<i32>,
59 message: Option<String>,
60 },
61}
62
63#[derive(Clone, Deserialize)]
65pub struct OrderResponse {
66 pub status: OrderResponseStatus,
67 pub client_order_id: OrderID,
69}
70
71impl OrderResponse {
72 pub fn notional_value(&self) -> Quantity {
74 match self.status {
75 OrderResponseStatus::Filled {
76 executed_price,
77 executed_quantity,
78 } => executed_price * executed_quantity,
79 _ => Quantity::ZERO,
80 }
81 }
82}