1use rust_decimal::Decimal;
2use serde::{Deserialize, Serialize};
3use strum_macros::{Display, EnumString};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ExchangeRates {
10 pub exchanges: Vec<ExchangeRate>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct ExchangeRate {
17 pub average_rate: f64,
19 pub base_currency: String,
21 pub bid_rate: f64,
23 pub offer_rate: f64,
25 pub other_currency: String,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct ProfitAnalysis {
38 pub summary: ProfitAnalysisSummary,
40 pub sublist: ProfitAnalysisSublist,
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ProfitAnalysisSummary {
47 pub currency: String,
49 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
51 pub current_total_asset: Option<Decimal>,
52 pub start_date: String,
54 pub end_date: String,
56 pub start_time: String,
58 pub end_time: String,
60 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
62 pub ending_asset_value: Option<Decimal>,
63 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
65 pub initial_asset_value: Option<Decimal>,
66 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
68 pub invest_amount: Option<Decimal>,
69 pub is_traded: bool,
71 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
73 pub sum_profit: Option<Decimal>,
74 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
76 pub sum_profit_rate: Option<Decimal>,
77 pub profits: ProfitSummaryBreakdown,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct ProfitSummaryBreakdown {
84 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
86 pub stock: Option<Decimal>,
87 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
89 pub fund: Option<Decimal>,
90 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
92 pub crypto: Option<Decimal>,
93 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
95 pub mmf: Option<Decimal>,
96 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
98 pub other: Option<Decimal>,
99 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
101 pub cumulative_transaction_amount: Option<Decimal>,
102 pub trade_order_num: String,
104 pub trade_stock_num: String,
106 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
108 pub ipo: Option<Decimal>,
109 pub ipo_hit: i32,
111 pub ipo_subscription: i32,
113 pub summary_info: Vec<ProfitSummaryInfo>,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct ProfitSummaryInfo {
120 pub asset_type: AssetType,
122 pub profit_max: String,
124 pub profit_max_name: String,
126 pub loss_max: String,
128 pub loss_max_name: String,
130}
131
132#[derive(Debug, Clone, Default, Serialize, Deserialize)]
134pub struct ProfitAnalysisSublist {
135 pub start: String,
137 pub end: String,
139 pub start_date: String,
141 pub end_date: String,
143 pub updated_at: String,
145 pub updated_date: String,
147 pub items: Vec<ProfitAnalysisItem>,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct ProfitAnalysisItem {
154 pub name: String,
156 pub market: String,
158 pub is_holding: bool,
160 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
162 pub profit: Option<Decimal>,
163 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
165 pub profit_rate: Option<Decimal>,
166 pub clearance_times: i64,
168 #[serde(rename = "type")]
170 pub item_type: AssetType,
171 pub currency: String,
173 pub symbol: String,
175 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
177 pub holding_period: String,
178 pub security_code: String,
180 pub isin: String,
182 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
184 pub underlying_profit: Option<Decimal>,
185 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
187 pub derivatives_profit: Option<Decimal>,
188 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
190 pub order_profit: Option<Decimal>,
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct ProfitAnalysisDetail {
198 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
200 pub profit: Option<Decimal>,
201 pub underlying_details: ProfitDetails,
203 pub derivative_pnl_details: ProfitDetails,
205 pub name: String,
207 pub updated_at: String,
209 pub updated_date: String,
211 pub currency: String,
213 pub default_tag: i32,
215 pub start: String,
217 pub end: String,
219 pub start_date: String,
221 pub end_date: String,
223}
224
225#[derive(Debug, Clone, Serialize, Deserialize)]
227pub struct ProfitDetails {
228 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
230 pub holding_value: Option<Decimal>,
231 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
233 pub profit: Option<Decimal>,
234 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
236 pub cumulative_credited_amount: Option<Decimal>,
237 pub credited_details: Vec<ProfitDetailEntry>,
239 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
241 pub cumulative_debited_amount: Option<Decimal>,
242 pub debited_details: Vec<ProfitDetailEntry>,
244 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
246 pub cumulative_fee_amount: Option<Decimal>,
247 pub fee_details: Vec<ProfitDetailEntry>,
249 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
251 pub short_holding_value: Option<Decimal>,
252 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
254 pub long_holding_value: Option<Decimal>,
255 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
257 pub holding_value_at_beginning: Option<Decimal>,
258 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
260 pub holding_value_at_ending: Option<Decimal>,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize)]
265pub struct ProfitDetailEntry {
266 pub describe: String,
268 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
270 pub amount: Option<Decimal>,
271}
272
273#[derive(Debug, Clone, Serialize, Deserialize)]
277pub struct ProfitAnalysisByMarket {
278 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
280 pub profit: Option<Decimal>,
281 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
283 pub has_more: bool,
284 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
286 pub stock_items: Vec<ProfitAnalysisByMarketItem>,
287}
288
289#[derive(Debug, Clone, Serialize, Deserialize)]
291pub struct ProfitAnalysisByMarketItem {
292 pub code: String,
294 pub name: String,
296 pub market: String,
298 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
300 pub profit: Option<Decimal>,
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
307pub struct ProfitAnalysisFlows {
308 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
310 pub flows_list: Vec<FlowItem>,
311 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
313 pub has_more: bool,
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize)]
318pub struct FlowItem {
319 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
321 pub executed_date: String,
322 #[serde(default, with = "crate::serde_utils::value_as_opt_string")]
325 pub executed_timestamp: Option<String>,
326 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
328 pub code: String,
329 pub direction: FlowDirection,
331 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
333 pub executed_quantity: Option<Decimal>,
334 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
336 pub executed_price: Option<Decimal>,
337 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
339 pub executed_cost: Option<Decimal>,
340 #[serde(default, deserialize_with = "crate::serde_utils::null_as_default")]
342 pub describe: String,
343}
344
345#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
347pub enum FlowDirection {
348 Unknown,
350 #[strum(serialize = "buy")]
352 Buy,
353 #[strum(serialize = "sell")]
355 Sell,
356}
357
358impl_default_for_enum_string!(FlowDirection);
359impl_serde_for_enum_string!(FlowDirection);
360
361#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
363pub enum AssetType {
364 Unknown,
366 #[strum(serialize = "stock")]
368 Stock,
369 #[strum(serialize = "fund")]
371 Fund,
372 #[strum(serialize = "crypto")]
374 Crypto,
375}
376
377impl_default_for_enum_string!(AssetType);
378impl_serde_for_enum_string!(AssetType);