Skip to content

Commit

Permalink
Merge pull request #88 from tarioch/bugfix/separate_ib_trx_per_account
Browse files Browse the repository at this point in the history
correctly separate ib trx for different accounts
  • Loading branch information
tarioch committed Mar 23, 2023
2 parents 281f43d + 9f92bf9 commit 66fa8ad
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/tariochbctools/importers/ibkr/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def identify(self, file):
def file_account(self, file):
return ""

def matches(self, trx, t):
def matches(self, trx, t, account):
p = re.compile(r".* (?P<perShare>\d+\.?\d+) PER SHARE")
trxPerShare = p.search(trx.description).group("perShare")
tPerShare = p.search(t["description"]).group("perShare")
Expand All @@ -31,6 +31,7 @@ def matches(self, trx, t):
t["date"] == trx.dateTime
and t["symbol"] == trx.symbol
and trxPerShare == tPerShare
and t["account"] == account
)

def extract(self, file, existing_entries):
Expand All @@ -51,7 +52,12 @@ def extract(self, file, existing_entries):
existingEntry = None
if CashAction.DIVIDEND == trx.type or CashAction.WHTAX == trx.type:
existingEntry = next(
(t for t in transactions if self.matches(trx, t)), None
(
t
for t in transactions
if self.matches(trx, t, stmt.accountId)
),
None,
)

if existingEntry:
Expand Down

0 comments on commit 66fa8ad

Please sign in to comment.