Пример #1
0
 def from_decoded_json(data):
     """Creates a Sell transaction from a dictionary."""
     quantity = Decimal(data['quantity'])
     price = Decimal(data['price'])
     fees = Decimal(data['fees'])
     total = Decimal(data['total'])  # quantity * price - fees
     return Sell(utility.from_js_date(data['date']), data['symbol'],
                 quantity, price, fees, total)
Пример #2
0
 def from_decoded_json(data):
     """Creates a Buy transaction from a dictionary."""
     quantity = Decimal(data['quantity'])
     price = Decimal(data['price'])
     fees = Decimal(data['fees'])
     total = Decimal(data['total'])
     return Buy(utility.from_js_date(data['date']), data['symbol'],
                quantity, price, fees, total, data['wasReinvestment'])
Пример #3
0
    def _parse_transaction(self, data):
        date = utility.from_js_date(data['date'])
        total = dollars.parse(data['total']) if data['total'] else None

        if data['type'] == 'Dividend':
            return transactions.Dividend(
                date,
                data['symbol'],
                total,
                ast.literal_eval(data['is_qualified']),
                False)
        if data['type'] == 'Transfer':
            return transactions.Transfer(date, total)
        if data['type'] == 'SecurityTransfer':
            return transactions.SecurityTransfer(
                date, data['symbol'], Decimal(data['quantity']))
        if data['type'] == 'Interest':
            return transactions.Interest(date, total)
        if data['type'] == 'CapGain':
            return transactions.CapGain(
                date, data['symbol'], total,
                ast.literal_eval(data['is_long_term']), False)
        assert data['type'] in ('Buy', 'Sell')
        return self._parse_trade(data, date, total)
Пример #4
0
 def test_dates(self):
     self.assertEqual(utility.from_js_date('2017-01-10T01:12:45.678Z'),
                      datetime.date(2017, 1, 10))
Пример #5
0
 def from_decoded_json(data):
     """Creates a Dividend transaction from dictionary."""
     return Dividend(utility.from_js_date(data['date']), data['symbol'],
                     Decimal(data['amount']), data['qualified'],
                     data['wasReinvested'])
Пример #6
0
 def from_decoded_json(data):
     """Creates a SecurityTransfer transaction from a dictionary."""
     return SecurityTransfer(utility.from_js_date(data['date']),
                             data['symbol'], Decimal(data['quantity']))
Пример #7
0
 def from_decoded_json(data):
     """Creates a Transfer transaction from a dictionary."""
     return Transfer(utility.from_js_date(data['date']),
                     Decimal(data['amount']))
Пример #8
0
 def from_decoded_json(data):
     """Creates a Liquidation transaction from a dictionary."""
     return Liquidation(utility.from_js_date(data['date']),
                        data['description'], Decimal(data['amount']))
Пример #9
0
 def from_decoded_json(data):
     """Creates a CapGain transaction from a dictionary."""
     return CapGain(utility.from_js_date(data['date']), data['symbol'],
                    Decimal(data['amount']), data['longTerm'],
                    data['wasReinvested'])