Importing Python dicts?

97 views
Skip to first unread message

Sam Bragg

unread,
Oct 9, 2020, 7:32:39 AM10/9/20
to Beancount
Hi all,

I'm completely new to beancount, but I want to use it to manage my trading/investing activities. I have already written a library to download transactions from my broker's API, which returns a list of dicts.

I have looked at the beancount documentation and I can't even seem to get started. Many of the example importers given, assume that one has a file which they wish to import, which in my particular case is not relevant(?).

Here's the process as I envision it:
  1. Get a given date's transactions from my broker, using the library I made
  2. Implement some logic to classify each transaction (Account:[fees/PnL] etc.)
  3. Append the new transactions as directives in my beancount file
All I am really seeking to know at the moment is how I would even get started. Looking at beancount.ingest.importer - it needs a FileMemo instance, but in this case I won't be reading from a file - this is where most of my confusion is coming from.

Truly grateful for any response received. Thank you so much for producing this awesome software!

Sam

Red S

unread,
Oct 9, 2020, 2:06:59 PM10/9/20
to Beancount
You have the steps right. I'm trying to understand where you are stuck. You would simply write a new importer that didn't read from a file, but instead called your library, and converted the list of dicts into transactions. Have you looked at:
./examples/ingest/office/importers/utrade/utrade_csv.py
and

Sam Bragg

unread,
Oct 9, 2020, 2:50:31 PM10/9/20
to Beancount
Hi there, thanks very much for taking the time to reply.

I hadn't seen that example, it seems to be along the lines of what I'm trying to do, so I'll see how far I can get.

Have a great weekend,

Sam

Martin Blais

unread,
Oct 9, 2020, 9:23:56 PM10/9/20
to Beancount
You can either write a custom script and just print out to stdout, or use the ingest framework.

Here's an example of a custom standalone script that converts from Ameritrade:

The ingest library only provides a framework to help you automate some of the process of automatically identifying the files in your downloads directory, run the extraction of transactions (that you write) and file  away the downloads. You don't necessarily have to use it. http://furius.ca/beancount/doc/ingest

Hope this helps,




--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/c38aefcb-0af3-4591-9905-b5f8fcc79fcan%40googlegroups.com.

Chary Chary

unread,
Oct 10, 2020, 6:24:12 PM10/10/20
to Beancount
Martin,

sorry if this is a stupid question, but what is this transactions module, which you import here?

and then you use transactions.RunDispatch(txn) , however RunDispatch is defined in ameritrade2beancount

Chary Chary

unread,
Oct 10, 2020, 6:37:48 PM10/10/20
to Beancount
In fact for me for all tests to run, I had to replace   transactions.RunDispatch(txn)  ==>   ameritrade2beancount.RunDispatch(txn)   

Martin Blais

unread,
Oct 10, 2020, 9:32:20 PM10/10/20
to Beancount
On Sat, Oct 10, 2020 at 6:24 PM Chary Chary <char...@gmail.com> wrote:
Martin,

sorry if this is a stupid question, but what is this transactions module, which you import here?

Ahhh yes. This script used to be called "transactions" before it was living here; I forgot to rename the import and indeed the test doesn't run. Fixed (a bit sloppy on my part). Sorry about that.


Message has been deleted

Patrick Ruckstuhl

unread,
Nov 28, 2020, 4:21:48 PM11/28/20
to bean...@googlegroups.com

Hi,

Maybe a stupid question but, what do you want to put into the inline comments? Maybe you can put them as metadata, that way it could even be queryable if needed.

Regards,

Patrick

On 28.11.2020 20:09, Chary Chary wrote:
Martin,

is my understanding correct, that by following your example from Ameritrade one cannot create a beancount file, which contains inline comments for postings, like that?

2015-01-01 * "Taxi home from concert in Brooklyn"
  Assets:Cash      -20 USD  ; inline comment
  Expenses:Taxi
  


Reasons:

  1. There seems to be no place for comment in the Posting class (only may be in meta-data?)
  2. As far as I can see,  printer.print_entries() cannot print posting comment

If this is the case, what is the best way to create a custom script for converting data into beancount format with possibility to preserve inline comments for postings?


On Saturday, October 10, 2020 at 3:23:56 AM UTC+2 bl...@furius.ca wrote:

Martin Blais

unread,
Nov 28, 2020, 4:31:38 PM11/28/20
to Beancount
Use metadata.
I'm not changing the syntax in v2.
(v3 will bring syntax improvements, but that's going to take some time ~ months.)


On Sat, Nov 28, 2020 at 2:10 PM Chary Chary <char...@gmail.com> wrote:
Martin,

is my understanding correct, that by following your example from Ameritrade one cannot create a beancount file, which contains inline comments for postings, like that?

2015-01-01 * "Taxi home from concert in Brooklyn"
  Assets:Cash      -20 USD  ; inline comment
  Expenses:Taxi
  


Reasons:

  1. There seems to be no place for comment in the Posting class (only may be in meta-data?)
  2. As far as I can see,  printer.print_entries() cannot print posting comment

If this is the case, what is the best way to create a custom script for converting data into beancount format with possibility to preserve inline comments for postings?


On Saturday, October 10, 2020 at 3:23:56 AM UTC+2 bl...@furius.ca wrote:

Chary Chary

unread,
Nov 29, 2020, 6:05:56 AM11/29/20
to Beancount
Martin,

thanks! I already figured out to use metadata

Chary Chary

unread,
Nov 29, 2020, 10:53:22 AM11/29/20
to Beancount
It works great!

I just managed to write a script to convert 16 years worth of excel Bank transactions to correct beancount format 

Reply all
Reply to author
Forward
0 new messages