Quick-and-dirty script for calculating cryptocurrency capital gains for tax purposes.

Overview

CrypTax

Software for calculating cryptocurrency capital gains for tax purposes. Calculation with LIFO method, developed with Italy in mind.

Screencast
The screencast is made with random transactions. They are not my holdings.

⚠️ Please read here before use

  • This is just the software I use for my tax reports. It's not perfect and it's not production ready, use it at your own risk.
  • At the moment in Italy there is no clear regulation regarding the declaration and taxation for cryptocurrencies and capital gains, so some of the logic used in this software could come from my interpretations. I take no responsibility about it. Always DYOR (Do Your Own Research).

ℹ️ What this software does

At the moment, the features of this software are quite limited, but they are the most inconvenient and time-consuming to do manually, at least in my case.

In fact, it is just a script that takes in input a csv file with all your transactions, and elaborates a quite complete and printable report. In the future I plan to make it a more complete software, maybe even with a nice front-end.

How to use it

  • Put the project folder in a web server with PHP;
  • create a copy of the file config.sample.php in config.php, and set inside it the credentials of the MySQL database (it will be used as a cache for cryptocurrency prices) and the location of the transactions.csv file;
  • visit index.php through a web browser.

📄 The transactions.csv file

  • The csv file must have 7 columns, separated by semicolon ;.
  • The file must not have a header row.

This is the description of the fields:

  1. transaction_date: in dd/mm/yyyy format
  2. transaction type: purchase, sale or expense (or the correspondents in Italian: acquisto, vendita or spesa)
  3. EUR value: the value of the transaction in euros, including commissions
  4. cryptocurrency amount: amount of cryptocurrency bought, sold or spent; without thousands separators, using the dot . as decimal separator
  5. cryptocurrency ticker: usually a 3 characters string, like BTC, ETH or BNB
  6. exchange: name of the exchange where the buy or sell has been done; this is only for the volume chart, you can leave it empty if you are not interested
  7. earning category: for purchase/acquisto type transactions with price = 0, you can set the earning category; it affects some calculations in the final report

Earning categories

  • airdrop: a capital gain is calculated equal to the value of the cryptocurrency on the day of the transaction
  • interessi/interest: are considered as redditi di capitale, taxed at a rate of 26%
  • cashback: the value at the day of the transaction is not taxed, but only the eventual capital gain at the time of the sale

please note: these are the considerations this software does, but they may not be the correct ones! DYOR and/or consult an expert!

Comments
  • Check why the cron job is not working properly

    Check why the cron job is not working properly

    cron.php currently performs two tasks:

    • deletes temporary files older than 12 hours (they contain encrypted transactions of users, if CrypTax is used in "public" mode)
    • update the expired cached prices (including prices that expire in the next 60 minutes)

    The cron job on core.cryptax.xyz runs every 30 minutes, so there should never be expired prices in the database, but it seems that this is not the case.

    Deleting temporary files works correctly, while updating cached prices needs to be reviewed.

    bug 
    opened by cristianlivella 3
  • Consider removing

    Consider removing "expense" transaction type

    "Expense" transaction type was originally intended to insert transactions as network fees, that did not have a well known countervalue.

    For tax purposes they have always been treated by CrypTax as sales, using the daily price from CryptoHistory.

    The only difference is that they were ignored when calculating the total investments for the year (Investimenti anno corrente).

    With the merge of PR #35 they are now considered as sales, so maybe it no longer makes sense to maintain the "expense" type, which has often also created confusion among new users.

    enhancement 
    opened by cristianlivella 1
  • Implement an alternative method to calculate the final value (RW, field 8)

    Implement an alternative method to calculate the final value (RW, field 8)

    At the moment the final value for the RW models is calculated as the average stock, using the prices of the day 31/12, as suggested in the guide Aspetti fiscali: Criptovalute e Bitcoin, Giorgio D’Amico, 4th edition, page 17.

    An alternative way is to use the actual value of the day 31/12, to which the values of sales made during the year should be added.

    We need to implement this alternative method, and allow the user the choice.

    enhancement 
    opened by cristianlivella 1
  • Make transaction id optional

    Make transaction id optional

    The id was initially required when the capital gain calculation was semi-manual.

    Now that the calculation is fully automatic, the id of each transaction can be generated automatically, and then we can make it optional in the .csv file.

    enhancement 
    opened by cristianlivella 1
  • Save the transaction array in a json file, after the first read from the source CSV/XLS file

    Save the transaction array in a json file, after the first read from the source CSV/XLS file

    The parse of a CSV file with ~100000 transactions takes about 6.5 seconds on my laptop.

    Saving the array to a json file doesn't take any significant additional time.

    Successive reads of the array from the json file only take about 0.1 seconds, so this is definitely a change to make.

    Encryption and decryption with AES does not seem to affect the loading time significantly, so the json file can be encrypted with the same key as the source file, before being saved.

    Originally posted by @cristianlivella in https://github.com/cristianlivella/cryptax/issues/14#issuecomment-980017121

    performance 
    opened by cristianlivella 0
  • Make column 3 (EUR value) optional

    Make column 3 (EUR value) optional

    In case column 3 is empty (or 0), and also column 7 is empty, automatically calculate the value of the transaction using cryptocurrency price on that day.

    enhancement 
    opened by cristianlivella 0
  • Display a message if the report is incomplete

    Display a message if the report is incomplete

    The report may be incomplete if:

    • you try to process the report of the current year: in this case the prices of 3 days ago are used as end of year prices*;
    • some of your cryptocurrency prices are not available on cryptohistory.one: in this case those cryptocurrencies will not be present in the report.

    In either case, it would be helpful to inform the user with a message

    * this is because of the cryptohistory.one API, that doesn't always have prices for the last 2-3 days

    enhancement 
    opened by cristianlivella 0
  • Add fiscal year selector

    Add fiscal year selector

    By default, the script processes the report for the current fiscal year. You can process a specific year through the year GET parameter.

    It would be useful to add links/buttons to be able to view the report for a year other than the current one, without having to manually set the GET parameter.

    This feature is currently not documented on the README file.

    documentation enhancement 
    opened by cristianlivella 0
  • Refactor fetchGlobalCryptoData function

    Refactor fetchGlobalCryptoData function

    Actually the fetchGlobalCryptoData function is a total mess.

    The initial idea was to optimize the number of requests to the API and database by grouping near dates. However, the result is a fairly complicated and unreadable function.

    It is probably simpler and more efficient every time we need to request data regarding cryptocurrency prices from the database or API, to always request the next 365 days of data as well and save it in RAM.

    enhancement 
    opened by cristianlivella 0
  • Make the software deployable

    Make the software deployable

    At the moment the script parses the transactions it takes in a file in a local location.

    This makes it usable only by installing a local PHP server, and makes it unusable for people who do not have advanced technical knowledge.

    It would be useful to make a page where you can upload the file with the transactions to be processed, so that the software can be published on a public web server and make it usable for everyone.

    Ideally, my idea would be that the user uploads a CSV/XSL file with his transactions, and then a ZIP file is generated containing the report of all the years, and the fac simile of the declaration forms (see issue #3)

    enhancement 
    opened by cristianlivella 0
  • Improve data validation

    Improve data validation

    Data validation at the moment is very poor, it is possible for example to have negative balances, or other strange situations that generate errors.

    There is a need to review and improve the validation of the transactions in the input file.

    bug enhancement 
    opened by cristianlivella 0
  • Implement an alternative method to calculate the initial value (RW, field 7)

    Implement an alternative method to calculate the initial value (RW, field 7)

    At the moment, the initial value corresponds to the equivalent on the first day of the year.

    A more correct way to calculate it would be to add to it the purchases made during the year, as also suggested in the Aspetti fiscali: Criptovalute e Bitcoin, Giorgio D’Amico, 6th edition, page 14.

    Indicare il valore (in Euro) del saldo del portafoglio all’inizio dell’anno oppure nel primo giorno di detenzione della cryptovaluta, utilizzando il cambio della cryptovaluta a inizio anno. A questo valore deve essere sommato il totale dei nuovi investimenti effettuatnell’anno, ovvero l’ammontare dei “depositi” effettuati sugli exchange ed utilizzati per l’acquisto di nuove crypto.

    We need to implement this method, which should be used as the default.

    The calculation is pretty easy, and it's very similiar to the final value one, we just need to add the currentYearInvestment value, if greater than 0.

    enhancement 
    opened by cristianlivella 0
  • Replace floats with arbitrary precision numbers (BigDecimal?)

    Replace floats with arbitrary precision numbers (BigDecimal?)

    The size of a float is platform-dependent, although a maximum of approximately 1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).

    Using floats to represent cryptocurrency costs and amounts causes some approximation issues. In 98119b0 a temporary fix has been made, but it is better to replace all floats completely, using for example Brick Math BicDecimal, to avoid other problems as well (for example, at the moment cryptocurrencies that have more than 14 decimal places, such as Nano, could cause problems).

    bug enhancement 
    opened by cristianlivella 0
  • Add fiscal detailed instructions and sources in the repository

    Add fiscal detailed instructions and sources in the repository

    Considering the increase of circulars from the Agenzia delle Entrate, it would be useful to add some markdown files explaining what the current regulatory situation is in Italy.

    In this way it would be easy for everyone to have an overview of the situation, propose and monitor changes.

    In addition, we might think of creating a directory where we can save the regulatory sources (from Agenzia delle Entrate, TAR, ecc..).

    documentation 
    opened by cristianlivella 0
  • It must be possible to set settings from the config.php file (for standalone/private mode)

    It must be possible to set settings from the config.php file (for standalone/private mode)

    At the moment there are some settings that can be set, prior to elaborate a report:

    • compensate losses: Italian legislation provides that capital gains may be compensated with any capital losses of the previous 5 years. However, the user can choose not to do so (he will pay more taxes, but will probably be subject to fewer controls by the revenue agency);
    • exchange earnings types: in cases of interest earned, for each exchange/service the user can choose whether to declare them in the RM or RL section of the fiscal income statement (the legislation is unclear, so various tax experts have different ideas about this);
    • postpone crypto-to-crypto-gains: the revenue agency's position seems to be to consider capital gains even between crypto-to-crypto trades, but some people don't think that's correct, and there's even a bill proposing the opposite. With this option, the user can then choose to postpone capital gains to the time of sale in euros.

    Currently in the public mode (with the frontend) of the application, the settings are made using the web UI and saved in a cookie.

    In private mode, however, it is not possible to easily change these settings. It is therefore necessary to introduce the possibility to manage them in the config.php file.

    Note that the last point has not actually been implemented yet, but is in progress (see issue #20).

    bug enhancement 
    opened by cristianlivella 0
  • Implement crypto-to-crypto transactions processing

    Implement crypto-to-crypto transactions processing

    At the moment all transactions have the euro as their base currency. Therefore, exchanges between cryptocurrencies are not handled.

    It is necessary to implement this functionality.

    For exchanges between cryptocurrencies it must be possible to choose whether:

    • calculate capital gains on each trade (as currently provided for by the interpretations of the "Agenzia delle Entrate" (the Italian revenue agency);
    • calculate the capital gains only when the sale is made in euro (as provided for by the bill 3131/2021).

    Branch: crypto-to-crypto-trades

    enhancement 
    opened by cristianlivella 0
  • Improve file reading performance

    Improve file reading performance

    PhpSpreadsheet uses a lot of memory in order to read the input file.

    Roughly ~400 MB of RAM are used for elaborate a report with ~200.000 transactions. Of these, about 350 MB are used by PhpSpreadsheet.

    This seems to be a known and frequent problem: https://phpspreadsheet.readthedocs.io/en/latest/topics/memory_saving.

    We need to consider replacing it with Spout, because of the supported file formats (csv, xsls and ods).

    Spout seems to use much less memory (they say 3 MB, regardless of file size), but seems to be less smart about recognizing file types and delimiters for CSV files.

    We could use PhpSpreadsheet to recognize the file type and delimiters, and then Spout to actually read the file.

    performance 
    opened by cristianlivella 1
Releases(v1.4.2)
  • v1.4.2(Aug 18, 2022)

    What's Changed

    • 🐛 Section RW shouldn't be counted for choosing field 18 value by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/40

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.4.1...v1.4.2

    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Jun 8, 2022)

    What's Changed

    • 🚑️ Fix stupid bug by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/38

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.4.0...v1.4.1

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jun 8, 2022)

  • v1.3.0(Mar 19, 2022)

    What's Changed

    • 👔 Fix in the calculation of RW final value using method "real_value_more_incomes" by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/35
    • ✨ Add setting to choose if consider earnings and expenses as investments by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/37

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Mar 17, 2022)

    What's Changed

    • 🍱 Add template Redditi 2022 (fiscal year 2021) by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/29
    • 🚑️ Converted PDF file to version 1.4 by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/30
    • ✨ Hardcoded EURx stablecoin (Nexo) by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/31
    • 🚑️ Fix static method calls by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/32
    • ✨ Implemented new methods for RW final value calculation (fix #19) by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/34

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.1.3...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.3(Jan 10, 2022)

    What's Changed

    • 🐛 Temporary fix for float approximation by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/25
    • 🐛 Add missing use, other fix for float approximation by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/26
    • 🐛 Removed duplicated exchange names by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/27
    • 🚑️ RAP earnings (realizzati anni precedenti) should not be considered for tax purposes by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/28

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.1.2...v1.1.3

    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(Jan 5, 2022)

    What's Changed

    • 🐛 Fix bug in CannotFindPurchase usage, add temp fix for float precision by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/23

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.1.1...v1.1.2

    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Dec 3, 2021)

    What's Changed

    • Fix cron job and vulnerabilities by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/17

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v1.1.0...v1.1.1

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Nov 21, 2021)

  • v1.0.1(Nov 21, 2021)

  • v1.0.0(Nov 20, 2021)

    What's Changed

    • V1 major update by @cristianlivella in https://github.com/cristianlivella/cryptax/pull/12

    New Contributors

    • @cristianlivella made their first contribution in https://github.com/cristianlivella/cryptax/pull/12

    Full Changelog: https://github.com/cristianlivella/cryptax/compare/v0.1.1...v1.0.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Nov 5, 2021)

  • v0.1.0(Nov 4, 2021)

Owner
Cristian Livella
🇮🇹 20 y/o, student and developer
Cristian Livella
Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

Dries Vints 1.1k Jan 1, 2023
Twitter clone - This project is conducted for learning purposes only

Twitter clone - This project is conducted for learning purposes only

Wanderson Renê 2 Jun 24, 2022
HiDomainer One-File Domain Portfolio Script, is a PHP script of only 8kb.

HiDomainer One-File Domain Portfolio Script, is a PHP script of only 8kb. Download Feature 1. PC and Mobile Friendly 2. Data management without page r

HiDomainer.com 1 Mar 2, 2022
A slim, lean forum package designed for quick and easy integration in Laravel projects

Complete documentation is available on teamteatime.net. Installation Requires Laravel 6+ and PHP 7.4+. Step 1: Install the package Install the package

TeamTeaTime 486 Dec 31, 2022
ULEARN - Open Source(FREE) LMS script in Laravel 5.8 and ReactJS 16.9

About ULEARN Key Features Demo & Credentials Access ReactJS Page Installation Support License About ULEARN ULEARN is an impressive LMS script which co

null 535 Jan 2, 2023
This is a project that was created for the main purpose of practising front end technology(HTML, CSS and Java-Script) with a litle addition of back-end technology.

This is a project that was created for the main purpose of practising front end technology(HTML, CSS and Java-Script) with a litle addition of back-end technology. This is a restaurant website which is to offer services such as ordering goods through sending of emails, viewing of any order, signing-in/up for customer's who want to order food, and much more, with also some live features like dates of the day alongside opening and closing working ours. So let's jump right into it.

null 1 Nov 26, 2021
phpSysInfo: a customizable PHP script that displays information about your system nicely

phpSysInfo Copyright (c), 1999-2008, Uriah Welcome (sf.net/users/precision) Copyright (c), 1999-2009, Michael Cramer (sf.net/users/bigmichi1) Copyrigh

phpSysInfo 1.3k Jan 1, 2023
Stream Site with a auth script for OvenMediaEngine

OvenMediaEngine Stream Site Two PHP pages, one for authentication. The other is for displaying the streams. License AGPL Previews Installation Require

Katie 1 Oct 15, 2021
A little PHP script created for uploading custom sharex files to your own webserver

ShareX-Custom-Upload A little PHP script created for uploading text, files, and images to your own webserver. It supports uploading via ShareX, but al

Joe Gandy 161 Dec 13, 2022
A free and open-source accounting and production system for businesses and non-profits with support for multiple users and varied integrations

A free and open-source accounting and production system for businesses and non-profits with support for multiple users and varied integrations.

null 3 Sep 22, 2022
Emoncms is an open-source web application for processing, logging and visualising energy, temperature and other environmental data and is part of the OpenEnergyMonitor project.

Emoncms is an open-source web application for processing, logging and visualising energy, temperature and other environmental data and is part of the OpenEnergyMonitor project.

Emoncms 1.1k Dec 22, 2022
Created simple login system and chat type website using mysql database along with php and html , css and javascript.

Created simple login system and chat type website using mysql database along with php and html , css and javascript.

null 1 Jan 6, 2022
This prj we have two NODEMCU ( ESP8266) and two RFID_RC522 and some rfid tags we used ARDUINO IDE on NODEMCU and running server with XAMPP

This prj we have two NODEMCU ( ESP8266) and two RFID_RC522 and some rfid tags we used ARDUINO IDE on NODEMCU and running server with XAMPP

Mohammadamir Soltanzadeh 2 Mar 29, 2022
Rafa Cake and Bakery is a web-based application project that aims to introduce Rafa Cake and Bakery, introduce what products are sold and can also order them via Whatsapp.

Rafa-cake-and-bakery Rafa Cake and Bakery is a web-based application project that aims to introduce Rafa Cake and Bakery, introduce what products are

Aan Evian Nanda 2 Jun 19, 2022
A great looking and easy-to-use photo-management-system you can run on your server, to manage and share photos.

Lychee A great looking and easy-to-use photo-management-system. Since the 1st of April 2018 this project has moved to it's own Organisation (https://g

Tobias Reich 6.2k Jan 5, 2023
TinyFileManager is web based file manager and it is a simple, fast and small file manager with a single file, multi-language ready web application

TinyFileManager is web based file manager and it is a simple, fast and small file manager with a single file, multi-language ready web application for storing, uploading, editing and managing files and folders online via web browser. The Application runs on PHP 5.5+, It allows the creation of multiple users and each user can have its own directory and a build-in support for managing text files with cloud9 IDE and it supports syntax highlighting for over 150+ languages and over 35+ themes.

Prasath Mani 3.5k Jan 7, 2023
Open source ERP software. Built on modern PHP and bootstrap 4. Easy and powerful.

FacturaScripts Open source ERP software. Built on modern PHP and bootstrap 4. Easy and powerful. Install Clone and deploy with composer and npm (compo

Carlos Garcia 313 Jan 4, 2023
OpenEMR is a Free and Open Source electronic health records and medical practice management application

OpenEMR is a Free and Open Source electronic health records and medical practice management application. It features fully integrated electronic health records, practice management, scheduling, electronic billing, internationalization, free support, a vibrant community, and a whole lot more. It runs on Windows, Linux, Mac OS X, and many other platforms.

OpenEMR 2.1k Jan 9, 2023