コード例 #1
0
ファイル: vanguard.py プロジェクト: rikonor/vanguard-api
    def get_current_holdings(self):
        self.go_to_balances_and_holdings()

        holdings_table = self.browser.find_element_by_id("BHForm2:accountID:0:_id245")
        rows = holdings_table.find_elements_by_tag_name("tr")

        # First row is Tables Headers
        # Second row simply says "ETFs"
        rows = rows[2:]

        # Row before last simply says "Buy Sell"
        # Last row is Total Assets
        rows = rows[:-2]

        # Remaining rows are actual ETFs
        holdings_info = []
        for row in rows:
            holding_info = {}
            els = row.find_elements_by_tag_name("td")

            # Symbol
            holding_info["symbol"] = els[0].text

            # Name (needs to be trimmed of spaces)
            name = els[1].text
            holding_info["name"] = name.strip()

            # Expense Ratio (Convert to float ratio)
            holding_info["expense_ratio"] = Converters.percent(els[2].text)

            # Quantity (Convert to doller value)
            holding_info["quantity"] = Converters.dollar_amount(els[3].text)

            # Last Price (Convert to doller value)
            holding_info["last_price"] = Converters.dollar_amount(els[4].text)

            # Absolute Change Amount (Convert to doller value)
            holding_info["change_amount"] = Converters.dollar_amount(els[5].text)

            # Precentage Change (Convert to float ratio)
            holding_info["change_percent"] = Converters.percent(els[6].text)

            # Current Balance for this holding (Convert to dollar value)
            holding_info["current_balance"] = Converters.dollar_amount(els[7].text)

            holdings_info.append(holding_info)

        return holdings_info
コード例 #2
0
    def test_can_convert_dollar_amounts(self):
        test_cases = [
            (1.0,   "1"),
            (10,   "10"),
            (10.1,  "10.1"),
            (1000,  "1,000"),
            (-1000000, "-1,000,000"),
            (1.0,   "$1"),
            (10,   "$10"),
            (10.1,  "$10.1"),
            (1000,  "$1,000"),
            (-1000000, "-$1,000,000"),
            (-1000000, "- $1,000,000"),
            (10,   "$ \u2013 10"),
            (10.1,  "\u2013 $10.1"),
        ]

        for result, case in test_cases:
            self.assertEqual(result, Converters.dollar_amount(case), "Failed for {}".format(case))