Skip to content

Commit

Permalink
Merge pull request #81 from carljm/schwabposfix
Browse files Browse the repository at this point in the history
Schwab CSV: parse per-account positions CSV too.
  • Loading branch information
jbms committed Dec 22, 2020
2 parents e9905e9 + 956c76d commit 8db33f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
16 changes: 12 additions & 4 deletions beancount_import/source/schwab_csv.py
Expand Up @@ -937,7 +937,7 @@ def _load_transactions(filename: str) -> List[RawEntry]:


POSITIONS_TITLE_RE = re.compile(
r'"Positions for All-Accounts as of (?P<time>.+), (?P<date>.+)"'
r'"Positions for (account )?(?P<account>.+) as of (?P<time>.+), (?P<date>.+)"'
)
POSITIONS_ACCT_RE = re.compile(r'"(?P<account>.+)"')

Expand All @@ -952,13 +952,21 @@ def _load_positions(filename: str) -> Sequence[RawPosition]:
title = csvfile.readline()
match = POSITIONS_TITLE_RE.match(title)
assert match, title
groups = match.groupdict()
date = _convert_date(match.groupdict()["date"])
if groups["account"] == "All-Accounts":
expect_account_headers = True
looking_for_account = True
account = None
else:
expect_account_headers = False
looking_for_account = False
account = groups["account"]
line_count += 1

account = None
looking_for_account = True
for line in csvfile:
if not line.strip():
looking_for_account = True
looking_for_account = expect_account_headers
empty_lines += 1
continue
if looking_for_account:
Expand Down
15 changes: 15 additions & 0 deletions testdata/source/schwab_csv/test_basic/import_results.beancount
Expand Up @@ -402,3 +402,18 @@
;; info: {"filename": "<testdata>/test_basic/positions/All-Accounts-Positions-2020-11-15.CSV", "line": 13, "type": "text/csv"}

2020-11-15 price SMAL040120203200P 12.53 USD

;; date: 2020-12-21
;; info: {"filename": "<testdata>/test_basic/positions/Intelligent-Positions-2020-11-30.CSV", "line": 4, "type": "text/csv"}

2020-12-21 balance Assets:Schwab:Intelligent-4321:SCHA 110 SCHA

;; date: 2020-12-21
;; info: {"filename": "<testdata>/test_basic/positions/Intelligent-Positions-2020-11-30.CSV", "line": 5, "type": "text/csv"}

2020-12-21 balance Assets:Schwab:Intelligent-4321:Cash 2953.34 USD

;; date: 2020-12-21
;; info: {"filename": "<testdata>/test_basic/positions/Intelligent-Positions-2020-11-30.CSV", "line": 4, "type": "text/csv"}

2020-12-21 price SCHA 88.71 USD
@@ -0,0 +1,6 @@
"Positions for account Intelligent XXXX-4321 as of 02:45 AM ET, 12/21/2020"

"Symbol","Description","Quantity","Price","Price Change $","Price Change %","Market Value","Day Change $","Day Change %","Cost Basis","Gain/Loss $","Gain/Loss %","Reinvest Dividends?","Capital Gains?","% Of Account","Dividend Yield","Last Dividend","Ex-Dividend Date","P/E Ratio","52 Week Low","52 Week High","Volume","Intrinsic Value","In The Money","Security Type",
"SCHA","SCHWAB US SMALL CAP ETF","110","$88.71","-$0.26","-0.29%","$9,758.10","-$2.86","-0.29%","$7,500.00","$2,258.10","+43.7%","No","--","5.24%","+1%","$0.30","12/10/2020","--","$43.05","$89.52","431,291","--","--","ETFs & Closed End Funds",
"Cash & Cash Investments","--","--","--","--","--","$2,953.34","$0.00","0%","--","--","--","--","--","13.97%","--","--","--","--","--","--","--","--","--","Cash and Money Market",
"Account Total","--","--","--","--","--","$12,711.44","-$2.86","-0.21%","$7,500.00","$2,258.10","+14.73%","--","--","--","--","--","--","--","--","--","--",

0 comments on commit 8db33f6

Please sign in to comment.