; -*- mode: org; mode: beancount; coding: utf-8; fill-column: 400; -*-;; Cheatsheet
option "title" "Crypto"option "operating_currency" "ETH"option "operating_currency" "GAS"option "operating_currency" "LTC"option "operating_currency" "NEO"
plugin "beancount.plugins.book_conversions" "Assets:Crypto:ETH,Income:Capital-gains"
;* Equity;2017-11-01 open Equity:Opening-Balances
* Account declarations; Account12017-08-18 open Assets:Crypto:ETH:Account1 ETH2017-08-18 open Assets:Crypto:LTC:Account1 LTC; Account22017-08-18 open Assets:Crypto:ETH:Account2 ETH; Exchange2017-08-18 open Assets:Crypto:GAS:Exchange GAS2017-08-18 open Assets:Crypto:NEO:Exchange NEO
2017-08-18 open Expenses:Crypto:ETH:Balance ETH2017-08-18 open Expenses:Crypto:GAS:Balance GAS2017-08-18 open Expenses:Crypto:LTC:Balance LTC2017-08-18 open Expenses:Crypto:NEO:Balance NEO
* Income2017-08-18 open Income:Capital-gains
* Expenses2017-08-18 open Expenses:Financial:Commisions:USD
* Transactions2017-11-19 * "Opening balance: Account1" Assets:Crypto:ETH:Account1 5.12561083 ETH Assets:Crypto:LTC:Account1 7.58990978 LTC Expenses:Crypto:ETH:Balance -5.12561083 ETH Expenses:Crypto:LTC:Balance -7.58990978 LTC
2017-11-19 * "Opening balance: Account2" Assets:Crypto:ETH:Account2 3.968560 ETH Expenses:Crypto:ETH:Balance -3.968560 ETH
2017-11-19 * "Opening balance: Exchange" Assets:Crypto:NEO:Exchange 4 NEO Assets:Crypto:GAS:Exchange 0.18651499 GAS Expenses:Crypto:NEO:Balance -4 NEO Expenses:Crypto:GAS:Balance -0.18651499 GAS
--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/88c1a28b-28ed-47fe-8a6d-489823f24bd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(.env3) > $ bean-price -e USD:coinmarketcapsource/ETH --no-cache2017-11-20 price ETH 358.93000000000000682121026329696178436279296875 USD (.env3) > $ bean-price -e USD:coinmarketcapsource/NEO --no-cache
2017-11-20 price NEO 40.57000000000000028421709430404007434844970703125 USD (.env3) > $ bean-price -e USD:coinmarketcapsource/GAS --no-cache
2017-11-20 price GAS 24.309999999999998721023075631819665431976318359375 USD
(.env3) > $ bean-price portfolio.beancount
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/a778178d-448e-4fed-a8c3-ffd29034e6ec%40googlegroups.com.
2017-11-20 price ETH 367.93000000000000682121026329696178436279296875 USD2017-11-19 price EUR 1.173155 USD2017-11-20 price GAS 23.3599999999999994315658113919198513031005859375 USD2017-11-20 price GNT 0.2210999999999999909849890400437288917601108551025390625 USD2017-11-20 price LTC 72.9899999999999948840923025272786617279052734375 USD
...
price = D(result[symbol][base_currency])
...
return source.SourcePrice(price, time, base_currency)
.
├── beancount_cryptocompare
│ ├── cryptocompareusd.py│ └── __pycache__│ ├── cryptocompareusd.cpython-36.pyc│ └── __init__.cpython-36.pyc├── beancount_cryptocompare.egg-info│ ├── dependency_links.txt│ ├── not-zip-safe│ ├── PKG-INFO│ ├── requires.txt│ ├── SOURCES.txt│ └── top_level.txt├── ...├── setup.cfg
├── setup.py
2017-11-19 commodity BTC export: "Crypto:BTC" name: "Bitcoin" price: "USD:beancount_cryptocompare.cryptocompareusd/BTC"
bean-query portfolio.beancount "\select account, convert(sum(position), 'USD') \group by account \order by account \"
account convert_su----------------------------- ----------Assets:Crypto:Exchange1:BTS 10 USDAssets:Crypto:Exchange1:CVC 10 USDAssets:Crypto:Exchange1:STRAT 10 USDAssets:Crypto:Wallet1:ETH 10 USDAssets:Crypto:Wallet1:LTC 10 USDAssets:Crypto:Wallet2:ETH 10 USD
account convert_su----------------------------- ----------Assets:Crypto 60 USD
Thank you Martin for the nice ideas.I have some related questions (underlined to try to ease your readability).
First: Here is an output example of the prices:
2017-11-20 price ETH 367.93000000000000682121026329696178436279296875 USD2017-11-19 price EUR 1.173155 USD2017-11-20 price GAS 23.3599999999999994315658113919198513031005859375 USD2017-11-20 price GNT 0.2210999999999999909849890400437288917601108551025390625 USD2017-11-20 price LTC 72.9899999999999948840923025272786617279052734375 USDOn my price source provider I have something like this at the end:
...
price = D(result[symbol][base_currency])
...
return source.SourcePrice(price, time, base_currency)
I wonder, is there a way to limit the decimal places? I tried with the Python Decimal's get_context (if I remember correctly).
Second: In general the prices source I made seems to work, so I would like to refactor it to a python module, so it is more maintainable and easy to install for others to use, if needed. The big issue is how do I use a python package as a price source provider?
Currently I have a file on the same folder of the beancount files called cryptocompareusd.py and it works fine (I added to the PYTHONPATH env var), however I have created a package using cookiecutter and the structure is as follows:I am not sure how to use the provider once on a python package. If I install the package described with `pip install --editable .` and I `import beancount_cryptocompare.cryptocompareusd` it works, however when I use the namespace on the price attribute it doesn't work, example:
.├── beancount_cryptocompare│ ├── cryptocompareusd.py│ └── __pycache__│ ├── cryptocompareusd.cpython-36.pyc│ └── __init__.cpython-36.pyc├── beancount_cryptocompare.egg-info│ ├── dependency_links.txt│ ├── not-zip-safe│ ├── PKG-INFO│ ├── requires.txt│ ├── SOURCES.txt│ └── top_level.txt├── ...├── setup.cfg├── setup.py
2017-11-19 commodity BTCexport: "Crypto:BTC"name: "Bitcoin"price: "USD:beancount_cryptocompare.cryptocompareusd/BTC"
Third: Is there any way to parse within the `get_latest_price` of the source.Source the external currency? I mean the first part before the ":", in the above example USD. (same as when using the command: `bean-price -e USD:cryptocompareusd/ETH`).
I am using a pip egg that supports querying the price of a cryptocurrency in another currency (USD, EUR, BTC, etc), so what I first thought is to define multiple "price:" attributes for each currency, however I don't know if that makes sense. I haven't yet tried that. What would be the right way to do this?
Fourth: Related to the last issue, I have found a query to get the current portfolio values using the prices:
bean-query portfolio.beancount "\select account, convert(sum(position), 'USD') \group by account \order by account \"This works awesome as expected (thank you!):
account convert_su----------------------------- ----------Assets:Crypto:Exchange1:BTS 10 USDAssets:Crypto:Exchange1:CVC 10 USDAssets:Crypto:Exchange1:STRAT 10 USDAssets:Crypto:Wallet1:ETH 10 USDAssets:Crypto:Wallet1:LTC 10 USDAssets:Crypto:Wallet2:ETH 10 USD
Is there a way to get the "Assets:Crypto:*" sum? Something like:
account convert_su----------------------------- ----------Assets:Crypto 60 USD
The more I use beancount (and I am barely scratching the surface), the more I am amazed with the state of the art of software you created. Congratulations indeed! Awesome contribution.Thank you very much.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/12b6bfdc-73aa-4ed8-a321-b18f5e6b2112%40googlegroups.com.
I wonder, is there a way to limit the decimal places? I tried with the Python Decimal's get_context (if I remember correctly).
price = D(response['rates'][to_currency]).quantize(D('1.000000'))
--
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 post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/752a8ea4-cfde-4e0b-a161-99696cda9f79%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAK21%2BhPYvXDE-k6Ubo2dgOZqnZDTVA-4XjaV_-0T0SSCJ46K-g%40mail.gmail.com.
--
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/91101592-cfd2-4e70-8622-8357474f31a5%40googlegroups.com.