rawsontetley.org

Calculating Tax on Crypto Trades

UK tax laws around crypto trading are comprehensive to the say the least. Every trade is classed as a taxable event, not just when you cash out your account back to fiat currency. This is makes it very difficult to calculate your tax liability if you do frequent trades.

There are online services that exist that claim to do this for you, but having seen their output, I can’t work out how they arrived at some of their figures. They also start charging quickly if you want to use their service with any regularity.

I use Coinjar Exchange for crypto trades as they are one of the few exchanges in the UK that have FCA approval. However, I have used Binance in the past and either service will produce you a CSV file of your order fills.

I wrote a Python script to process these files and produce a list of what you are currently holding, along with a list of closed positions.

A closed position is calculated for every sell transaction. Each closed position gives you a profit or loss amount for that trade by working out a cost basis for the sale.

For each sale in your fills file, the script will use the most recent buy price for that coin as the cost basis. If the trade is not buying or selling to fiat currency, it will use the last buy price against fiat for the coin you are exchanging for as the cost basis.

Finally, it will total each closed position to give you an overall profit or loss for a period that you can put on your tax return.

Edit the script and set the ticker and symbol for your fiat currency. For example, I trade with GBP directly rather than stable coins like USDC or USDT. You will also need to set a list of tickers for coins that you have actively traded in the list at the top.

# Which coin represents fiat in your trades (ie. your currency for tax purposes)
FIAT = "GBP"
SYMBOL = "£"

# Coins that you have traded in the period
coins = [ "USDC", "GBP",
    "ALGO", "BTC", "CHZ", "COMP", "CRV", "ENJ", "EOS", "ETH", "LINK", "LTC", "MATIC", "XLM", "XRP", "XTZ",
    "OMG", "AAVE"
]

The script will search for .csv files in the same folder when run. Example output:

Closed positions:

2021-10-04T09:38:19Z, 50.0000 ALGO. buy price £1.2040, sell price £1.4940, cost basis £60.20, sold for £74.70, profit £14.50
2021-10-04T09:38:19Z, 260.0000 ALGO. buy price £1.2040, sell price £1.4930, cost basis £313.04, sold for £388.18, profit £75.14
2021-10-04T09:39:42Z, 100.0000 MATIC. buy price £0.8065, sell price £0.9357, cost basis £80.65, sold for £93.57, profit £12.92
2021-10-16T08:19:46Z, 0.4408 AAVE. buy price £224.5000, sell price £221.2000, cost basis £98.95, sold for £97.50, profit £-1.45
2021-10-16T08:19:46Z, 0.5000 AAVE. buy price £224.5000, sell price £220.8000, cost basis £112.25, sold for £110.40, profit £-1.85
2021-10-16T08:20:45Z, 20.0000 MATIC. buy price £0.8065, sell price £1.1160, cost basis £16.13, sold for £22.32, profit £6.19
2021-10-22T14:34:53Z, 300.0000 MATIC. buy price £1.0940, sell price £1.0960, cost basis £328.20, sold for £328.80, profit £0.60
2021-10-22T14:35:02Z, 30.0000 ALGO. buy price £1.2830, sell price £1.3410, cost basis £38.49, sold for £40.23, profit £1.74
2021-10-22T14:35:02Z, 170.0000 ALGO. buy price £1.2830, sell price £1.3400, cost basis £218.11, sold for £227.80, profit £9.69
2021-10-22T14:35:14Z, 3.2000 COMP. buy price £220.8000, sell price £229.4000, cost basis £706.56, sold for £734.08, profit £27.52
2021-10-22T14:35:26Z, 24.0000 LINK. buy price £20.2800, sell price £21.0200, cost basis £486.72, sold for £504.48, profit £17.76
2021-12-06T09:59:05Z, 40.0000 OMG. buy price £4.7680, sell price £4.3200, cost basis £190.72, sold for £172.80, profit £-17.92
2021-12-06T10:01:31Z, 100.0000 XLM. buy price £0.2181, sell price £0.1880, cost basis £21.81, sold for £18.80, profit £-3.01
2021-12-06T10:01:31Z, 3100.0000 XLM. buy price £0.2181, sell price £0.1879, cost basis £676.11, sold for £582.49, profit £-93.62
2021-12-06T10:01:40Z, 1000.0000 XRP. buy price £0.6065, sell price £0.5727, cost basis £606.50, sold for £572.70, profit £-33.80
2022-01-03T21:18:32Z, 350.0000 ALGO. buy price £1.2050, sell price £1.3350, cost basis £421.75, sold for £467.25, profit £45.50
2022-01-03T21:18:47Z, 3.0000 COMP. buy price £144.3000, sell price £154.8000, cost basis £432.90, sold for £464.40, profit £31.50
2022-01-03T21:20:09Z, 200.0000 ENJ. buy price £2.3080, sell price £2.0350, cost basis £461.60, sold for £407.00, profit £-54.60
2022-01-03T21:20:46Z, 120.0000 EOS. buy price £2.5170, sell price £2.3370, cost basis £302.04, sold for £280.44, profit £-21.60
2022-02-06T08:56:03Z, 150.0000 CRV. buy price £2.1720, sell price £2.5690, cost basis £325.80, sold for £385.35, profit £59.55
2022-02-06T08:56:13Z, 400.0000 ENJ. buy price £1.1240, sell price £1.4710, cost basis £449.60, sold for £588.40, profit £138.80
2022-02-06T08:56:27Z, 40.0000 LINK. buy price £11.5700, sell price £13.1900, cost basis £462.80, sold for £527.60, profit £64.80
2022-02-17T14:53:36Z, 1200.0000 XRP. buy price £0.4484, sell price £0.5864, cost basis £538.08, sold for £703.68, profit £165.60
2022-02-17T14:53:44Z, 0.2500 ETH. buy price £1821.0000, sell price £2180.0000, cost basis £455.25, sold for £545.00, profit £89.75
2022-02-17T14:53:50Z, 0.0250 BTC. buy price £26430.0000, sell price £30810.0000, cost basis £660.75, sold for £770.25, profit £109.50
2022-02-17T14:57:23Z, 0.0010 BTC. buy price £26430.0000, sell price £30770.0000, cost basis £26.43, sold for £30.77, profit £4.34
2022-02-17T14:57:23Z, 0.0480 BTC. buy price £26430.0000, sell price £30760.0000, cost basis £1268.64, sold for £1476.48, profit £207.84
2022-02-17T14:57:28Z, 0.5000 ETH. buy price £1821.0000, sell price £2177.0000, cost basis £910.50, sold for £1088.50, profit £178.00
2022-03-31T16:34:45Z, 500.0000 MATIC. buy price £1.0760, sell price £1.2310, cost basis £538.00, sold for £615.50, profit £77.50
2022-03-31T16:34:56Z, 350.0000 CRV. buy price £1.5310, sell price £2.0060, cost basis £535.85, sold for £702.10, profit £166.25
2022-03-31T16:35:09Z, 0.5000 ETH. buy price £2004.0000, sell price £2485.0000, cost basis £1002.00, sold for £1242.50, profit £240.50
2022-03-31T16:35:21Z, 0.0350 BTC. buy price £30030.0000, sell price £34760.0000, cost basis £1051.05, sold for £1216.60, profit £165.55

Total profit: £1683.19

Download