probstj / ccGains

Python package for calculating cryptocurrency trading profits and creating capital gains reports
GNU Lesser General Public License v3.0
49 stars 13 forks source link

Obtain fees with `blockcypher` library #5

Closed cristobaltapia closed 5 years ago

cristobaltapia commented 5 years ago

I found this library (blockcypher-python [1]) that can be used to get the real fees from a given transaction. Maybe it could be integrated?

It works like this

from blockcypher import get_transaction_details, from_satoshis

tx = get_transaction_details('b44003aaad20e7dffd66c7bf7f9f9abc4498de1932476c4db7fc62f5b330f64b')
fees = from_satoshis(tx['fees'], 'btc')
print(fees)
>>> 1.014e-05

[1] https://github.com/blockcypher/blockcypher-python

cristobaltapia commented 5 years ago

I made a fast implementation of this to try it out here. It works for me at least. I assume that the TX-id is in the 'mark' entry.

probstj commented 5 years ago

I like the blockcypher idea very much. But I understand that it will only include the blockchain fees? Most (all?) exchanges charge other fees, higher than the pure blockchain fees, so that will only work with your own wallet, like Electron or Trezor. Doesn't the Electron and Trezor csv files include these fees?

In my logic, it is the fault of the csv files from some exchanges (like poloniex) who don't include the fees. If it would be possible to get these fees (like for example from blockcypher) already when importing the csv files, I think it would be much cleaner to do it right there in the append_..._csv-method. I really don't like that hackish add_missing_transaction_fees method, but found no better way since it must be called when all csvs from all wallets were imported. Blockcypher doesn't need to work that way. So if the fees are not included in the Electron or Trezor csv files, could you move the blockcypher functionality to their respective append_ methods?

Then another thing I had in mind with the whole project was privacy. If you poll blockcypher only for your transactions, they know exactly your transaction history, i.e. which transactions and wallets belong to a single IP, right? It would be nice to poll a couple of extra transactions just as disguises, but that's a wish that can be implemented at a later time. If you add the functionality to the append_ methods, could you turn it off by default so the user needs to turn them on knowingly? Then write a little warning about the issue in the docstring?

cristobaltapia commented 5 years ago

That was exactly my problem, i.e. that the Electrum csv-files do not contain the fees (the Trezor does include them). So I think that your suggestion is cleaner: to get the missing fees at the moment of appending the specific csv-file, for which we know the fees are missing (like for the case of the Electrum wallet csv-file). I'll try to work on that. ;)

probstj commented 5 years ago

I'm closing this, since there is already a pull request covering this issue.

cristobaltapia commented 5 years ago

Sorry I didn't take care of this is a while. I am just fighting with my thesis at the moment haha

probstj commented 5 years ago

Hey man, that's no problem at all. I completely understand, I'm fighting with the same issue! Good luck, progress and success to you with that! Very happy to hear you are still around! :)