Qalculate / libqalculate

Qalculate! library and CLI
https://qalculate.github.io/
GNU General Public License v2.0
1.79k stars 144 forks source link

Get exchange rates from a custom source #209

Open ashpool37 opened 4 years ago

ashpool37 commented 4 years ago

Firstly, I would like to say thanks to all contributors for the amazing tool. I've been using qalc for a while now, and it really helps me out (coupled with hledger) with keeping my financial affairs in order.

The automatic fetching of exchange rates from a fixed widely trusted source like ECB is universally great for quick estimates. However, for the task of calculating one's taxes, one needs to refer strictly to their local authority and use precise rates published by that authority for that day. In Russia, for instance, if you receive salary in foreign currency, you need to use the daily rate provided by the Central Bank of Russia to calculate the exact amount of tax you need to pay.

It would be great to have a way to customize the source of exchange rates without having to modify and recompile the program. I would suggest implementing a plugin system by the means of which a user can provide their own scripts (e.g. Lua) to fetch and parse any sources they need. That would also imply having a runtime option to switch between sources and plugins as needed.

hanna-kn commented 4 years ago

This can most easily be implemented by allowing the user to specify an external command which writes the exchange rates to a file in a format recognized by Qalculate.

I have now added initial support for loading exchange rates from ~/.local/share/qalculate/custom_exchange_rates (or in the corresponding directory on platforms other than GNU/Linux). The file is a simple text file with one "x ABC = y DEF" (e.g. "1USD=70.86RUB") statement on each row. At the moment it can only be updated outside of qalc (e.g. in cron job, or before running qalc).

ashpool37 commented 4 years ago

Thanks, that works! Even neater than custom parser integration.