Skip to content

Commit

Permalink
feat(minor): add deep_identify to ibkr
Browse files Browse the repository at this point in the history
  • Loading branch information
redstreet committed Aug 1, 2024
1 parent c08e6eb commit b60e97f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion beancount_reds_importers/importers/ibkr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,22 @@ class Importer(investments.Importer, xmlreader.Importer):
def custom_init(self):
if not self.custom_init_run:
self.max_rounding_error = 0.04
self.filename_pattern_def = "Transaction_report"
self.filename_pattern_def = "ibkr"
self.custom_init_run = True
self.date_format = '%Y-%m-%d'
self.get_ticker_info = self.get_ticker_info_from_id

def deep_identify(self, file):
try:
if self.config.get('account_number', None):
# account number specific matching
return self.config['account_number'] == list(self.get_xpath_elements("/FlexQueryResponse/FlexStatements/FlexStatement/AccountInformation"))[0]['accountId']
else:
# base check: simply ensure this looks like a valid IBKR Flex Query file
return list(self.get_xpath_elements("/FlexQueryResponse"))[0] is not None
except IndexError:
return False

def set_currency(self):
self.currency = list(self.get_xpath_elements("/FlexQueryResponse/FlexStatements/FlexStatement/AccountInformation"))[0]['currency']

Expand Down
4 changes: 2 additions & 2 deletions beancount_reds_importers/libreader/xmlreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def initialize_reader(self, file):
self.file = file
self.reader_ready = False
self.xmltree = etree.parse(file.name)
self.reader_ready = self.deep_identify()
self.reader_ready = self.deep_identify(file)
if self.reader_ready:
self.set_currency()

def deep_identify(self):
def deep_identify(self, file):
"""For overriding by institution specific importer which can check if an account name
matches, and oother such things."""
return True
Expand Down

0 comments on commit b60e97f

Please sign in to comment.