tradestation_rs/responses/
execution.rs

1use crate::{
2    execution::{ActivationTrigger, Order, OrderConfirmation},
3    Error, Route,
4};
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, Deserialize, Serialize)]
8#[serde(rename_all = "PascalCase")]
9/// The TradeStation API Response for confirming
10/// an order, but not actually placing it.
11pub struct OrderRespRaw {
12    /// The orders modified, placed, or canceled.
13    orders: Option<Vec<Order>>,
14
15    /// The error type from TradeStation's API
16    ///
17    /// NOTE: Will be None if there was no error
18    error: Option<String>,
19
20    /// The error message from TradeStation's API
21    ///
22    /// NOTE: Will be None if there was no error
23    message: Option<String>,
24}
25#[derive(Debug)]
26/// The TradeStation API Response for confirming
27/// an order, but not actually placing it.
28pub struct OrderResp {
29    /// The order confirmations.
30    pub orders: Option<Vec<Order>>,
31
32    /// The error from TradeStation's API.
33    ///
34    /// NOTE: Will be None if there was no error.
35    pub error: Option<Error>,
36}
37impl From<OrderRespRaw> for OrderResp {
38    fn from(raw: OrderRespRaw) -> Self {
39        let error_enum =
40            if let (Some(err), Some(msg)) = (raw.error.as_deref(), raw.message.as_deref()) {
41                Error::from_tradestation_api_error(err, msg)
42            } else {
43                None
44            };
45
46        OrderResp {
47            orders: raw.orders,
48            error: error_enum,
49        }
50    }
51}
52
53#[derive(Clone, Debug, Deserialize, Serialize)]
54#[serde(rename_all = "PascalCase")]
55/// The TradeStation API Response for confirming
56/// an order, but not actually placing it.
57pub struct ConfirmOrderRespRaw {
58    /// The order confirmations.
59    confirmations: Option<Vec<OrderConfirmation>>,
60    /// The error type from TradeStation's API
61    ///
62    /// NOTE: Will be None if there was no error
63    error: Option<String>,
64    /// The error message from TradeStation's API
65    ///
66    /// NOTE: Will be None if there was no error
67    message: Option<String>,
68}
69#[derive(Debug)]
70/// The TradeStation API Response for confirming
71/// an order, but not actually placing it.
72pub struct ConfirmOrderResp {
73    /// The order confirmations.
74    pub confirmations: Option<Vec<OrderConfirmation>>,
75    /// The error from TradeStation's API.
76    ///
77    /// NOTE: Will be None if there was no error.
78    pub error: Option<Error>,
79}
80impl From<ConfirmOrderRespRaw> for ConfirmOrderResp {
81    fn from(raw: ConfirmOrderRespRaw) -> Self {
82        let error_enum =
83            if let (Some(err), Some(msg)) = (raw.error.as_deref(), raw.message.as_deref()) {
84                Error::from_tradestation_api_error(err, msg)
85            } else {
86                None
87            };
88
89        ConfirmOrderResp {
90            confirmations: raw.confirmations,
91            error: error_enum,
92        }
93    }
94}
95
96#[derive(Clone, Debug, Deserialize, Serialize)]
97#[serde(rename_all = "PascalCase")]
98/// The TradeStation API Response for running risk vs reward
99/// analysis on an options trade.
100pub struct GetExecutionRoutesRespRaw {
101    routes: Option<Vec<Route>>,
102    /// The error type from TradeStation's API
103    ///
104    /// NOTE: Will be None if there was no error
105    error: Option<String>,
106    /// The error message from TradeStation's API
107    ///
108    /// NOTE: Will be None if there was no error
109    message: Option<String>,
110}
111#[derive(Debug)]
112/// The TradeStation API Response for fetching symbol details.
113pub struct GetExecutionRoutesResp {
114    /// The option expirations for a symbol.
115    pub routes: Option<Vec<Route>>,
116    /// The error from TradeStation's API.
117    ///
118    /// NOTE: Will be None if there was no error.
119    pub error: Option<Error>,
120}
121impl From<GetExecutionRoutesRespRaw> for GetExecutionRoutesResp {
122    fn from(raw: GetExecutionRoutesRespRaw) -> Self {
123        let error_enum =
124            if let (Some(err), Some(msg)) = (raw.error.as_deref(), raw.message.as_deref()) {
125                Error::from_tradestation_api_error(err, msg)
126            } else {
127                None
128            };
129
130        GetExecutionRoutesResp {
131            routes: raw.routes,
132            error: error_enum,
133        }
134    }
135}
136
137#[derive(Clone, Debug, Deserialize, Serialize)]
138#[serde(rename_all = "PascalCase")]
139/// The TradeStation API Response for fetching valid
140/// activation triggers and their corresponding key.
141pub struct GetActivationTriggersRespRaw {
142    /// Activation Triggers.
143    activation_triggers: Option<Vec<ActivationTrigger>>,
144
145    /// The error type from TradeStation's API.
146    ///
147    /// NOTE: Will be None if there was no error.
148    error: Option<String>,
149
150    /// The error message from TradeStation's API.
151    ///
152    /// NOTE: Will be None if there was no error.
153    message: Option<String>,
154}
155#[derive(Debug)]
156/// The TradeStation API Response for fetching symbol details.
157pub struct GetActivationTriggersResp {
158    /// The Activation Triggers.
159    pub activation_triggers: Option<Vec<ActivationTrigger>>,
160
161    /// The error from TradeStation's API.
162    ///
163    /// NOTE: Will be None if there was no error.
164    pub error: Option<Error>,
165}
166impl From<GetActivationTriggersRespRaw> for GetActivationTriggersResp {
167    fn from(raw: GetActivationTriggersRespRaw) -> Self {
168        let error_enum =
169            if let (Some(err), Some(msg)) = (raw.error.as_deref(), raw.message.as_deref()) {
170                Error::from_tradestation_api_error(err, msg)
171            } else {
172                None
173            };
174
175        GetActivationTriggersResp {
176            activation_triggers: raw.activation_triggers,
177            error: error_enum,
178        }
179    }
180}