How to use the ofxparse.ofxparse.InvestmentTransaction function in ofxparse

To help you get started, we’ve selected a few ofxparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egh / ledger-autosync / ledgerautosync / converter.py View on Github external
metadata=posting_metadata)
            checknum=None
            if hasattr(txn, 'checknum') and txn.checknum != '':
                checknum=int(txn.checknum)
            return Transaction(
                date=txn.date,
                payee=self.format_payee(txn),
                postings=[
                    posting,
                    posting.clone_inverted(
                        self.mk_dynamic_account(self.format_payee(txn),
                                                exclude=self.name))],
                date_format=self.date_format,
                checknum=checknum
            )
        elif isinstance(txn, InvestmentTransaction):
            acct1 = self.name
            acct2 = self.name

            posting1 = None
            posting2 = None

            security = self.maybe_get_ticker(txn.security)

            if isinstance(txn.type, str):
                # recent versions of ofxparse
                if re.match('^(buy|sell)', txn.type):
                    acct2 = self.unknownaccount or 'Assets:Unknown'
                elif txn.type == 'transfer':
                    acct2 = 'Transfer'
                elif txn.type == 'reinvest':
                    # reinvestment of income
github jseutter / ofxparse / ofxparse / ofxparse.py View on Github external
def parseInvestmentTransaction(cls, ofx):
        transaction = InvestmentTransaction(ofx.name)
        tag = ofx.find('fitid')
        if hasattr(tag, 'contents'):
            transaction.id = tag.contents[0].strip()
        tag = ofx.find('memo')
        if hasattr(tag, 'contents'):
            transaction.memo = tag.contents[0].strip()
        tag = ofx.find('dttrade')
        if hasattr(tag, 'contents'):
            try:
                transaction.tradeDate = cls.parseOfxDateTime(
                    tag.contents[0].strip())
            except ValueError:
                raise
        tag = ofx.find('dtsettle')
        if hasattr(tag, 'contents'):
            try:
github jseutter / ofxparse / ofxparse / ofxparse.py View on Github external
'posdebt']:
            try:
                for investment_ofx in invstmtrs_ofx.findAll(transaction_type):
                    statement.positions.append(
                        cls.parseInvestmentPosition(investment_ofx))
            except (ValueError, IndexError, decimal.InvalidOperation,
                    TypeError):
                e = sys.exc_info()[1]
                if cls.fail_fast:
                    raise
                statement.discarded_entries.append(
                    {six.u('error'): six.u("Error parsing positions: \
                        ") + str(e), six.u('content'): investment_ofx}
                )

        for transaction_type in InvestmentTransaction.AGGREGATE_TYPES:
            try:
                for investment_ofx in invstmtrs_ofx.findAll(transaction_type):
                    statement.transactions.append(
                        cls.parseInvestmentTransaction(investment_ofx))
            except (ValueError, IndexError, decimal.InvalidOperation):
                e = sys.exc_info()[1]
                if cls.fail_fast:
                    raise
                statement.discarded_entries.append(
                    {six.u('error'): transaction_type + ": " + str(e),
                     six.u('content'): investment_ofx}
                )

        for transaction_ofx in invstmtrs_ofx.findAll('invbanktran'):
            for stmt_ofx in transaction_ofx.findAll('stmttrn'):
                try: