#![allow(missing_docs)]
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use crate::utils::counter::deserialize_counter_id_as_symbol;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExchangeRates {
pub exchanges: Vec<ExchangeRate>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExchangeRate {
pub average_rate: f64,
pub base_currency: String,
pub bid_rate: f64,
pub offer_rate: f64,
pub other_currency: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysis {
pub summary: ProfitAnalysisSummary,
pub sublist: ProfitAnalysisSublist,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisSummary {
pub currency: String,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub current_total_asset: Option<Decimal>,
pub start_date: String,
pub end_date: String,
pub start_time: String,
pub end_time: String,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub ending_asset_value: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub initial_asset_value: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub invest_amount: Option<Decimal>,
pub is_traded: bool,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub sum_profit: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub sum_profit_rate: Option<Decimal>,
pub profits: ProfitSummaryBreakdown,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitSummaryBreakdown {
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub stock: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub fund: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub crypto: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub mmf: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub other: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub cumulative_transaction_amount: Option<Decimal>,
pub trade_order_num: String,
pub trade_stock_num: String,
#[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
pub ipo: Option<Decimal>,
pub ipo_hit: i32,
pub ipo_subscription: i32,
pub summary_info: Vec<ProfitSummaryInfo>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitSummaryInfo {
pub asset_type: AssetType,
pub profit_max: String,
pub profit_max_name: String,
pub loss_max: String,
pub loss_max_name: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ProfitAnalysisSublist {
pub start: String,
pub end: String,
pub start_date: String,
pub end_date: String,
pub updated_at: String,
pub updated_date: String,
pub items: Vec<ProfitAnalysisItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisItem {
pub name: String,
pub market: String,
pub is_holding: bool,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit_rate: Option<Decimal>,
pub clearance_times: i64,
#[serde(rename = "type")]
pub item_type: AssetType,
pub currency: String,
#[serde(
rename = "counter_id",
deserialize_with = "deserialize_counter_id_as_symbol"
)]
pub symbol: String,
#[serde(default)]
pub holding_period: String,
pub security_code: String,
pub isin: String,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub underlying_profit: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub derivatives_profit: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub order_profit: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisDetail {
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit: Option<Decimal>,
pub underlying_details: ProfitDetails,
pub derivative_pnl_details: ProfitDetails,
pub name: String,
pub updated_at: String,
pub updated_date: String,
pub currency: String,
pub default_tag: i32,
pub start: String,
pub end: String,
pub start_date: String,
pub end_date: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitDetails {
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub holding_value: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub cumulative_credited_amount: Option<Decimal>,
pub credited_details: Vec<ProfitDetailEntry>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub cumulative_debited_amount: Option<Decimal>,
pub debited_details: Vec<ProfitDetailEntry>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub cumulative_fee_amount: Option<Decimal>,
pub fee_details: Vec<ProfitDetailEntry>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub short_holding_value: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub long_holding_value: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub holding_value_at_beginning: Option<Decimal>,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub holding_value_at_ending: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitDetailEntry {
pub describe: String,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub amount: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisByMarket {
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit: Option<Decimal>,
#[serde(default)]
pub has_more: bool,
#[serde(default)]
pub stock_items: Vec<ProfitAnalysisByMarketItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisByMarketItem {
pub code: String,
pub name: String,
pub market: String,
#[serde(with = "crate::serde_utils::decimal_opt_str_is_none")]
pub profit: Option<Decimal>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProfitAnalysisFlows {
#[serde(default)]
pub flows_list: Vec<FlowItem>,
#[serde(default)]
pub has_more: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FlowItem {
#[serde(default)]
pub executed_date: String,
#[serde(default)]
pub executed_timestamp: serde_json::Value,
#[serde(default)]
pub code: String,
pub direction: FlowDirection,
#[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
pub executed_quantity: Option<Decimal>,
#[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
pub executed_price: Option<Decimal>,
#[serde(default, with = "crate::serde_utils::decimal_opt_str_is_none")]
pub executed_cost: Option<Decimal>,
#[serde(default)]
pub describe: String,
}
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
pub enum FlowDirection {
Unknown,
#[strum(serialize = "buy")]
Buy,
#[strum(serialize = "sell")]
Sell,
}
impl_default_for_enum_string!(FlowDirection);
impl_serde_for_enum_string!(FlowDirection);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, EnumString, Display)]
pub enum AssetType {
Unknown,
#[strum(serialize = "stock")]
Stock,
#[strum(serialize = "fund")]
Fund,
#[strum(serialize = "crypto")]
Crypto,
}
impl_default_for_enum_string!(AssetType);
impl_serde_for_enum_string!(AssetType);