TradingCalc Primitive API
The primitive API from TradingCalc — 2 operation(s) for primitive.
The primitive API from TradingCalc — 2 operation(s) for primitive.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/tradingcalc-io:tradingcalc-io-primitive-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
openapi: 3.2.0
info:
title: TradingCalc tools Primitive API
description: 'Every TradingCalc tool as a plain HTTP endpoint: POST the arguments as JSON, get the result as JSON. These are the same tools, with the same input schemas, quota and signed results, as the MCP server at https://tradingcalc.io/api/mcp. The same input always returns the same number, and every formula is published at https://docs.tradingcalc.io. Inputs are never stored.'
version: 1.0.0
servers:
- url: https://tradingcalc.io
security:
- {}
- bearerAuth: []
tags:
- name: primitive
paths:
/api/v1/tools/primitive.average_entry:
post:
operationId: primitive_average_entry
summary: Average Entry Price
description: 'Calculate the weighted average entry price from multiple buy/sell fills (DCA): the bare number only, no breakeven or per-fill breakdown. Edge cases: symbol non-empty; at least one fill, each price and quantity above zero (size is accepted as quantity); leverage above zero is optional. The average is weighted by quantity. Not covered: fees, sells or partial closes (give only the fills still open), and funding. Use when user asks only "what''s my average entry?" and wants just that figure. Each fill is { price, quantity } here (workflow.run_dca_entry calls the same field size). For breakeven and a per-level summary too, use workflow.run_dca_entry instead. Returns: averagePrice, totalSize, totalCost.'
tags:
- primitive
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
symbol:
type: string
description: Trading pair symbol, e.g. BTCUSDT
exchangeCode:
type: string
description: Exchange identifier (optional)
input:
type: object
description: 'Object with a "fills" array, e.g. { "fills": [{ "price": 60000, "quantity": 0.5 }, { "price": 58000, "quantity": 1 }] }'
properties:
fills:
type: array
description: Buy/sell fills to average, each with a price and a quantity (at least 1)
items:
type: object
properties:
price:
type: number
description: Fill price
quantity:
type: number
description: Fill quantity, required unless "size" is given (the same field)
size:
type: number
description: Same field as quantity
required:
- price
minItems: 1
required:
- fills
contractType:
type: string
enum:
- linear
- inverse
description: linear = USDT-margined, average is the arithmetic mean (default). inverse = coin-margined, average is the harmonic mean (fill quantity is USD notional).
required:
- symbol
- input
example:
symbol: BTCUSDT
input:
fills:
- price: 60000
quantity: 0.5
- price: 58000
quantity: 1
contractType: linear
responses:
'200':
description: 'The tool result as JSON. The X-TradingCalc-Signature, X-TradingCalc-Kid and X-TradingCalc-Signed-At headers sign the exact bytes of this body (verification steps: tool system.pubkey, or GET /api/mcp/pubkey). The object carries _method.release, the server release that produced it.'
content:
application/json:
schema:
type: object
additionalProperties: true
'400':
description: The body is not valid JSON.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'404':
description: Unknown tool name.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'413':
description: The body is too large.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'422':
description: 'Invalid arguments: the message names the fields.'
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'429':
description: Daily quota or per-minute cap exceeded; Retry-After says how many seconds until the quota or the minute resets.
headers:
Retry-After:
description: Seconds to wait before retrying.
schema:
type: integer
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'500':
description: Internal error; retry later.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'502':
description: 'The tool could not finish: usually a live data source it needs failed, otherwise an internal error. Retry later.'
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
/api/v1/tools/primitive.hedge_ratio:
post:
operationId: primitive_hedge_ratio
summary: Hedge Ratio
description: 'Calculate the short perpetual futures position size needed to hedge a spot holding. Default USDT-linear: sizes and costs in USD. With contractType "inverse" (coin-margined, needs entryPrice) the short is the same USD contracts and margin and funding come back in the base coin. Edge cases: spotSize above zero (USD value); hedgeRatio 0 to 200 percent (default 100); leverage 1 or more (default 1); fundingRatePct in percent per interval (0.01 is 0.01%, default 0.01); intervalHours 0.25 to 24 (default 8); an inverse contract needs entryPrice. Not covered: basis risk between spot and the perp, rebalancing as prices move, margin calls, and a funding rate that changes. Use when user asks "how much should I short to hedge my BTC?" or "what margin do I need for a 100% hedge?". Returns: perpNotional, requiredMargin, dailyFundingCost, annualFundingCost, hedgeCoverage, contractType and costUnit ("USD", or "base_coin" for inverse: read it before showing margin or funding as dollars). Inverse converts at the one entryPrice you give, so the coin figures assume the price stays there.'
tags:
- primitive
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
spotSize:
type: number
description: Spot position value in USDT
hedgeRatio:
type: number
description: Percentage of spot to hedge, e.g. 100 for full hedge, 50 for half. Default 100.
leverage:
type: number
description: Leverage on the perp short. Default 1.
fundingRatePct:
type: number
description: 'Current funding rate per funding interval in PERCENT: 0.01 means 0.01%, so a quoted 0.0125% is 0.0125 (per 8h unless intervalHours says otherwise). Used for cost estimate.'
intervalHours:
type: number
minimum: 0.25
maximum: 24
description: Hours between funding payments, the period fundingRatePct covers. Default 8 (3 payments a day); 1 on Hyperliquid, dYdX, Kraken and Backpack (per-hour rates); 4 or 2 on some symbols of Binance, Bybit, OKX, Gate, KuCoin, MEXC, Aster and Phemex.
contractType:
type: string
enum:
- linear
- inverse
description: 'linear = USDT-margined (default). inverse = coin-margined: spotSize stays the USD value of the holding, requiredMargin and the funding costs are returned in the base coin.'
entryPrice:
type: number
description: Coin price in USD. Required for contractType inverse (converts the USD margin and funding to coin); ignored for linear.
required:
- spotSize
example:
spotSize: 1
hedgeRatio: 100
leverage: 3
fundingRatePct: 0.01
intervalHours: 8
entryPrice: 60000
contractType: linear
responses:
'200':
description: 'The tool result as JSON. The X-TradingCalc-Signature, X-TradingCalc-Kid and X-TradingCalc-Signed-At headers sign the exact bytes of this body (verification steps: tool system.pubkey, or GET /api/mcp/pubkey). The object carries _method.release, the server release that produced it.'
content:
application/json:
schema:
type: object
additionalProperties: true
'400':
description: The body is not valid JSON.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'404':
description: Unknown tool name.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'413':
description: The body is too large.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'422':
description: 'Invalid arguments: the message names the fields.'
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'429':
description: Daily quota or per-minute cap exceeded; Retry-After says how many seconds until the quota or the minute resets.
headers:
Retry-After:
description: Seconds to wait before retrying.
schema:
type: integer
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'500':
description: Internal error; retry later.
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
'502':
description: 'The tool could not finish: usually a live data source it needs failed, otherwise an internal error. Retry later.'
content:
application/json:
schema:
type: object
properties:
error:
type: object
properties:
code:
type: integer
message:
type: string
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: Optional API key. Anonymous callers get a smaller daily quota; the quota is shared with /api/mcp.