Crypto trading bot taxes in Spain: a guide for residents
A bot can make hundreds of trades a year, and every sale or crypto-to-crypto swap has tax consequences. This guide summarises how they are taxed under Spanish personal income tax (IRPF) for Spanish tax residents. It isn’t tax advice: if your situation is complex, talk to an adviser.
Last updated: 11/06/2026 · 8 min readThe key idea: every sale or swap counts
For the Spanish tax agency, when your bot sells a crypto-asset for euros or swaps it for another one (BTC for ETH, or for a stablecoin), you make a capital gain or loss (ganancia o pérdida patrimonial). You don’t need to cash out to euros: Spain’s Directorate General for Taxes treats crypto-to-crypto swaps as taxable exchanges (binding ruling V0999-18).
Buying with euros is not taxable on its own: it sets the acquisition cost you’ll use when you sell.
Trades in a practice (paper trading) account or in a backtest are simulated and have no tax consequences at all.
How the gain or loss is calculated
Gain or loss = disposal value − acquisition value. Buying fees are added to the acquisition value and selling fees are deducted from the disposal value.
If you bought the same crypto-asset several times at different prices, the FIFO method applies (“first in, first out”): when you sell, you are deemed to sell the oldest units first. It’s the rule the Spanish income tax law sets for identical assets (article 37.2), and the tax agency applies it to crypto-assets.
Example: you buy 0.1 BTC at €50,000 and later 0.1 BTC at €60,000. Your bot sells 0.1 BTC at €65,000. Under FIFO you sell the first lot: a gain of (65,000 − 50,000) × 0.1 = €1,500, minus fees.
With a bot that trades daily, that means tracking every lot. A spreadsheet can do it, but it’s very error-prone.
How much you pay: savings income rates
Crypto capital gains go into the savings tax base (base imponible del ahorro), with this scale (state and regional rates combined, common territory):
| Savings base | Rate |
|---|---|
| Up to €6,000 | 19% |
| €6,000 to €50,000 | 21% |
| €50,000 to €200,000 | 23% |
| €200,000 to €300,000 | 27% |
| Over €300,000 | 30% |
The top band rose from 28% to 30% from 2025 (Ley 7/2024). The Basque Country and Navarre have their own rules.
What happens with losses
Losses aren’t wasted: a net capital loss in the savings base is first offset against gains from the same year and, if anything is left, against net income from movable capital (interest, dividends) up to 25% of it. Whatever remains can be carried forward for the next four years (article 49 of the income tax law).
That’s why you should record your bot’s losing trades too, not just the winners.
Modelo 721: crypto held abroad
If on 31 December you hold crypto-assets in custody with foreign platforms worth more than €50,000 in total, you must file Modelo 721, an information return (no tax is paid with it), between 1 January and 31 March of the following year. You only need to file again if the balance rises by more than €20,000 compared with your last return, or if you stop holding the assets (Orden HFP/886/2023).
Self-custodied crypto (your own wallet) is not reported on Modelo 721, although its gains are still taxed under IRPF when you sell or swap.
How to stay organised if you use bots
- Download your trade history from each exchange (usually as CSV) at least once a year.
- Bring it together in one place and apply FIFO per crypto-asset, including crypto-to-crypto swaps and fees.
- Check your 31 December balance on foreign platforms to see whether Modelo 721 applies.
- Keep the records: the tax agency can ask for them for four years.
Bot Shaper includes a Taxes module that does this calculation with FIFO on your real trades (the ones you import from your exchanges) and prepares the summary for your tax return and Modelo 721. Practice account trades never count.
FAQ
Do I have to declare my trading bot’s trades in Spain?
Yes, if you are a Spanish tax resident. Each sale or crypto-to-crypto swap creates a capital gain or loss that goes on your IRPF return for that year, even if you never moved the money to your bank.
Is swapping BTC for USDT taxable in Spain?
Yes. Spain’s Directorate General for Taxes treats swaps between crypto-assets, stablecoins included, as exchanges that create a capital gain or loss.
Which method is used to calculate gains: FIFO or average cost?
FIFO. When you sell, you are deemed to sell the units you bought first, under the identical-assets rule of the Spanish income tax law.
Are demo account trades taxable?
No. Simulated trades, in a practice account or a backtest, have no tax consequences because nothing is actually sold.
Sources
Templates to start with
Keep reading
- How to build a trading bot without codingA step-by-step guide to building a trading bot with no code: turn your strategy into rules, backtest it and run it on paper before you risk real money.
- How to backtest a trading strategy without fooling yourselfWhat backtesting is, how to test a trading strategy on historical data and the mistakes that inflate results: overfitting, look-ahead bias, fees and slippage.