1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*!
 * Definitions for Flex Query report
 */

use serde::Deserialize;

/**
 * The structure of the IB Flex report.
 */
#[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
pub struct FlexQueryResponse {
    pub FlexStatements: FlexStatements,
}

impl From<String> for FlexQueryResponse {
    /**
     * Parses the file contents (xml) into the FlexQueryResponse object.
     */
    fn from(value: String) -> Self {
        serde_xml_rs::from_str(&value).expect("parsed XML")
    }
}

#[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
pub struct FlexStatements {
    pub count: i32,
    pub FlexStatement: FlexStatement,
}

#[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
pub struct FlexStatement {
    pub accountId: String,
    pub fromDate: String,
    pub toDate: String,
    pub period: String,
    pub whenGenerated: String,

    pub CashTransactions: CashTransactions,
}

#[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
pub struct CashTransactions {
    pub CashTransaction: Vec<CashTransaction>,
}

/**
 * .report_date is the real date, when the transaction appears in the IB report.
 * .date is the transaction effective date.
 */
#[allow(non_snake_case)]
#[derive(Debug, Default, Deserialize, PartialEq, Eq)]
pub struct CashTransaction {
    pub reportDate: String,
    pub dateTime: String,
    pub symbol: String,
    pub listingExchange: String,
    pub r#type: String,
    pub amount: String,
    pub currency: String,
    pub description: String,
}

// pub enum TxType {
//     "Deposits/Withdrawals",
//     Dividends,
//     WithholdingTax
// }