Calculators
Crypto/stock cost basis (FIFO/LIFO/HIFO) API
Compute cost basis and realized gain for a disposal using FIFO, LIFO, or HIFO lot matching across your purchase lots, returning proceeds, matched-lot basis, realized gain, gain per unit, and the matched lots. Lot-accounting math LLMs get wrong. Answers 'FIFO cost basis for selling 15 of 20 coins','HIFO to minimize my gain','realized gain on this stock sale','LIFO vs FIFO basis'.
Price$0.01per request
MethodPOST
Route/v1/calc/tax-crypto-cost-basis
StatusLive
MIME typeapplication/json
Rate limit120/minute
CacheNo cache
taxcost-basisfifolifohifocryptocapital-gainscalc
API URL
Integration docshttps://x402.hexl.dev/v1/calc/tax-crypto-cost-basisExample request
{
"lots": [
{
"quantity": 10,
"price": 100
},
{
"quantity": 10,
"price": 200
}
],
"sellQuantity": 15,
"sellPrice": 250,
"method": "FIFO"
}Example response
{
"method": "FIFO",
"sellQuantity": 15,
"sellPrice": 250,
"proceeds": 3750,
"costBasis": 2000,
"realizedGain": 1750,
"gainPerUnit": 116.6667,
"isGain": true,
"lotsMatched": [
{
"quantity": 10,
"price": 100,
"cost": 1000
},
{
"quantity": 5,
"price": 200,
"cost": 1000
}
],
"note": "Estimate. Lot matching only; does not classify short/long-term (use tax-capital-gains) or apply wash-sale."
}Input schema
{
"type": "object",
"required": [
"lots",
"sellQuantity",
"sellPrice"
],
"properties": {
"lots": {
"type": "array",
"description": "Purchase lots",
"items": {
"type": "object",
"properties": {
"quantity": {
"type": "number"
},
"price": {
"type": "number"
},
"date": {
"type": "string"
}
}
},
"examples": [
[
{
"quantity": 10,
"price": 100
},
{
"quantity": 10,
"price": 200
}
]
]
},
"sellQuantity": {
"type": "number",
"examples": [
15
]
},
"sellPrice": {
"type": "number",
"examples": [
250
]
},
"method": {
"type": "string",
"enum": [
"FIFO",
"LIFO",
"HIFO"
],
"examples": [
"FIFO"
]
}
}
}Output schema
{
"type": "object",
"additionalProperties": true
}