ig_client/application/models/
market.rs1use serde::{Deserialize, Serialize};
7use std::fmt::Display;
8
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
11#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
12pub enum InstrumentType {
13 Shares,
15 Currencies,
17 Indices,
19 SprintMarket,
21 Commodities,
23 Options,
25 #[serde(rename = "BINARY")]
27 Binary,
28 #[serde(other)]
30 Unknown,
31}
32
33#[derive(Debug, Clone, Deserialize)]
35pub struct Instrument {
36 pub epic: String,
38 pub name: String,
40 #[serde(rename = "instrumentType")]
42 pub instrument_type: InstrumentType,
43 pub expiry: String,
45 #[serde(rename = "contractSize")]
47 pub contract_size: Option<f64>,
48 #[serde(rename = "lotSize")]
50 pub lot_size: Option<f64>,
51 #[serde(rename = "highLimitPrice")]
53 pub high_limit_price: Option<f64>,
54 #[serde(rename = "lowLimitPrice")]
56 pub low_limit_price: Option<f64>,
57 #[serde(rename = "marginFactor")]
59 pub margin_factor: Option<f64>,
60 #[serde(rename = "marginFactorUnit")]
62 pub margin_factor_unit: Option<String>,
63 #[serde(rename = "slippageFactor")]
65 pub slippage_factor: Option<f64>,
66 #[serde(rename = "limitedRiskPremium")]
68 pub limited_risk_premium: Option<f64>,
69 #[serde(rename = "newsCode")]
71 pub news_code: Option<String>,
72 #[serde(rename = "chartCode")]
74 pub chart_code: Option<String>,
75 pub currencies: Option<Vec<Currency>>,
77}
78
79#[derive(Debug, Clone, Deserialize)]
81pub struct Currency {
82 pub code: String,
84 pub symbol: Option<String>,
86 #[serde(rename = "baseExchangeRate")]
88 pub base_exchange_rate: Option<f64>,
89 #[serde(rename = "exchangeRate")]
91 pub exchange_rate: Option<f64>,
92 #[serde(rename = "isDefault")]
94 pub is_default: Option<bool>,
95}
96
97#[derive(Debug, Clone, Deserialize)]
99pub struct MarketDetails {
100 pub instrument: Instrument,
102 pub snapshot: MarketSnapshot,
104}
105
106#[derive(Debug, Clone, Deserialize)]
108pub struct DealingRules {
109 #[serde(rename = "minDealSize")]
111 pub min_deal_size: Option<f64>,
112 #[serde(rename = "maxDealSize")]
114 pub max_deal_size: Option<f64>,
115 #[serde(rename = "minControlledRiskStopDistance")]
117 pub min_controlled_risk_stop_distance: Option<f64>,
118 #[serde(rename = "minNormalStopOrLimitDistance")]
120 pub min_normal_stop_or_limit_distance: Option<f64>,
121 #[serde(rename = "maxStopOrLimitDistance")]
123 pub max_stop_or_limit_distance: Option<f64>,
124 #[serde(rename = "marketOrderPreference")]
126 pub market_order_preference: String,
127 #[serde(rename = "trailingStopsPreference")]
129 pub trailing_stops_preference: String,
130}
131
132#[derive(Debug, Clone, Deserialize)]
134pub struct MarketSnapshot {
135 #[serde(rename = "marketStatus")]
137 pub market_status: String,
138 #[serde(rename = "netChange")]
140 pub net_change: Option<f64>,
141 #[serde(rename = "percentageChange")]
143 pub percentage_change: Option<f64>,
144 #[serde(rename = "updateTime")]
146 pub update_time: Option<String>,
147 #[serde(rename = "delayTime")]
149 pub delay_time: Option<i64>,
150 pub bid: Option<f64>,
152 pub offer: Option<f64>,
154 #[serde(rename = "high")]
156 pub high: Option<f64>,
157 #[serde(rename = "low")]
159 pub low: Option<f64>,
160 #[serde(rename = "binaryOdds")]
162 pub binary_odds: Option<f64>,
163 #[serde(rename = "decimalPlacesFactor")]
165 pub decimal_places_factor: Option<i64>,
166 #[serde(rename = "scalingFactor")]
168 pub scaling_factor: Option<i64>,
169 #[serde(rename = "controlledRiskExtraSpread")]
171 pub controlled_risk_extra_spread: Option<f64>,
172}
173
174#[derive(Debug, Clone, Deserialize)]
176pub struct MarketSearchResult {
177 pub markets: Vec<MarketData>,
179}
180
181#[derive(Debug, Clone, Deserialize, Serialize)]
183pub struct MarketData {
184 pub epic: String,
186 #[serde(rename = "instrumentName")]
188 pub instrument_name: String,
189 #[serde(rename = "instrumentType")]
191 pub instrument_type: InstrumentType,
192 pub expiry: String,
194 #[serde(rename = "highLimitPrice")]
196 pub high_limit_price: Option<f64>,
197 #[serde(rename = "lowLimitPrice")]
199 pub low_limit_price: Option<f64>,
200 #[serde(rename = "marketStatus")]
202 pub market_status: String,
203 #[serde(rename = "netChange")]
205 pub net_change: Option<f64>,
206 #[serde(rename = "percentageChange")]
208 pub percentage_change: Option<f64>,
209 #[serde(rename = "updateTime")]
211 pub update_time: Option<String>,
212 pub bid: Option<f64>,
214 pub offer: Option<f64>,
216}
217
218impl Display for MarketData {
219 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
220 let json = serde_json::to_string(self).unwrap_or_else(|_| "Invalid JSON".to_string());
221 write!(f, "{}", json)
222 }
223}
224
225#[derive(Debug, Clone, Deserialize)]
227pub struct HistoricalPricesResponse {
228 pub prices: Vec<HistoricalPrice>,
230 #[serde(rename = "instrumentType")]
232 pub instrument_type: InstrumentType,
233 #[serde(rename = "allowance")]
235 pub allowance: PriceAllowance,
236}
237
238#[derive(Debug, Clone, Deserialize)]
240pub struct HistoricalPrice {
241 #[serde(rename = "snapshotTime")]
243 pub snapshot_time: String,
244 #[serde(rename = "openPrice")]
246 pub open_price: PricePoint,
247 #[serde(rename = "highPrice")]
249 pub high_price: PricePoint,
250 #[serde(rename = "lowPrice")]
252 pub low_price: PricePoint,
253 #[serde(rename = "closePrice")]
255 pub close_price: PricePoint,
256 #[serde(rename = "lastTradedVolume")]
258 pub last_traded_volume: Option<i64>,
259}
260
261#[derive(Debug, Clone, Deserialize)]
263pub struct PricePoint {
264 pub bid: Option<f64>,
266 pub ask: Option<f64>,
268 #[serde(rename = "lastTraded")]
270 pub last_traded: Option<f64>,
271}
272
273#[derive(Debug, Clone, Deserialize)]
275pub struct PriceAllowance {
276 #[serde(rename = "remainingAllowance")]
278 pub remaining_allowance: i64,
279 #[serde(rename = "totalAllowance")]
281 pub total_allowance: i64,
282 #[serde(rename = "allowanceExpiry")]
284 pub allowance_expiry: i64,
285}