ig_client/presentation/order.rs
1/******************************************************************************
2 Author: Joaquín Béjar García
3 Email: jb@taunais.com
4 Date: 13/5/25
5******************************************************************************/
6use pretty_simple_display::DisplaySimple;
7use serde::{Deserialize, Serialize};
8
9/// Order direction (buy or sell)
10#[repr(u8)]
11#[derive(
12 Debug, Clone, Copy, DisplaySimple, Serialize, Deserialize, PartialEq, Eq, Hash, Default,
13)]
14#[serde(rename_all = "UPPERCASE")]
15pub enum Direction {
16 /// Buy direction (long position)
17 #[default]
18 Buy,
19 /// Sell direction (short position)
20 Sell,
21}
22
23/// Order type
24#[repr(u8)]
25#[derive(
26 Debug, Clone, Copy, DisplaySimple, Serialize, Deserialize, PartialEq, Eq, Hash, Default,
27)]
28#[serde(rename_all = "UPPERCASE")]
29pub enum OrderType {
30 /// Limit order - executed when price reaches specified level
31 #[default]
32 Limit,
33 /// Market order - executed immediately at current market price
34 Market,
35 /// Quote order - executed at quoted price
36 Quote,
37 /// Stop order - becomes market order when price reaches specified level
38 Stop,
39 /// Stop limit order - becomes limit order when price reaches specified level
40 StopLimit,
41}
42
43/// Represents the status of an order or transaction in the system.
44///
45/// This enum covers various states an order can be in throughout its lifecycle,
46/// from creation to completion or cancellation.
47#[repr(u8)]
48#[derive(
49 Debug, Clone, Copy, DisplaySimple, Serialize, Deserialize, PartialEq, Eq, Hash, Default,
50)]
51#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
52pub enum Status {
53 /// Order has been amended or modified after initial creation
54 Amended,
55 /// Order has been deleted from the system
56 Deleted,
57 /// Order has been completely closed with all positions resolved
58 FullyClosed,
59 /// Order has been opened and is active in the market
60 Opened,
61 /// Order has been partially closed with some positions still open
62 PartiallyClosed,
63 /// Order has been closed but may differ from FullyClosed in context
64 Closed,
65 /// Default state - order is open and active in the market
66 #[default]
67 Open,
68 /// Order has been updated with new parameters
69 Updated,
70 /// Order has been accepted by the system or exchange
71 Accepted,
72 /// Order has been rejected by the system or exchange
73 Rejected,
74 /// Order is currently working (waiting to be filled)
75 Working,
76 /// Order has been filled (executed)
77 Filled,
78 /// Order has been cancelled
79 Cancelled,
80 /// Order has expired (time in force elapsed)
81 Expired,
82}
83
84/// Order duration (time in force)
85#[repr(u8)]
86#[derive(
87 Debug, Clone, Copy, DisplaySimple, Serialize, Deserialize, PartialEq, Eq, Hash, Default,
88)]
89#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
90pub enum TimeInForce {
91 /// Order remains valid until cancelled by the client
92 #[default]
93 GoodTillCancelled,
94 /// Order remains valid until a specified date
95 GoodTillDate,
96 /// Order is executed immediately (partially or completely) or cancelled.
97 ///
98 /// Note: `IMMEDIATE_OR_CANCEL` is not a documented value for IG's OTC
99 /// `timeInForce`; it is retained for backward compatibility. Prefer
100 /// [`TimeInForce::ExecuteAndEliminate`] for partial-fill-then-cancel
101 /// semantics on OTC create/close position endpoints.
102 ImmediateOrCancel,
103 /// Order must be filled completely immediately or cancelled.
104 ///
105 /// Serializes to `FILL_OR_KILL`.
106 FillOrKill,
107 /// Order fills as much as possible immediately, then cancels the remainder.
108 ///
109 /// Serializes to `EXECUTE_AND_ELIMINATE`. Accepted alongside
110 /// [`TimeInForce::FillOrKill`] by IG's OTC create/close position endpoints.
111 ExecuteAndEliminate,
112}