xuhcc / beancount-ethereum-importer

Ethereum transaction importer for Beancount
GNU General Public License v3.0
12 stars 5 forks source link

get balances for each token from API #5

Open grostim opened 2 years ago

grostim commented 2 years ago

Hi!

Have you considered gathering token balance from API ?

With Blockscout it should be pretty straightforward thanks to : https://blockscout.com/xdai/mainnet/api?module=account&action=tokenlist&address=0x

With etherscan and clones, it should be more work as you need to make one request per token, and we will a dict to list the tokens to be checked.

https://api.etherscan.io/api
   ?module=account
   &action=tokenbalance
   &contractaddress=0x57d90b64a1a57749b0f932f1a3395792e12e7055
   &address=0xe04f27eb70e025b78871a2ad7eabe85e61212761
   &tag=latest&apikey=YourApiKeyToken

I am wondering what would be neatest way to implement that without breaking the current behaviour ? I was thinking about using the downloader to create a separate json file with the balances, and then a separate importer dedicated to the balance statements.

What do you think ?

xuhcc commented 2 years ago

I was thinking about using the downloader to create a separate json file with the balances, and then a separate importer dedicated to the balance statements.

This sounds like a way to go

But why do you want for insert balance statements?

grostim commented 2 years ago

It's a good practice with beancount to insert balance statement on a regular basis for each account as an integrity checkpoint. https://beancount.github.io/docs/beancount_language_syntax.html#balance-assertions

xuhcc commented 2 years ago

Ok, I will accept a PR if you implement this. I think downloaded balances should be saved to separate files with names like {config_name}_balances.json. But instead of making separate importer, we can add new options to downloader.py and importer.py to avoid code duplication.

grostim commented 2 years ago

I agree.

I'll think about it.