Code Monkey home page Code Monkey logo

yabc's Introduction

yabc on PyPI MIT License badge yabc on TravisCI Supported Python versions

yabc - a bitcoin tax calculator

yabc translates cryptocurrency trades, mining, and spending data into a list of reports that can be sent to tax authorities. It is most useful for cryptocurrency traders in the US.

yabc is the tax calculator behind https://velvetax.com/.

$ python -m yabc testdata/gemini/sample_gemini.xlsx ./testdata/coinbase/sample_coinbase.csv
14 transactions to be reported
<CostBasisReport: Sold 0.76 BTC on 2008-04-21 01:12:00 for $236. Exchange: coinbase. Profit:$-155.
	<TX 2008-04-21 01:12:00 SELL 1993.93 USD for 6.26 BTC, from exchange coinbase. Fee 48.44 USD>>
<CostBasisReport: Sold 1 BTC on 2008-04-21 01:12:00 for $311. Exchange: coinbase. Profit:$29.
	<TX 2008-04-21 01:12:00 SELL 1993.93 USD for 6.26 BTC, from exchange coinbase. Fee 48.44 USD>>
<CostBasisReport: Sold 2 BTC on 2008-04-21 01:12:00 for $622. Exchange: coinbase. Profit:$546.
	<TX 2008-04-21 01:12:00 SELL 1993.93 USD for 6.26 BTC, from exchange coinbase. Fee 48.44 USD>>
<CostBasisReport: Sold 2.5 BTC on 2008-04-21 01:12:00 for $777. Exchange: coinbase. Profit:$666.
	<TX 2008-04-21 01:12:00 SELL 1993.93 USD for 6.26 BTC, from exchange coinbase. Fee 48.44 USD>>
<CostBasisReport: Sold 0.07453875 BTC on 2017-12-01 20:14:32.284003 for $786. Exchange: gemini. Profit:$748. Long term.
	<TX 2017-12-01 20:14:32.284003 SELL 788.39635875 USD for 0.07453875 BTC, from exchange gemini. Fee 1.970990896875 USD>>
<CostBasisReport: Sold 0.0429050269 BTC on 2017-12-24 23:04:26.829998 for $594. Exchange: gemini. Profit:$572. Long term.
	<TX 2017-12-24 23:04:26.829998 SELL 595.35873426978 USD for 0.0429050269 BTC, from exchange gemini. Fee 1.48839683567445 USD>>
<CostBasisReport: Sold 0.35608537 BTC on 2017-12-24 23:04:27.855999 for $4929. Exchange: gemini. Profit:$4746. Long term.
	<TX 2017-12-24 23:04:27.855999 SELL 4941.111811194 USD for 0.35608537 BTC, from exchange gemini. Fee 12.352779527985 USD>>
<CostBasisReport: Sold 0.0010096031 BTC on 2017-12-24 23:04:33.120005 for $14. Exchange: gemini. Profit:$13. Long term.
	<TX 2017-12-24 23:04:33.120005 SELL 14.00945453622 USD for 0.0010096031 BTC, from exchange gemini. Fee 0.03502363634055 USD>>
<CostBasisReport: Sold 0.5 BTC on 2017-12-24 23:56:38.505998 for $7032. Exchange: gemini. Profit:$6775. Long term.
	<TX 2017-12-24 23:56:38.505998 SELL 7049.995 USD for 0.5 BTC, from exchange gemini. Fee 17.6249875 USD>>
<CostBasisReport: Sold 0.035 BTC on 2018-01-14 02:30:07.163003 for $496. Exchange: gemini. Profit:$478. Long term.
	<TX 2018-01-14 02:30:07.163003 SELL 497.441 USD for 0.035 BTC, from exchange gemini. Fee 1.2436025 USD>>
<CostBasisReport: Sold 0.03518002 BTC on 2018-01-14 02:30:08.652997 for $498. Exchange: gemini. Profit:$480. Long term.
	<TX 2018-01-14 02:30:08.652997 SELL 499.5080873726 USD for 0.03518002 BTC, from exchange gemini. Fee 1.2487702184315 USD>>
<CostBasisReport: Sold 0.03447186 BTC on 2018-01-14 02:30:10.102003 for $488. Exchange: gemini. Profit:$470. Long term.
	<TX 2018-01-14 02:30:10.102003 SELL 489.4531855518 USD for 0.03447186 BTC, from exchange gemini. Fee 1.2236329638795 USD>>
<CostBasisReport: Sold 0.01057786 BTC on 2018-01-14 02:30:10.911001 for $150. Exchange: gemini. Profit:$145. Long term.
	<TX 2018-01-14 02:30:10.911001 SELL 150.1911203318 USD for 0.01057786 BTC, from exchange gemini. Fee 0.3754778008295 USD>>
<CostBasisReport: Sold 0.035 BTC on 2018-01-14 02:30:11.599998 for $496. Exchange: gemini. Profit:$478. Long term.
	<TX 2018-01-14 02:30:11.599998 SELL 496.95205 USD for 0.035 BTC, from exchange gemini. Fee 1.242380125 USD>>

total gain or loss for above transactions: 15991

total basis for above transactions: 1438
total proceeds for above transactions: 17429
Remaining coins after sales:
<TX 2007-08-18 01:12:00 BUY 4 BTC for 2048 USD, from exchange coinbase. Fee 11.11 USD>
<TX 2007-08-31 01:12:00 BUY 4 BTC for 97 USD, from exchange coinbase. Fee 11.12 USD>
<TX 2007-09-13 01:12:00 BUY 7 BTC for 102.34 USD, from exchange coinbase. Fee 14.98 USD>
<TX 2007-10-22 01:12:00 BUY 4 BTC for 45.6 USD, from exchange coinbase. Fee 31.9 USD>
<TX 2007-12-13 01:12:00 BUY 8 BTC for 13.2 USD, from exchange coinbase. Fee 32.25 USD>
<TX 2007-12-26 01:12:00 BUY 3 BTC for 98.04 USD, from exchange coinbase. Fee 9.54 USD>
<TX 2008-02-03 01:12:00 BUY 10.23 BTC for 203 USD, from exchange coinbase. Fee 92.2 USD>
<TX 2008-03-13 01:12:00 BUY 5.234 BTC for 302 USD, from exchange coinbase. Fee 30.4 USD>
<TX 2008-04-08 01:12:00 BUY 2.532 BTC for 1776.76 USD, from exchange coinbase. Fee 17.56 USD>
<TX 2015-10-16 06:27:56.139998 BUY 20.2092 BTC for 53.624236 USD, from exchange gemini. Fee 0.13406059 USD>
<TX 2015-10-16 06:27:56.373002 BUY 0.339 BTC for 86.89587 USD, from exchange gemini. Fee 0.217239675 USD>
<TX 2015-10-16 06:28:09.103999 BUY 0.323 BTC for 82.79459 USD, from exchange gemini. Fee 0.206986475 USD>
<TX 2015-10-16 06:28:09.735004 BUY 0.10020404 BTC for 25.6853015732 USD, from exchange gemini. Fee 0.064213253933 USD>

An adhoc CSV format is supported for non-exchange transactions like mining, gifts, and purchases.

yabc also includes a set of HTTP endpoints that allow for storing data more permanently in a database, sqlite by default. Postgres as a backend is also supported.

TODO

  • TODO: Support coin/coin trades like BTC/ETH.
  • TODO: Enable importing from more exchanges (binance)
  • TODO: Add better historical price lookup support; it is now a stub.

Installation from source, with virtualenv

git clone [email protected]:robertkarl/yabc.git
cd yabc
virtualenv -p python3 venv
. venv/bin/activate
python setup.py install

Notes

File structure, setup.py usage, and shields inspired by source of python modules sshuttle, flask, and black.

Caveats

Please note that yabc is not a tax service or tax accounting software and is provided with no warranty. Please see the LICENSE file for more details.

yabc is not associated with any of the mentioned exchanges or companies including but not limited to binance, coinbase, or gemini. Any trademarks are property of their respective owners.

yabc's People

Contributors

robertkarl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gorilik324

yabc's Issues

Support multiple open 'pools'

Required for #62.

Currently the algorithm looks like this:

for each different coin:
  select all tx's that appear to contain that coin
  create an empty pool
  for each tx we selected:
    call process_one()

At the very least we need to make sure that we select the right tx's for each coin.

cost basis reports for coin/coin trades need to lookup prices

resolved when:
the cost basis reports generated from running yabc on adhoc.csv look up a dollar value for the amount of BTC and ETH on that date.

$ python -m yabc /home/rk/code/yabc/testdata/adhoc/adhoc.csv
...
<Sold 10000 ETH on 2018-05-22 00:00:00 for $0. Exchange: adhoc. Profit:$0.
	<TX 2018-05-22 00:00:00 SELL 0.33 BTC for 10000 ETH, from exchange adhoc. Fee 0.001 BTC>>

"Perpetual Futures" contracts

Perpetual futures are a strange beast.

https://help.bybit.com/hc/en-us/articles/360012865933-Bybit-Definition-Features-Uses

Two traders, one short and one long, enter into a contract with each other. Payments are made, typically in BTC, based on price movements in the underlying asset. TODO: Does the exchange take long and short positions with their customers?

bybit, bitmex and deribit offer these contracts.

Make yabc understand them better. AFAIK no IRS guidance has been given about this, so the best way to treat this seems to me to be:

  • First, track the initial deposit to the exchange. This is typically in BTC.
  • Once the user enters into one of these contracts, there is a daily stream of BTC inputs and BTC payments made.
    • For each input, when the price moves in your favor, assign a cost basis to that coin from the current price
    • For each output, when you lose bitcoin, treat this the same as making a payment for something that cost $0. The BTC vanished, you received nothing for it, create a sale at a loss equal to the cost basis.

If the inputs don't make sense, don't panic

If inputs are received with only SELLs, but no BUYS, we currently panic.

Instead detect this and use a cost basis of zero for those sells.

    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/rk/code/yabc/src/yabc/__main__.py", line 42, in <module>
    main()
  File "/home/rk/code/yabc/src/yabc/__main__.py", line 36, in main
    reports = processor.process()
  File "/home/rk/code/yabc/src/yabc/basis.py", line 293, in process
    reports, pool = _process_all(self.method, self.txs)
  File "/home/rk/code/yabc/src/yabc/basis.py", line 257, in _process_all
    ops = process_one(tx, pool)
  File "/home/rk/code/yabc/src/yabc/basis.py", line 128, in process_one
    amount += pool[pool_index].quantity
IndexError: list index out of range

Coin/coin trades

Support markets like ETH/BTC.

These are required for importing trade data from Binance for example.

  • Right now, we have asset_name as a field on Transaction.

Migration plan

  • add new fields to in-memory object (quantity_traded, quantity_received, symbol_traded, symbol_received)
  • Allow passing the new fields to constructor of Transaction
  • Deprecate usd_subtotal and quantity fields
  • Add migrate script to add the fields to existing DBs
  • write the values for 4 new fields to in-memory objects. (Still create Transactions using old syntax, but propagate it to new columns). This ability is critical for migration.
  • Move basis calculation logic to use NEW fields. Stop using usd_subtotal in basis.py. This is the most critical step for making sure basis calculations are still correct.

At this point we should be able to use both syntaxes. Either usd_subtotal and asset_name, or the fully specified one.

  • Migrate ALL usages of Transaction over to new syntax
  • Remove the deprecated parameters from Transaction constructor

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.