ig_client/application/models/
account.rs

1/******************************************************************************
2   Author: Joaquín Béjar García
3   Email: jb@taunais.com
4   Date: 13/5/25
5******************************************************************************/
6use serde::{Deserialize, Serialize};
7
8use super::order::Direction;
9
10/// Account information
11#[derive(Debug, Clone, Deserialize)]
12pub struct AccountInfo {
13    /// List of accounts owned by the user
14    pub accounts: Vec<Account>,
15}
16
17/// Details of a specific account
18#[derive(Debug, Clone, Deserialize)]
19pub struct Account {
20    /// Unique identifier for the account
21    #[serde(rename = "accountId")]
22    pub account_id: String,
23    /// Name of the account
24    #[serde(rename = "accountName")]
25    pub account_name: String,
26    /// Type of the account (e.g., CFD, Spread bet)
27    #[serde(rename = "accountType")]
28    pub account_type: String,
29    /// Balance information for the account
30    pub balance: AccountBalance,
31    /// Base currency of the account
32    pub currency: String,
33    /// Current status of the account
34    pub status: String,
35    /// Whether this is the preferred account
36    pub preferred: bool,
37}
38
39/// Account balance information
40#[derive(Debug, Clone, Deserialize)]
41pub struct AccountBalance {
42    /// Total balance of the account
43    pub balance: f64,
44    /// Deposit amount
45    pub deposit: f64,
46    /// Current profit or loss
47    #[serde(rename = "profitLoss")]
48    pub profit_loss: f64,
49    /// Available funds for trading
50    pub available: f64,
51}
52
53/// Account activity
54#[derive(Debug, Clone, Deserialize)]
55pub struct AccountActivity {
56    /// List of activities on the account
57    pub activities: Vec<Activity>,
58}
59
60/// Individual activity record
61#[derive(Debug, Clone, Deserialize, Serialize)]
62pub struct Activity {
63    /// Date and time of the activity
64    pub date: String,
65    /// Unique identifier for the deal
66    #[serde(rename = "dealId")]
67    pub deal_id: String,
68    /// Instrument EPIC identifier
69    pub epic: String,
70    /// Time period of the activity
71    pub period: String,
72    /// Client-generated reference for the deal
73    #[serde(rename = "dealReference")]
74    pub deal_reference: String,
75    /// Type of activity
76    #[serde(rename = "activityType")]
77    pub activity_type: String,
78    /// Status of the activity
79    pub status: String,
80    /// Description of the activity
81    pub description: String,
82    /// Additional details about the activity
83    pub details: Option<String>,
84}
85
86/// Open positions
87#[derive(Debug, Clone, Deserialize, Serialize)]
88pub struct Positions {
89    /// List of open positions
90    pub positions: Vec<Position>,
91}
92
93/// Individual position
94#[derive(Debug, Clone, Serialize, Deserialize)]
95pub struct Position {
96    /// Details of the position
97    pub position: PositionDetails,
98    /// Market information for the position
99    pub market: PositionMarket,
100    /// Profit and loss for the position
101    pub pnl: Option<f64>,
102}
103
104/// Details of a position
105#[derive(Debug, Clone, Deserialize, Serialize)]
106pub struct PositionDetails {
107    /// Size of one contract
108    #[serde(rename = "contractSize")]
109    pub contract_size: f64,
110    /// Date and time when the position was created
111    #[serde(rename = "createdDate")]
112    pub created_date: String,
113    /// UTC date and time when the position was created
114    #[serde(rename = "createdDateUTC")]
115    pub created_date_utc: String,
116    /// Unique identifier for the deal
117    #[serde(rename = "dealId")]
118    pub deal_id: String,
119    /// Client-generated reference for the deal
120    #[serde(rename = "dealReference")]
121    pub deal_reference: String,
122    /// Direction of the position (buy or sell)
123    pub direction: Direction,
124    /// Price level for take profit
125    #[serde(rename = "limitLevel")]
126    pub limit_level: Option<f64>,
127    /// Opening price level of the position
128    pub level: f64,
129    /// Size/quantity of the position
130    pub size: f64,
131    /// Price level for stop loss
132    #[serde(rename = "stopLevel")]
133    pub stop_level: Option<f64>,
134    /// Step size for trailing stop
135    #[serde(rename = "trailingStep")]
136    pub trailing_step: Option<f64>,
137    /// Distance for trailing stop
138    #[serde(rename = "trailingStopDistance")]
139    pub trailing_stop_distance: Option<f64>,
140    /// Currency of the position
141    pub currency: String,
142    /// Whether the position has controlled risk
143    #[serde(rename = "controlledRisk")]
144    pub controlled_risk: bool,
145    /// Premium paid for limited risk
146    #[serde(rename = "limitedRiskPremium")]
147    pub limited_risk_premium: Option<f64>,
148}
149
150/// Market information for a position
151#[derive(Debug, Clone, Deserialize, Serialize)]
152pub struct PositionMarket {
153    /// Human-readable name of the instrument
154    #[serde(rename = "instrumentName")]
155    pub instrument_name: String,
156    /// Expiry date of the instrument
157    pub expiry: String,
158    /// Unique identifier for the market
159    pub epic: String,
160    /// Type of the instrument
161    #[serde(rename = "instrumentType")]
162    pub instrument_type: String,
163    /// Size of one lot
164    #[serde(rename = "lotSize")]
165    pub lot_size: f64,
166    /// Highest price of the current trading session
167    pub high: f64,
168    /// Lowest price of the current trading session
169    pub low: f64,
170    /// Percentage change in price since previous close
171    #[serde(rename = "percentageChange")]
172    pub percentage_change: f64,
173    /// Net change in price since previous close
174    #[serde(rename = "netChange")]
175    pub net_change: f64,
176    /// Current bid price
177    pub bid: f64,
178    /// Current offer/ask price
179    pub offer: f64,
180    /// Time of the last price update
181    #[serde(rename = "updateTime")]
182    pub update_time: String,
183    /// UTC time of the last price update
184    #[serde(rename = "updateTimeUTC")]
185    pub update_time_utc: String,
186    /// Delay time in milliseconds for market data
187    #[serde(rename = "delayTime")]
188    pub delay_time: i64,
189    /// Whether streaming prices are available for this market
190    #[serde(rename = "streamingPricesAvailable")]
191    pub streaming_prices_available: bool,
192    /// Current status of the market (e.g., "OPEN", "CLOSED")
193    #[serde(rename = "marketStatus")]
194    pub market_status: String,
195    /// Factor for scaling prices
196    #[serde(rename = "scalingFactor")]
197    pub scaling_factor: i64,
198}
199
200/// Working orders
201#[derive(Debug, Clone, Deserialize, Serialize)]
202pub struct WorkingOrders {
203    /// List of pending working orders
204    pub working_orders: Vec<WorkingOrder>,
205}
206
207/// Working order
208#[derive(Debug, Clone, Deserialize, Serialize)]
209pub struct WorkingOrder {
210    /// Details of the working order
211    #[serde(rename = "workingOrderData")]
212    pub working_order_data: WorkingOrderData,
213    /// Market information for the working order
214    #[serde(rename = "marketData")]
215    pub market_data: MarketData,
216}
217
218/// Details of a working order
219#[derive(Debug, Clone, Deserialize, Serialize)]
220pub struct WorkingOrderData {
221    /// Unique identifier for the deal
222    #[serde(rename = "dealId")]
223    pub deal_id: String,
224    /// Direction of the order (buy or sell)
225    pub direction: Direction,
226    /// Instrument EPIC identifier
227    pub epic: String,
228    /// Size/quantity of the order
229    #[serde(rename = "orderSize")]
230    pub order_size: f64,
231    /// Price level for the order
232    #[serde(rename = "orderLevel")]
233    pub order_level: f64,
234    /// Time in force for the order
235    #[serde(rename = "timeInForce")]
236    pub time_in_force: String,
237    /// Expiry date for GTD orders
238    #[serde(rename = "goodTillDate")]
239    pub good_till_date: Option<String>,
240    /// ISO formatted expiry date for GTD orders
241    #[serde(rename = "goodTillDateISO")]
242    pub good_till_date_iso: Option<String>,
243    /// Date and time when the order was created
244    #[serde(rename = "createdDate")]
245    pub created_date: String,
246    /// UTC date and time when the order was created
247    #[serde(rename = "createdDateUTC")]
248    pub created_date_utc: String,
249    /// Whether the order has a guaranteed stop
250    #[serde(rename = "guaranteedStop")]
251    pub guaranteed_stop: bool,
252    /// Type of the order
253    #[serde(rename = "orderType")]
254    pub order_type: String,
255    /// Distance for stop loss
256    #[serde(rename = "stopDistance")]
257    pub stop_distance: Option<f64>,
258    /// Distance for take profit
259    #[serde(rename = "limitDistance")]
260    pub limit_distance: Option<f64>,
261    /// Currency code for the order
262    #[serde(rename = "currencyCode")]
263    pub currency_code: String,
264    /// Whether direct market access is enabled
265    pub dma: bool,
266    /// Premium for limited risk
267    #[serde(rename = "limitedRiskPremium")]
268    pub limited_risk_premium: Option<f64>,
269    /// Price level for take profit
270    #[serde(rename = "limitLevel", default)]
271    pub limit_level: Option<f64>,
272    /// Price level for stop loss
273    #[serde(rename = "stopLevel", default)]
274    pub stop_level: Option<f64>,
275    /// Client-generated reference for the deal
276    #[serde(rename = "dealReference", default)]
277    pub deal_reference: Option<String>,
278}
279
280/// Market data for a working order
281#[derive(Debug, Clone, Deserialize, Serialize)]
282pub struct MarketData {
283    /// Human-readable name of the instrument
284    #[serde(rename = "instrumentName")]
285    pub instrument_name: String,
286    /// Exchange identifier
287    #[serde(rename = "exchangeId")]
288    pub exchange_id: String,
289    /// Expiry date of the instrument
290    pub expiry: String,
291    /// Current status of the market
292    #[serde(rename = "marketStatus")]
293    pub market_status: String,
294    /// Unique identifier for the market
295    pub epic: String,
296    /// Type of the instrument
297    #[serde(rename = "instrumentType")]
298    pub instrument_type: String,
299    /// Size of one lot
300    #[serde(rename = "lotSize")]
301    pub lot_size: f64,
302    /// Highest price of the current trading session
303    pub high: f64,
304    /// Lowest price of the current trading session
305    pub low: f64,
306    /// Percentage change in price since previous close
307    #[serde(rename = "percentageChange")]
308    pub percentage_change: f64,
309    /// Net change in price since previous close
310    #[serde(rename = "netChange")]
311    pub net_change: f64,
312    /// Current bid price
313    pub bid: f64,
314    /// Current offer/ask price
315    pub offer: f64,
316    /// Time of the last price update
317    #[serde(rename = "updateTime")]
318    pub update_time: String,
319    /// UTC time of the last price update
320    #[serde(rename = "updateTimeUTC")]
321    pub update_time_utc: String,
322    /// Delay time in milliseconds for market data
323    #[serde(rename = "delayTime")]
324    pub delay_time: i64,
325    /// Whether streaming prices are available for this market
326    #[serde(rename = "streamingPricesAvailable")]
327    pub streaming_prices_available: bool,
328    /// Factor for scaling prices
329    #[serde(rename = "scalingFactor")]
330    pub scaling_factor: i64,
331}
332
333/// Transaction history
334#[derive(Debug, Clone, Deserialize, Serialize)]
335pub struct TransactionHistory {
336    /// List of account transactions
337    pub transactions: Vec<AccountTransaction>,
338    /// Metadata about the transaction list
339    pub metadata: TransactionMetadata,
340}
341
342/// Transaction metadata
343#[derive(Debug, Clone, Deserialize, Serialize)]
344pub struct TransactionMetadata {
345    /// Pagination information
346    #[serde(rename = "pageData")]
347    pub page_data: PageData,
348    /// Total number of transactions
349    pub size: i32,
350}
351
352/// Pagination information
353#[derive(Debug, Clone, Deserialize, Serialize)]
354pub struct PageData {
355    /// Current page number
356    #[serde(rename = "pageNumber")]
357    pub page_number: i32,
358    /// Number of items per page
359    #[serde(rename = "pageSize")]
360    pub page_size: i32,
361    /// Total number of pages
362    #[serde(rename = "totalPages")]
363    pub total_pages: i32,
364}
365
366/// Individual transaction
367#[derive(Debug, Clone, Deserialize, Serialize)]
368pub struct AccountTransaction {
369    /// Date and time of the transaction
370    pub date: String,
371    /// UTC date and time of the transaction
372    #[serde(rename = "dateUtc")]
373    pub date_utc: String,
374    /// Name of the instrument
375    #[serde(rename = "instrumentName")]
376    pub instrument_name: String,
377    /// Time period of the transaction
378    pub period: String,
379    /// Profit or loss amount
380    #[serde(rename = "profitAndLoss")]
381    pub profit_and_loss: String,
382    /// Type of transaction
383    #[serde(rename = "transactionType")]
384    pub transaction_type: String,
385    /// Reference identifier for the transaction
386    pub reference: String,
387    /// Opening price level
388    #[serde(rename = "openLevel")]
389    pub open_level: String,
390    /// Closing price level
391    #[serde(rename = "closeLevel")]
392    pub close_level: String,
393    /// Size/quantity of the transaction
394    pub size: String,
395    /// Currency of the transaction
396    pub currency: String,
397    /// Whether this is a cash transaction
398    #[serde(rename = "cashTransaction")]
399    pub cash_transaction: bool,
400}