Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def test_can_convert_percentages(self):
        test_cases = [
            (1.0,   "100%"),
            (1.0,   "100.00%"),
            (0.99,  "99.00%"),
            (0.01,  "1%"),
            (-0.01, "-1%"),
            (-0.1,  "- 10%"),
            (-0.01, "-\u2013 1%"),
            (-0.1,  "- \u2013 10%")
        ]

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