1#![allow(missing_docs)]
2
3use rust_decimal::Decimal;
4use serde::{Deserialize, Serialize};
5use strum_macros::{Display, EnumString};
6
7use crate::utils::counter::deserialize_counter_id_as_symbol;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct ExchangeRates {
14 pub exchanges: Vec<ExchangeRate>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ExchangeRate {
21 pub average_rate: f64,
23 pub base_currency: String,
25 pub bid_rate: f64,
27 pub offer_rate: f64,
29 pub other_currency: String,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ProfitAnalysis {
42 pub summary: ProfitAnalysisSummary,
44 pub sublist: ProfitAnalysisSublist,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct ProfitAnalysisSummary {
51 pub currency: String,
53 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
55 pub current_total_asset: Option<Decimal>,
56 pub start_date: String,
58 pub end_date: String,
60 pub start_time: String,
62 pub end_time: String,
64 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
66 pub ending_asset_value: Option<Decimal>,
67 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
69 pub initial_asset_value: Option<Decimal>,
70 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
72 pub invest_amount: Option<Decimal>,
73 pub is_traded: bool,
75 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
77 pub sum_profit: Option<Decimal>,
78 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
80 pub sum_profit_rate: Option<Decimal>,
81 pub profits: ProfitSummaryBreakdown,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct ProfitSummaryBreakdown {
88 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
90 pub stock: Option<Decimal>,
91 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
93 pub fund: Option<Decimal>,
94 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
96 pub crypto: Option<Decimal>,
97 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
99 pub mmf: Option<Decimal>,
100 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
102 pub other: Option<Decimal>,
103 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
105 pub cumulative_transaction_amount: Option<Decimal>,
106 pub trade_order_num: String,
108 pub trade_stock_num: String,
110 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
112 pub ipo: Option<Decimal>,
113 pub ipo_hit: i32,
115 pub ipo_subscription: i32,
117 pub summary_info: Vec<ProfitSummaryInfo>,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct ProfitSummaryInfo {
124 pub asset_type: AssetType,
126 pub profit_max: String,
128 pub profit_max_name: String,
130 pub loss_max: String,
132 pub loss_max_name: String,
134}
135
136#[derive(Debug, Clone, Default, Serialize, Deserialize)]
138pub struct ProfitAnalysisSublist {
139 pub start: String,
141 pub end: String,
143 pub start_date: String,
145 pub end_date: String,
147 pub updated_at: String,
149 pub updated_date: String,
151 pub items: Vec<ProfitAnalysisItem>,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
157pub struct ProfitAnalysisItem {
158 pub name: String,
160 pub market: String,
162 pub is_holding: bool,
164 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
166 pub profit: Option<Decimal>,
167 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
169 pub profit_rate: Option<Decimal>,
170 pub clearance_times: i64,
172 #[serde(rename = "type")]
174 pub item_type: AssetType,
175 pub currency: String,
177 #[serde(
179 rename = "counter_id",
180 deserialize_with = "deserialize_counter_id_as_symbol"
181 )]
182 pub symbol: String,
183 #[serde(default)]
185 pub holding_period: String,
186 pub security_code: String,
188 pub isin: String,
190 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
192 pub underlying_profit: Option<Decimal>,
193 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
195 pub derivatives_profit: Option<Decimal>,
196 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
198 pub order_profit: Option<Decimal>,
199}
200
201#[derive(Debug, Clone, Serialize, Deserialize)]
205pub struct ProfitAnalysisDetail {
206 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
208 pub profit: Option<Decimal>,
209 pub underlying_details: ProfitDetails,
211 pub derivative_pnl_details: ProfitDetails,
213 pub name: String,
215 pub updated_at: String,
217 pub updated_date: String,
219 pub currency: String,
221 pub default_tag: i32,
223 pub start: String,
225 pub end: String,
227 pub start_date: String,
229 pub end_date: String,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize)]
235pub struct ProfitDetails {
236 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
238 pub holding_value: Option<Decimal>,
239 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
241 pub profit: Option<Decimal>,
242 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
244 pub cumulative_credited_amount: Option<Decimal>,
245 pub credited_details: Vec<ProfitDetailEntry>,
247 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
249 pub cumulative_debited_amount: Option<Decimal>,
250 pub debited_details: Vec<ProfitDetailEntry>,
252 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
254 pub cumulative_fee_amount: Option<Decimal>,
255 pub fee_details: Vec<ProfitDetailEntry>,
257 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
259 pub short_holding_value: Option<Decimal>,
260 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
262 pub long_holding_value: Option<Decimal>,
263 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
265 pub holding_value_at_beginning: Option<Decimal>,
266 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
268 pub holding_value_at_ending: Option<Decimal>,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize)]
273pub struct ProfitDetailEntry {
274 pub describe: String,
276 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
278 pub amount: Option<Decimal>,
279}
280
281#[derive(Debug, Clone, Serialize, Deserialize)]
285pub struct ProfitAnalysisByMarket {
286 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
288 pub profit: Option<Decimal>,
289 #[serde(default)]
291 pub has_more: bool,
292 #[serde(default)]
294 pub stock_items: Vec<ProfitAnalysisByMarketItem>,
295}
296
297#[derive(Debug, Clone, Serialize, Deserialize)]
299pub struct ProfitAnalysisByMarketItem {
300 pub code: String,
302 pub name: String,
304 pub market: String,
306 #[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
308 pub profit: Option<Decimal>,
309}
310
311#[derive(Debug, Clone, Serialize, Deserialize)]
315pub struct ProfitAnalysisFlows {
316 #[serde(default)]
318 pub flows_list: Vec<FlowItem>,
319 #[serde(default)]
321 pub has_more: bool,
322}
323
324#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct FlowItem {
327 #[serde(default)]
329 pub executed_date: String,
330 #[serde(default)]
332 pub executed_timestamp: serde_json::Value,
333 #[serde(default)]
335 pub code: String,
336 pub direction: FlowDirection,
338 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
340 pub executed_quantity: Option<Decimal>,
341 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
343 pub executed_price: Option<Decimal>,
344 #[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
346 pub executed_cost: Option<Decimal>,
347 #[serde(default)]
349 pub describe: String,
350}
351
352#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
354pub enum FlowDirection {
355 Unknown,
357 #[strum(serialize = "buy")]
359 Buy,
360 #[strum(serialize = "sell")]
362 Sell,
363}
364
365impl_default_for_enum_string!(FlowDirection);
366impl_serde_for_enum_string!(FlowDirection);
367
368#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
370pub enum AssetType {
371 Unknown,
373 #[strum(serialize = "stock")]
375 Stock,
376 #[strum(serialize = "fund")]
378 Fund,
379 #[strum(serialize = "crypto")]
381 Crypto,
382}
383
384impl_default_for_enum_string!(AssetType);
385impl_serde_for_enum_string!(AssetType);