Skip to content

Commit

Permalink
Better missing security reporting (redstreet#43)
Browse files Browse the repository at this point in the history
* if get_ticker_info_from_id finds an id not present in fund_info.py try to use self.ofx.security_list
to report more useful information.  At least in Fidelity ofx files both the symbol and security name
are present, so in most cases the required additions to fund_info.py are already in the file.

* Slightly better reportings...print a summary line before list of securities

* remove unused f string

* 1. Comments to explain what is going on
2. Key the extracted securities dict by CUSIP (not symbol) which matches what is found
     in the transaction entries (not for bonds symbol generally matches CUSIP)
3. Values of dict are now a tuple of (symbol, cusip, name) which for stocks should be all
     that is needed for fund_info.py

* Remove another unnecessary f string

Co-authored-by: Ware Adams <ware@rwa.washdcmail-intranet.lan>
  • Loading branch information
2 people authored and scanta2 committed Oct 13, 2023
1 parent 03da816 commit 4d54c90
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion beancount_reds_importers/libtransactionbuilder/investments.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,32 @@ def get_ticker_info_from_id(self, security_id):
if s in k:
securities_missing.remove(s)
# securities_missing = [s for s in securities if s not in self.funds_db]
print(f"List of securities without fund info: {securities_missing}", file=sys.stderr)

# try to extract security info from ofx
ofx_securities = dict()
try:
for o in self.ofx.security_list:
# It seems that because of the way investment transactions are reported
# in ofx the securities returned by self.get_security_list() are a list
# of cusip codes. In the section of the ofx that lists all securities
# and is found in self.ofx.security_list these codes are generally
# referred to as UNIQUEID (though the presence of another key called
# UNIQUEIDTYPE suggests that UNIQUEID is not always a cusip).
# because of this the key for the ofx_securities dict is uniqueid which
# corresponds to the items in the securities_missing list. The values
# of this dict are the best guess at what an entry for fund_info.py should
# be: a tuple of (ticker, cusip, name). Note in the case of bonds the
# ticker will match the cusip (at least in examples I have) and not be
# literally usable as a beancount symbol
ofx_securities[o.uniqueid] = (o.ticker, o.uniqueid, o.name)
except AttributeError:
# ofx doesn't have a security list
pass

print("List of securities without fund info:", file=sys.stderr)
for m in securities_missing:
print("%s: %s" % (m, ofx_securities.get(m, "???")), file=sys.stderr)
# print(f"List of securities without fund info: {securities_missing}", file=sys.stderr)
# import pdb; pdb.set_trace()
sys.exit(1)
return ticker, ticker_long_name
Expand Down

0 comments on commit 4d54c90

Please sign in to comment.