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

Question: How do you consider transactions between different wallets? #1

Closed cristobaltapia closed 5 years ago

cristobaltapia commented 5 years ago

Hi,

first I wanted to thank you for this very nice library. I am trying to use it to do my tax declaration but there is something I don't understand: how do you consider transactions between your wallets: e.g. if you buy a 1 BTC in a website and then transfer it to your personal wallet (like a Trezor). Then you are not really selling your bitcoin.

probstj commented 5 years ago

Hi,

well, thanks for your nice feedback! I'm glad someone is considering to use it. ;)

That is actually no problem at all. For example, have a look at the file Transactions2017.pdf in the example_output folder (unfortunately the example pdf is in German): In line 2 some BTC is withdrawn from one exchange, on the next line it is deposited to another exchange. These transactions are not considered in the final report (except the fees, which are subtracted from profits).

For the report you'll need a ccgains.BagFIFO object. Now you have a couple of options to feed your transactions to this BagFIFO:

  1. First create a TradeHistory object which allows you to import from a (currently still a small) selection of exchanges (more specific, from csv files exported from these exchanges) - In these csv files withdrawals and deposits should be marked as such (you could also add support for the exchanges you use there, I'll also help you with that, then you could make a pull request to improve ccGains). Then just use BagFIFO.process_trade to process all trades like it is done in the example.py. OR
  2. You could populate a TradeHistory object manually with transactions: A normal transaction, where you sold BTC, will have both a buy_amount and a sell_amount greater than zero. These are the ones considered for capital gains (see also 'Transactions2017.pdf'). I you create a transaction with zero sell_amount, it will be a deposit. Or a transaction with zero buy_amount will be a withdrawal. So for a transaction between wallets, you'll need one of each: one with zero buy_amount (for the wallet withdrawn from) and one with zero 'sell_amount' (for the receiving wallet). Then you'll feed the transactions to BagFIFO.process_trade like above. OR
  3. You could directly call BagFIFO.process_trade for your transactions (using Trade objects like in 2.) or more specific use BagFIFO.withdraw and BagFIFO.deposit, one for the sending and one for the receiving wallet/exchange.

Internally, the BagFIFO object will keep track on which exchanges/wallets your funds are and won't mix them. You just need to call your wallets differently (all relevant methods have an 'exchange' parameter accepting a string).

probstj commented 5 years ago

Just to make myself clear (and maybe answer your question better): In the software, there is no difference whether you deposit funds onto an exchange or onto your private wallet, like a Trezor. So if you have a csv file with all deposits and withdrawals onto and from your Trezor, it is possible to add an 'import_trezor_csv' method to TradeHistory (like I mentioned in 1. above). If you create your transactions manually, call your exchange 'Trezor' or 'BTC-Wallet_123' and it will work. :)

cristobaltapia commented 5 years ago

Thanks for your answer!

That is actually no problem at all. For example, have a look at the file 'Transactions2017.pdf' in the 'example_output' folder (unfortunately the example pdf is in German)

That's no problem: I live in Germany, too :P So for me it is perfect that the example is in German.

Yeah, I'll try to do a function like append_trezor_csv(). I actually already have the param_locs for it, but I wasn't sure of how the software would consider exactly the deposits and withdrawals, so thanks for clarifying that. I also have the param_locs for bitpanda.com. (but the csv file given there has to be manually edited, because there are basically two tables in one file).

What I did in the mean time was to put all transactions in one csv file... but I think that is not optimal. I'll try the better way now. Thanks!

probstj commented 5 years ago

Yeah, I'll try to do a function like append_trezor_csv(). I actually already have the param_locs...

Perfect, that's exactly the way to do it! :) (...with simple csv formats - unlike the bitpanda csv) For the bitpanda import, I think it would be better to not use param_locs, because of the special csv format. And then make a 'custom' import method append_bitpanda_csv, like I've done e.g. with append_bisq_csv. I don't like that one would need to manually edit a file before importing. I have no idea how the bitpanda csv looks like, though. Could you attach here an abridged version of the csv, with fake data?

cristobaltapia commented 5 years ago

Sure, here is a cleaned and anonymized version:

"Disclaimer: All data is without guarantee, errors and changes are reserved."
"Jon Doe, 1967-10-14"
foo@bar.com
Trades and Fiat Wallets transaction history
ID,Type,In/Out,Amount Fiat,Fee,Fiat Currency,Amount Cryptocoin,Cryptocoin,Status,Created at
8e909fda-7e9d-4991-97bf-4a2a44dc7814,sell,incoming,1000.46000000,-,EUR,0.10000000,BTC,finished,2017-12-07T18:47:31+01:00
9138029f-d992-433e-9a9d-e6448774b191,withdrawal,outgoing,1261.46,0.00,EUR,-,-,finished,2017-12-07T18:47:31+01:00
425421618779169942,buy,outgoing,2788.40000000,-,EUR,0.20475923,BTC,finished,2017-12-10T05:21:15+01:00
525771368009594176,sell,incoming,2138.11000000,-,EUR,0.15475923,BTC,finished,2017-12-11T21:16:53+01:00

Wallet Transactions history
ID,Type,In/Out,Amount Fiat,Fee,Fiat Currency,Amount Cryptocoin,Cryptocoin,Status,Created at
df7f72c0-dc35-11e7-a69c-058397581a5f,deposit,incoming,310.5,0.00,EUR,0.10000000,BTC,finished,2017-12-08T17:35:59+01:00
307640030740494708,withdrawal,outgoing,0,0.00,EUR,1.71908767,DASH,finished,2017-11-12T21:32:21+01:00
740309250212121399,deposit,incoming,0,0.00,EUR,1.00000000,DASH,finished,2017-11-30T19:39:12+01:00
cristobaltapia commented 5 years ago

Well, I think that I can close this now. ;)