API Endpoint
Average Cost Basis
Calculate weighted average cost basis when adding to a position.
Endpoint
Also supports GET with query parameters.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
existingShares | number | — | Existing shares owned |
existingAvgCost | number | — | Existing average cost per share ($) |
newShares | number | — | New shares purchased |
newPrice | number | — | New purchase price per share ($) |
Request Examples
POST (JSON body)
curl -X POST https://likeoptions.com/api/v1/calculate/avgcost \
-H "Content-Type: application/json" \
-d '{"existingShares": 100000, "existingAvgCost": 50000, "newShares": 6}'GET (query parameters)
curl "https://likeoptions.com/api/v1/calculate/avgcost?existingShares=100000&existingAvgCost=50000&newShares=6"Response
{
"kind": "avgcost",
"result": {
"primary": 1234.56,
"secondary": [
{ "label": "Example metric", "value": 100, "format": "money" },
{ "label": "Example percent", "value": 5.5, "format": "percent" }
]
}
}When to Use
- Calculate tax basis
- Track cost basis
- Plan averaging-down strategies
Error Handling
- 400 Bad Request — Invalid input parameters or missing required fields
- 404 Not Found — Unknown calculator kind
- 429 Too Many Requests — Rate limit exceeded (120 req/hour per IP)
- 413 Payload Too Large — Request body exceeds 16 KB
Related Endpoints
View request examples in JavaScript, Python, cURL, and more →
Stock positions, grants and margin
- Margin API endpointAPI
- Vesting API endpointAPI
- Stock grant vesting calculatorCalculator
- Cost basis calculatorCalculator
- Stock profit calculatorCalculator