1use serde::{Deserialize, Serialize};
2
3pub mod order_action {
4 pub const BUY: &str = "ORDER_ACTION_BUY";
5 pub const SELL: &str = "ORDER_ACTION_SELL";
6}
7
8pub mod order_type {
9 pub const LIMIT: &str = "ORDER_TYPE_LIMIT";
10}
11
12pub mod tif {
13 pub const GTC: &str = "TIME_IN_FORCE_GOOD_TILL_CANCEL";
14 pub const GTD: &str = "TIME_IN_FORCE_GOOD_TILL_DATE";
15 pub const FAK: &str = "TIME_IN_FORCE_IMMEDIATE_OR_CANCEL";
16 pub const FOK: &str = "TIME_IN_FORCE_FILL_OR_KILL";
17}
18
19pub mod outcome {
20 pub const LONG: &str = "LONG";
21 pub const SHORT: &str = "SHORT";
22}
23
24#[derive(Debug, Clone, Deserialize)]
25pub struct HealthResponse {
26 #[serde(default)]
27 pub status: String,
28 #[serde(default)]
29 pub timestamp: String,
30}
31
32#[derive(Debug, Clone, Deserialize)]
33pub struct MarketsResponse {
34 #[serde(default)]
35 pub markets: Vec<UsMarket>,
36}
37
38#[derive(Debug, Clone, Deserialize)]
39pub struct UsMarket {
40 #[serde(default)]
41 pub id: String,
42 #[serde(default)]
43 pub slug: String,
44 #[serde(default)]
45 pub question: String,
46 #[serde(default)]
47 pub status: String,
48 #[serde(default)]
49 pub category: String,
50 #[serde(default, rename = "startDate")]
51 pub start_date: String,
52 #[serde(default, rename = "endDate")]
53 pub end_date: String,
54 #[serde(default)]
55 pub description: String,
56 #[serde(default)]
57 pub active: bool,
58 #[serde(default)]
59 pub closed: bool,
60 #[serde(default, rename = "marketType")]
61 pub market_type: String,
62 #[serde(default, rename = "marketSides")]
63 pub market_sides: Vec<serde_json::Value>,
64 #[serde(default)]
65 pub instruments: Vec<serde_json::Value>,
66 #[serde(default)]
67 pub outcomes: Vec<serde_json::Value>,
68}
69
70#[derive(Debug, Clone, Deserialize)]
71pub struct MarketSide {
72 #[serde(default)]
73 pub id: String,
74 #[serde(default)]
75 pub identifier: String,
76 #[serde(default)]
77 pub description: String,
78 #[serde(default)]
79 pub price: String,
80 #[serde(default)]
81 pub long: bool,
82 #[serde(default, rename = "marketSideType")]
83 pub market_side_type: String,
84 #[serde(default)]
85 pub team: Option<serde_json::Value>,
86 #[serde(default)]
87 pub player: Option<serde_json::Value>,
88 #[serde(flatten)]
89 pub extra: std::collections::HashMap<String, serde_json::Value>,
90}
91
92#[derive(Debug, Clone, Serialize)]
93pub struct PlaceOrderRequest {
94 pub symbol: String,
95 pub action: String,
96 #[serde(rename = "outcomeSide")]
97 pub outcome_side: String,
98 #[serde(rename = "type")]
99 pub order_type: String,
100 pub price: Money,
101 pub quantity: u64,
102 pub tif: String,
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub client_order_id: Option<String>,
105 #[serde(skip_serializing_if = "std::ops::Not::not")]
106 pub post_only: bool,
107 #[serde(skip_serializing_if = "Option::is_none")]
108 pub expires_at: Option<u64>,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct Money {
113 pub value: String,
114 pub currency: String,
115}
116
117#[derive(Debug, Clone, Deserialize)]
118pub struct PlaceOrderResponse {
119 pub order_id: String,
120 #[serde(default)]
121 pub client_order_id: Option<String>,
122 #[serde(default)]
123 pub status: String,
124 #[serde(default)]
125 pub filled_quantity: u64,
126 #[serde(default)]
127 pub remaining_quantity: u64,
128 #[serde(default)]
129 pub created_at: String,
130}
131
132#[derive(Debug, Clone, Serialize)]
133pub struct BatchedOrderRequest {
134 pub orders: Vec<PlaceOrderRequest>,
135 pub atomic: bool,
136}
137
138#[derive(Debug, Clone, Deserialize)]
139pub struct BatchedOrderResponse {
140 #[serde(default)]
141 pub orders: Vec<PlaceOrderResponse>,
142}
143
144#[derive(Debug, Clone, Deserialize)]
145pub struct CancelOrderResponse {
146 pub order_id: String,
147 #[serde(default)]
148 pub status: String,
149 #[serde(default)]
150 pub cancelled_at: Option<String>,
151}
152
153#[derive(Debug, Clone, Deserialize)]
154pub struct PortfolioPositionsResponse {
155 #[serde(default)]
156 pub positions: std::collections::HashMap<String, UsPosition>,
157 #[serde(default)]
158 pub next_cursor: String,
159 #[serde(default)]
160 pub eof: bool,
161 #[serde(default, rename = "availablePositions")]
162 pub available_positions: Vec<UsPosition>,
163}
164
165#[derive(Debug, Clone, Deserialize)]
166pub struct UsPosition {
167 #[serde(default)]
168 pub symbol: String,
169 #[serde(default)]
170 pub quantity: i64,
171 #[serde(default, rename = "avgEntryPrice")]
172 pub avg_entry_price: String,
173 #[serde(default, rename = "unrealizedPnl")]
174 pub unrealized_pnl: Option<String>,
175}
176
177#[derive(Debug, Clone, Deserialize)]
178pub struct PortfolioActivitiesResponse {
179 #[serde(default)]
180 pub activities: Vec<serde_json::Value>,
181 #[serde(default)]
182 pub next_cursor: Option<String>,
183}
184
185#[derive(Debug, Clone, Deserialize)]
186pub struct AccountBalancesResponse {
187 #[serde(default)]
188 pub balances: Vec<UserBalance>,
189}
190
191#[derive(Debug, Clone, Deserialize)]
192pub struct UserBalance {
193 #[serde(default, rename = "currentBalance")]
194 pub current_balance: f64,
195 #[serde(default)]
196 pub currency: String,
197 #[serde(default, rename = "lastUpdated")]
198 pub last_updated: Option<String>,
199 #[serde(default, rename = "buyingPower")]
200 pub buying_power: f64,
201 #[serde(default, rename = "assetNotional")]
202 pub asset_notional: Option<f64>,
203 #[serde(default, rename = "assetAvailable")]
204 pub asset_available: Option<f64>,
205 #[serde(default, rename = "pendingCredit")]
206 pub pending_credit: Option<f64>,
207 #[serde(default, rename = "openOrders")]
208 pub open_orders: Option<f64>,
209 #[serde(default, rename = "unsettledFunds")]
210 pub unsettled_funds: Option<f64>,
211 #[serde(default, rename = "marginRequirement")]
212 pub margin_requirement: Option<f64>,
213 #[serde(default, rename = "balanceReservation")]
214 pub balance_reservation: Option<f64>,
215}
216
217#[derive(Debug, Clone, Serialize, Default)]
218pub struct CancelOrderParams {
219 #[serde(skip_serializing_if = "Option::is_none")]
220 pub quantity: Option<u64>,
221}
222
223#[derive(Debug, Clone, Serialize, Default)]
224pub struct CancelAllOrdersParams {
225 #[serde(skip_serializing_if = "Option::is_none")]
226 pub symbol: Option<String>,
227}
228
229#[derive(Debug, Clone, Deserialize)]
230pub struct CancelAllOrdersResponse {
231 #[serde(default)]
232 pub cancelled: Vec<String>,
233}
234
235#[derive(Debug, Clone, Serialize)]
236pub struct ModifyOrderRequest {
237 pub price: Money,
238 pub quantity: u64,
239}
240
241#[derive(Debug, Clone, Serialize)]
242pub struct PreviewOrderRequest {
243 pub symbol: String,
244 pub action: String,
245 #[serde(rename = "outcomeSide")]
246 pub outcome_side: String,
247 #[serde(rename = "type")]
248 pub order_type: String,
249 pub price: Money,
250 pub quantity: u64,
251}
252
253#[derive(Debug, Clone, Deserialize)]
254pub struct PreviewOrderResponse {
255 #[serde(default)]
256 pub estimate: serde_json::Value,
257}
258
259#[derive(Debug, Clone, Serialize)]
260pub struct ClosePositionRequest {
261 pub symbol: String,
262 pub quantity: u64,
263}
264
265#[derive(Debug, Clone, Deserialize)]
266pub struct ClosePositionResponse {
267 #[serde(default)]
268 pub status: String,
269 #[serde(default)]
270 pub order_id: Option<String>,
271}
272
273#[derive(Debug, Clone, Deserialize)]
274pub struct GetOpenOrdersResponse {
275 #[serde(default)]
276 pub orders: Vec<PlaceOrderResponse>,
277}