Code Monkey home page Code Monkey logo

bitcoin-taxes's Introduction

Bitcoin Capital Gains Tax Calculator

This is a Python script that attempts to calculate your capital gains/losses based on your transaction history(ies).

First, a disclaimer: I am not an accountant or otherwise authorized to give tax advice. This code is released under the GPL, which in particular disavows all responsibility for the accuracy of these results. That being said, I hope it's helpful and I've been using it for years myself.

Method

For tax purposes, this script treats bitcoin as personal property, consistent with IRS Notice 2014-21. Every sale is a taxable event, and the gains computed by taking the difference between the sale price and cost basis. As bitcoins are bought and sold in fractional amounts, a sale's gain is computed against one or more buys.

The lot selection method is configurable, defaulting to FIFO (first in first out). Deposits (e.g. from mining) are considered income unless otherwise specified, and withdrawals sales (again, unless otherwise specified). Among the options for withdrawals, a purchase is taxed as a sale and an expense offsets income. Actual transfers out must be taxed manually when sold externally. The suggested "fair market" value for these transfers is pulled from https://blockchain.info/charts/market-price. When running in interactive mode, user input will be saved in a JSON file (defaulting to external_transactions.json) and not asked again. This file can be edited manually or removed to re-evaluate the nature of a transaction.

Transfers between known accounts are automatically detected.

A final report is generated, listing the total gains and losses per month/year/all time, the lots in each account, etc. Realized long-term gains (or losses) are split out in separate column, short term gains are the difference between realized gains and long-term gains. Long-term gift exempt gains are also split out for ease in itemizing charitable contributions. (Note that for gifts exceeding $5,000 in value, a qualified appraisal and signed Form 8283 is also required to claim the deduction. Some options are CharitableSolutions or CryptoAppraisers or finding another appraiser willing to do the research on Bitcoin.) This should be sufficient information to file your taxes. There are a couple of options listed in --help to provide even more detailed reports and options. In particular, the --cost_basis flag is quite useful.

Use

First, download/export all the transaction histories from all your exchanges/wallets. Several exchanges (e.g. Bitstamp, Coinbase, Gdax, Kraken, and MtGox) are supported; more formats can be easily added. Note that for MtGox both the BTC and USD files must be downloaded (with BTC or USD in the filename) as neither has the full history. Transactions exported from your local wallets such as Electrum and Bitcoin Core can be imported (e.g. bitcoin-cli listtransactions '*' 1000000 > local-accounts.json). Additionally, any set of public addresses (e.g. from a wallet that does not support export) can be treated as a single account by simply enumerating them in a text file.

Run the script as

python3 bitcoin_gains.py transaction_downloads/*.csv local-accounts.json ...

This script will be interactive, it will ask questions about external transfers. To accept all the defaults (as explained above) one can use the -y option. At any point you may enter "quit" and it will remember the answers you have provided so far.

bitcoin-taxes's People

Contributors

guhur avatar jeremyrand avatar robertwb avatar sophom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitcoin-taxes's Issues

Is support for cryptocurrencies other than BTC planned?

I was trying to take ALL my transactions from Coinbase Pro and generate my tax data. However, I bought/sold more than BTC on that account. I saw here that maybe you were planning on supporting other cryptocurrencies. I was wondering if you have made any progress on that? I might be interested in helping in that effort, but I'm not too familiar with Python. I could probably figure it out, but if you would like help it'd be great if you could give me some pointers on what would be needed to make this work. Thanks!

Problem dealing with wallet transfers

Hello,

The code seems to have a problem with an internal transfer. I transferred btc from a bitcoin-qt wallet to an electrum wallet. I run the script as follows:

./bitcoin_gains.py --consolidate_bitcoind bitcoin-qt_2017.json electrum_2017.csv
The error I get look like this:

Traceback (most recent call last):
  File "./bitcoin_gains.py", line 1354, in <module>
    main(parsed_args)
  File "./bitcoin_gains.py", line 1226, in main
    lost_in_transfer -= lost.btc
AttributeError: 'NoneType' object has no attribute 'btc'

Please let me know if you need me to try a fix.

Atomic payments are dropped

If a Bitcoin Core wallet sent funds to multiple addresses in a single transaction, only one of the outputs will be counted.

Transfers from Coinbase to public address not "matched"

Several transfers listed in a Coinbase csv file were not matched in the list of transactions derived from a list of public addresses. The result is that several transfers from Coinbase to my public address are incorrectly identified as external transactions.

It appears that the BTC amount reported by Coinbase and the amount actually transferred into my public address do not match exactly. For example, the Coinbase csv file reports one transfer of the amount -0.85301237 BTC, but the actual amount transferred to my public address was 0.8530 BTC. The Coinbase csv file reports the transaction hash in the last column which I can use to confirm the discrepancy between amounts. As a workaround, I have manually edited my Coinbase csv file to split each misidentified transaction into one amount which matches excactly the amount in the public bitcoin transaction, and one additional transaction for the remaining amount which will be categorized as an expense.

Document Transaction.btc/usd

At a quick glance at the Transaction class, it is not immediately obvious whether the btc and usd attributes include or exclude the fee. It would be nice if there were a comment for this class's definition that clarifies this aspect of the API. (Based on looking at the BitcoindParser class implementation, I am reasonably confident that it excludes the fee.)

Coinbase Transactions Aren't Processed

Coinbase must have changed the format of the .csv they make available; the rows are much different than as specified in the Coinbase parser and the entire parser will need to be updated.

"Is this a Sale, Purchase, Expense, or Transfer" is confusing for novices

As a novice to taxes, I found the question "Is this a Sale, Purchase, Expense, or Transfer" confusing. Purchasing something is an expense, and constitutes selling my BTC for that product, which constitutes transferring my BTC to the person I bought it from. I realize that these all mean different things in tax terminology, but it would be more usable for novices if an example were provided for each answer along with this question prompt.

Merging two Electrum wallets together causes an assertion

When trying to merge two electrum wallets together, the "assert len(transactions) == 1" in merge asserts.

For example let's just say you created a segwit wallet after happily using the old style wallet. Then you moved your bitcoin from the old wallet to the new segwit wallet. When entering both wallet csvs on the command line, the above assertion will assert on the transaction that transfers the funds from the old wallet to the new wallet.

Adding the below to the ElectrumParser seems to fix the problem:

def merge_some(self, transactions):
    return transactions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.