ig_client/application/models/
market.rs1pub(crate) use crate::presentation::InstrumentType;
2use serde::{Deserialize, Serialize};
3use std::fmt::Display;
4
5#[derive(Debug, Clone, Deserialize)]
7pub struct Instrument {
8 pub epic: String,
10 pub name: String,
12 #[serde(rename = "instrumentType")]
14 pub instrument_type: InstrumentType,
15 pub expiry: String,
17 #[serde(rename = "contractSize")]
19 pub contract_size: Option<f64>,
20 #[serde(rename = "lotSize")]
22 pub lot_size: Option<f64>,
23 #[serde(rename = "highLimitPrice")]
25 pub high_limit_price: Option<f64>,
26 #[serde(rename = "lowLimitPrice")]
28 pub low_limit_price: Option<f64>,
29 #[serde(rename = "marginFactor")]
31 pub margin_factor: Option<f64>,
32 #[serde(rename = "marginFactorUnit")]
34 pub margin_factor_unit: Option<String>,
35 #[serde(rename = "slippageFactor")]
37 pub slippage_factor: Option<f64>,
38 #[serde(rename = "limitedRiskPremium")]
40 pub limited_risk_premium: Option<f64>,
41 #[serde(rename = "newsCode")]
43 pub news_code: Option<String>,
44 #[serde(rename = "chartCode")]
46 pub chart_code: Option<String>,
47 pub currencies: Option<Vec<Currency>>,
49}
50
51#[derive(Debug, Clone, Deserialize)]
53pub struct Currency {
54 pub code: String,
56 pub symbol: Option<String>,
58 #[serde(rename = "baseExchangeRate")]
60 pub base_exchange_rate: Option<f64>,
61 #[serde(rename = "exchangeRate")]
63 pub exchange_rate: Option<f64>,
64 #[serde(rename = "isDefault")]
66 pub is_default: Option<bool>,
67}
68
69#[derive(Debug, Clone, Deserialize)]
71pub struct MarketDetails {
72 pub instrument: Instrument,
74 pub snapshot: MarketSnapshot,
76}
77
78#[derive(Debug, Clone, Deserialize)]
80pub struct DealingRules {
81 #[serde(rename = "minDealSize")]
83 pub min_deal_size: Option<f64>,
84 #[serde(rename = "maxDealSize")]
86 pub max_deal_size: Option<f64>,
87 #[serde(rename = "minControlledRiskStopDistance")]
89 pub min_controlled_risk_stop_distance: Option<f64>,
90 #[serde(rename = "minNormalStopOrLimitDistance")]
92 pub min_normal_stop_or_limit_distance: Option<f64>,
93 #[serde(rename = "maxStopOrLimitDistance")]
95 pub max_stop_or_limit_distance: Option<f64>,
96 #[serde(rename = "marketOrderPreference")]
98 pub market_order_preference: String,
99 #[serde(rename = "trailingStopsPreference")]
101 pub trailing_stops_preference: String,
102}
103
104#[derive(Debug, Clone, Deserialize)]
106pub struct MarketSnapshot {
107 #[serde(rename = "marketStatus")]
109 pub market_status: String,
110 #[serde(rename = "netChange")]
112 pub net_change: Option<f64>,
113 #[serde(rename = "percentageChange")]
115 pub percentage_change: Option<f64>,
116 #[serde(rename = "updateTime")]
118 pub update_time: Option<String>,
119 #[serde(rename = "delayTime")]
121 pub delay_time: Option<i64>,
122 pub bid: Option<f64>,
124 pub offer: Option<f64>,
126 #[serde(rename = "high")]
128 pub high: Option<f64>,
129 #[serde(rename = "low")]
131 pub low: Option<f64>,
132 #[serde(rename = "binaryOdds")]
134 pub binary_odds: Option<f64>,
135 #[serde(rename = "decimalPlacesFactor")]
137 pub decimal_places_factor: Option<i64>,
138 #[serde(rename = "scalingFactor")]
140 pub scaling_factor: Option<i64>,
141 #[serde(rename = "controlledRiskExtraSpread")]
143 pub controlled_risk_extra_spread: Option<f64>,
144}
145
146#[derive(Debug, Clone, Deserialize)]
148pub struct MarketSearchResult {
149 pub markets: Vec<MarketData>,
151}
152
153#[derive(Debug, Clone, Deserialize, Serialize)]
155pub struct MarketData {
156 pub epic: String,
158 #[serde(rename = "instrumentName")]
160 pub instrument_name: String,
161 #[serde(rename = "instrumentType")]
163 pub instrument_type: InstrumentType,
164 pub expiry: String,
166 #[serde(rename = "highLimitPrice")]
168 pub high_limit_price: Option<f64>,
169 #[serde(rename = "lowLimitPrice")]
171 pub low_limit_price: Option<f64>,
172 #[serde(rename = "marketStatus")]
174 pub market_status: String,
175 #[serde(rename = "netChange")]
177 pub net_change: Option<f64>,
178 #[serde(rename = "percentageChange")]
180 pub percentage_change: Option<f64>,
181 #[serde(rename = "updateTime")]
183 pub update_time: Option<String>,
184 pub bid: Option<f64>,
186 pub offer: Option<f64>,
188}
189
190impl Display for MarketData {
191 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
192 let json = serde_json::to_string(self).unwrap_or_else(|_| "Invalid JSON".to_string());
193 write!(f, "{}", json)
194 }
195}
196
197#[derive(Debug, Clone, Deserialize)]
199pub struct HistoricalPricesResponse {
200 pub prices: Vec<HistoricalPrice>,
202 #[serde(rename = "instrumentType")]
204 pub instrument_type: InstrumentType,
205 #[serde(rename = "allowance")]
207 pub allowance: PriceAllowance,
208}
209
210#[derive(Debug, Clone, Deserialize)]
212pub struct HistoricalPrice {
213 #[serde(rename = "snapshotTime")]
215 pub snapshot_time: String,
216 #[serde(rename = "openPrice")]
218 pub open_price: PricePoint,
219 #[serde(rename = "highPrice")]
221 pub high_price: PricePoint,
222 #[serde(rename = "lowPrice")]
224 pub low_price: PricePoint,
225 #[serde(rename = "closePrice")]
227 pub close_price: PricePoint,
228 #[serde(rename = "lastTradedVolume")]
230 pub last_traded_volume: Option<i64>,
231}
232
233#[derive(Debug, Clone, Deserialize)]
235pub struct PricePoint {
236 pub bid: Option<f64>,
238 pub ask: Option<f64>,
240 #[serde(rename = "lastTraded")]
242 pub last_traded: Option<f64>,
243}
244
245#[derive(Debug, Clone, Deserialize)]
247pub struct PriceAllowance {
248 #[serde(rename = "remainingAllowance")]
250 pub remaining_allowance: i64,
251 #[serde(rename = "totalAllowance")]
253 pub total_allowance: i64,
254 #[serde(rename = "allowanceExpiry")]
256 pub allowance_expiry: i64,
257}