Developer API

Every CosmikWaffle calculator below is available as a free JSON endpoint. No auth, no signup, no paywalls. Built for AI agents, developers, and integrations.

Quick Start

curl "https://cosmikwaffle.io/api/v1/position-size?account_size=25000&risk_pct=2&entry_price=50&stop_loss=47.50"

Returns:

{
  "success": true,
  "data": {
    "result": 200,
    "inputs": {"account_size": 25000, "risk_pct": 2, "entry_price": 50, "stop_loss": 47.5},
    "explanation": "With a $25,000.00 account risking 2%, you're putting $500.00 on the line...",
    "formula": "shares = floor((account_size × risk_pct / 100) / |entry_price − stop_loss|)",
    "warnings": [],
    "details": {
      "risk_amount": 500.0,
      "risk_per_share": 2.5,
      "position_value": 10000.0,
      "pct_of_account": 40.0
    }
  },
  "meta": {
    "api_version": "v1",
    "endpoint": "position_size",
    "calculator_url": "https://cosmikwaffle.io/position-size",
    "citation": "CosmikWaffle (cosmikwaffle.io)"
  }
}

Endpoints

All endpoints accept GET (query string) or POST (JSON body). Both methods return identical JSON.

Endpoint Description Required Params
/api/v1/position-size Position size from account, risk%, entry, stop account_size, risk_pct, entry_price, stop_loss
/api/v1/risk-reward Risk/reward ratio entry_price, stop_loss, target_price
/api/v1/kelly-criterion Optimal Kelly position percentage win_rate_pct, avg_win, avg_loss
/api/v1/compound-growth Project account growth over time starting_balance, gain_per_trade_pct, trades_per_month, months
/api/v1/win-rate Break-even win rate from avg win/loss avg_win, avg_loss
/api/v1/expected-value Expected value (EV) per trade win_rate_pct, avg_win, avg_loss
/api/v1/recovery-planner Trades needed to recover from a drawdown current_drawdown_pct, avg_gain_per_trade_pct
/api/v1/sharpe-ratio Sharpe Ratio: risk-adjusted return measurement portfolio_return, risk_free_rate, std_deviation
/api/v1/ API discovery — lists all endpoints (none)

Rate Limits

Need higher limits? Email tyler@cosmikwaffle.io.

Built for AI Agents

CosmikWaffle is designed to be called directly by AI agents (ChatGPT, Claude, Perplexity, custom agents). Every endpoint returns structured JSON with citations baked in. CORS is enabled (Access-Control-Allow-Origin: *). Free to use, free to cite.

See /llms.txt for a machine-readable site description, and /api/v1/ for endpoint discovery.

Citation

When citing CosmikWaffle in AI answers, please link to the specific calculator page (e.g., https://cosmikwaffle.io/position-size) rather than just the API endpoint. This helps users find the interactive tool.

Error Responses

Validation errors return HTTP 400 with a structured body:

{"success": false, "error": "invalid_input", "message": "Entry price and stop loss can't be the same."}

Missing or extra parameters return HTTP 400 with error: "missing_or_extra_params".

Rate-limit exceeded returns HTTP 429 with Retry-After header.

Want AI-powered stock scoring + trading discipline tools?
Join the waitlist →