-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add TD Ameritrade CSV importer #54
Open
reedlaw
wants to merge
2
commits into
redstreet:main
Choose a base branch
from
reedlaw:tdameritrade-csv
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−17
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
beancount_reds_importers/importers/tdameritrade/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +0,0 @@ | ||
|
||
from beancount_reds_importers.libreader import ofxreader | ||
from beancount_reds_importers.libtransactionbuilder import investments | ||
|
||
|
||
class Importer(investments.Importer, ofxreader.Importer): | ||
IMPORTER_NAME = 'TDAmeritrade' | ||
|
||
def custom_init(self): | ||
super(Importer, self).custom_init() | ||
self.max_rounding_error = 0.07 | ||
self.filename_pattern_def = '.*tdameritrade' | ||
self.get_ticker_info = self.get_ticker_info_from_id | ||
|
||
def get_ticker_info(self, security): | ||
ticker = self.config['fund_info']['cusip_map'][security] | ||
return ticker, '' | ||
62 changes: 62 additions & 0 deletions
62
beancount_reds_importers/importers/tdameritrade/tdameritrade_csv.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" TD Ameritrade .csv importer.""" | ||
|
||
from beancount_reds_importers.libreader import csvreader | ||
from beancount_reds_importers.libtransactionbuilder import investments | ||
|
||
|
||
class Importer(csvreader.Importer, investments.Importer): | ||
IMPORTER_NAME = 'TD Ameritrade CSV' | ||
|
||
def custom_init(self): | ||
self.max_rounding_error = 0.04 | ||
self.filename_pattern_def = 'transactions' | ||
self.header_identifier = 'DATE,TRANSACTION ID,DESCRIPTION.*' | ||
self.get_ticker_info = self.get_ticker_info_from_id | ||
self.date_format = '%m/%d/%Y' | ||
self.funds_db_txt = 'funds_by_ticker' | ||
self.skip_head_rows = 0 | ||
self.skip_tail_rows = 1 | ||
self.header_map = { | ||
"DATE": 'date', | ||
"TRANSACTION ID": 'txid', | ||
"DESCRIPTION": 'memo', | ||
"SYMBOL": 'security', | ||
"QUANTITY": 'units', | ||
"PRICE": 'unit_price', | ||
"AMOUNT": 'amount', | ||
"SHORT-TERM RDM FEE": 'short_term_fee', | ||
"FUND REDEMPTION FEE": 'fund_redmpt_fee', | ||
" DEFERRED SALES CHARGE": 'deferred_sales_charge', | ||
"REG FEE": 'fees', | ||
} | ||
self.transaction_type_map = {} | ||
self.skip_transaction_types = [] | ||
|
||
def prepare_raw_columns(self, rdr): | ||
def f(desc): | ||
if desc.startswith('Bought'): | ||
return 'buystock' | ||
if desc.startswith('Sold'): | ||
return 'sellstock' | ||
if desc.startswith('QUALIFIED DIVIDEND'): | ||
return 'dividends' | ||
if desc.startswith('ADR FEE'): | ||
return 'debit' | ||
if desc.startswith('CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT'): | ||
return 'credit' | ||
return 'Unknown type' | ||
|
||
rdr = rdr.addfield('type', lambda x: f(x['DESCRIPTION'])) | ||
rdr = rdr.addfield('total', lambda x: x['AMOUNT']) | ||
rdr = rdr.addfield('tradeDate', lambda x: x['DATE']) | ||
|
||
return rdr | ||
|
||
def get_balance_positions(self): | ||
return [] | ||
|
||
def build_metadata(self, file, metatype=None, data={}): | ||
"""This method is for importers to override. The overridden method can | ||
look at the metatype ('transaction', 'balance', 'account', 'commodity', etc.) | ||
and the data dictionary to return additional metadata""" | ||
return {'txid': data['transaction'].txid} |
18 changes: 18 additions & 0 deletions
18
beancount_reds_importers/importers/tdameritrade/tdameritrade_ofx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" TD Ameritrade ofx importer.""" | ||
|
||
from beancount_reds_importers.libreader import ofxreader | ||
from beancount_reds_importers.libtransactionbuilder import investments | ||
|
||
|
||
class Importer(investments.Importer, ofxreader.Importer): | ||
IMPORTER_NAME = 'TDAmeritrade' | ||
|
||
def custom_init(self): | ||
super(Importer, self).custom_init() | ||
self.max_rounding_error = 0.07 | ||
self.filename_pattern_def = '.*tdameritrade' | ||
self.get_ticker_info = self.get_ticker_info_from_id | ||
|
||
def get_ticker_info(self, security): | ||
ticker = self.config['fund_info']['cusip_map'][security] | ||
return ticker, '' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as duplicate.
Sorry, something went wrong.