100 lines
2.5 KiB
Python
100 lines
2.5 KiB
Python
import codecs
|
|
import json
|
|
from ofxparse import OfxParser
|
|
with codecs.open('./afcu.ofx',encoding="us-ascii") as fileobj:
|
|
ofx = OfxParser.parse(fileobj)
|
|
|
|
# The OFX object
|
|
|
|
ofx.account # An Account object
|
|
|
|
# AccountType
|
|
# (Unknown, Bank, CreditCard, Investment)
|
|
|
|
# Account
|
|
|
|
account = ofx.account
|
|
account.account_id # The account number
|
|
account.number # The account number (deprecated -- returns account_id)
|
|
account.routing_number # The bank routing number
|
|
account.branch_id # Transit ID / branch number
|
|
account.type # An AccountType object
|
|
account.statement # A Statement object
|
|
account.institution # An Institution object
|
|
|
|
# InvestmentAccount(Account)
|
|
|
|
#account.brokerid # Investment broker ID
|
|
account.statement # An InvestmentStatement object
|
|
|
|
# Institution
|
|
|
|
institution = account.institution
|
|
institution.organization
|
|
institution.fid
|
|
|
|
# Statement
|
|
|
|
statement = account.statement
|
|
statement.start_date # The start date of the transactions
|
|
statement.end_date # The end date of the transactions
|
|
statement.balance # The money in the account as of the statement date
|
|
statement.available_balance # The money available from the account as of the statement date
|
|
statement.transactions # A list of Transaction objects
|
|
|
|
# InvestmentStatement
|
|
|
|
statement = account.statement
|
|
#statement.positions # A list of Position objects
|
|
statement.transactions # A list of InvestmentTransaction objects
|
|
|
|
# Transaction
|
|
|
|
for transaction in statement.transactions:
|
|
#print("payee:%s"%transaction.payee)
|
|
#print("type:%s"%transaction.type)
|
|
transaction.date
|
|
transaction.user_date
|
|
transaction.amount
|
|
transaction.id
|
|
transaction.memo
|
|
transaction.sic
|
|
transaction.mcc
|
|
transaction.checknum
|
|
|
|
# InvestmentTransaction
|
|
|
|
#for transaction in statement.transactions:
|
|
# transaction.type
|
|
# transaction.tradeDate
|
|
# transaction.settleDate
|
|
# transaction.memo
|
|
# transaction.security # A Security object
|
|
# transaction.income_type
|
|
# transaction.units
|
|
# transaction.unit_price
|
|
# transaction.comission
|
|
# transaction.fees
|
|
# transaction.total
|
|
# transaction.tferaction
|
|
|
|
# Positions
|
|
|
|
#for position in statement.positions:
|
|
# position.security # A Security object
|
|
# position.units
|
|
# position.unit_price
|
|
# position.market_value
|
|
|
|
# Security
|
|
|
|
#security = transaction.security
|
|
## or
|
|
#security = position.security
|
|
#security.uniqueid
|
|
#security.name
|
|
#security.ticker
|
|
#security.memo
|
|
js=json.dumps(ofx.account.statement.__dict__)
|
|
print(js);
|