POST
/v1/mf/capital-gains- Authentication
- Bearer token
- Scope
mf:read
Before you integrate
- Transactions may be sent in any order; they are sorted by date before matching.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
transactions | array | Yes | Non-empty list of buys and sells of one scheme. |
transactions[].date | string | Yes | Transaction date as YYYY-MM-DD or a full ISO 8601 date-time. |
transactions[].type | string | Yes | buy or sell. |
transactions[].units | number | Yes | Units bought or sold; must be above 0. |
transactions[].price_minor | integer | Yes | NAV per unit in paise; 0 or more. |
ltcg_days | integer | No | Holding days after which a gain counts as long-term; above 0. Defaults to 365. |
fmv_31jan2018_minor | integer | No | Fair market value per unit on 31 January 2018 in paise, to apply grandfathering to older units. |
current_nav_minor | integer | No | Today's NAV per unit in paise, to include units still held in the XIRR. Needs valuation_date too. |
valuation_date | string | No | Date of current_nav_minor, as YYYY-MM-DD. |
Sample code
Set your key in the GRAPPI_API_KEY environment variable. Sample values are placeholders.
curl -sS -X POST 'https://grappi.ai/v1/mf/capital-gains' \
-H "Authorization: Bearer $GRAPPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"transactions": [
{
"date": "2022-01-01",
"type": "buy",
"units": 100,
"price_minor": 10000
},
{
"date": "2024-01-01",
"type": "sell",
"units": 100,
"price_minor": 15000
}
]
}'Sample response
{
"request_id": "req_01HZY3K8M2",
"result": {
"realized": [
{
"buy_date": "2022-01-01",
"sell_date": "2024-01-01",
"units": 100,
"term": "LTCG",
"proceeds_minor": 1500000,
"cost_minor": 1000000,
"gain_minor": 500000
}
],
"total_stcg_minor": 0,
"total_ltcg_minor": 500000,
"total_gain_minor": 500000,
"xirr": 0.224745,
"warnings": []
}
}Response fields
| Field | Type | Description |
|---|---|---|
realized | array | Each sale matched to the units it sold, first in first out. |
realized[].buy_date | string | Date those units were bought. |
realized[].sell_date | string | Date they were sold. |
realized[].units | number | Units matched. |
realized[].term | string | STCG or LTCG. |
realized[].proceeds_minor | integer | Sale value in paise. |
realized[].cost_minor | integer | Cost in paise, after grandfathering where it applies. |
realized[].gain_minor | integer | Proceeds minus cost, in paise. |
total_stcg_minor | integer | Total short-term gain in paise. |
total_ltcg_minor | integer | Total long-term gain in paise. |
total_gain_minor | integer | Total gain in paise. |
xirr | number | Annualised return as a fraction (0.18 means 18%); null when it cannot be worked out. |
warnings | array | Plain-text issues, for example a sale of more units than were bought. |
Errors
Every failure has the same shape. A call that fails on our side or at the data source is refunded to your wallet; a "no record found" answer is charged. See the error reference.