{
  "openapi": "3.1.0",
  "info": {
    "title": "Simple Trading Journal API",
    "version": "1.0.0",
    "description": "Read-only access to one trading journal: statistics, trades, the cost of self-tagged mistakes and discipline habits. Notes, photos and custom tags are never returned."
  },
  "servers": [{ "url": "https://www.simpletradejournal.io/api/v1" }],
  "security": [{ "apiKey": [] }],
  "components": {
    "securitySchemes": {
      "apiKey": { "type": "http", "scheme": "bearer", "description": "An AI key created in the app under \"AI connection\" (starts with stj_)." }
    },
    "parameters": {
      "from": { "name": "from", "in": "query", "required": false, "schema": { "type": "string", "format": "date" }, "description": "Only trades on or after this date (YYYY-MM-DD)." },
      "to": { "name": "to", "in": "query", "required": false, "schema": { "type": "string", "format": "date" }, "description": "Only trades on or before this date (YYYY-MM-DD)." }
    }
  },
  "paths": {
    "/stats": {
      "get": {
        "operationId": "getStats",
        "summary": "Performance statistics: win rate, net P&L, profit factor, R multiples, drawdown, breakdown by symbol and setup.",
        "parameters": [{ "$ref": "#/components/parameters/from" }, { "$ref": "#/components/parameters/to" }],
        "responses": { "200": { "description": "Statistics for the journal." } }
      }
    },
    "/trades": {
      "get": {
        "operationId": "listTrades",
        "summary": "Recent trades, newest first (at most 50 per call).",
        "parameters": [
          { "$ref": "#/components/parameters/from" },
          { "$ref": "#/components/parameters/to" },
          { "name": "symbol", "in": "query", "required": false, "schema": { "type": "string" }, "description": "Only this symbol, e.g. EURUSD." },
          { "name": "limit", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 20 } },
          { "name": "offset", "in": "query", "required": false, "schema": { "type": "integer", "minimum": 0, "default": 0 } }
        ],
        "responses": { "200": { "description": "A page of trades." } }
      }
    },
    "/mistakes": {
      "get": {
        "operationId": "getMistakeCosts",
        "summary": "What each self-tagged mistake (moved stop, entry without a plan, ...) has cost in total.",
        "parameters": [{ "$ref": "#/components/parameters/from" }, { "$ref": "#/components/parameters/to" }],
        "responses": { "200": { "description": "Mistake tags with trade count and net P&L." } }
      }
    },
    "/discipline": {
      "get": {
        "operationId": "getDiscipline",
        "summary": "Automatically detected habits (revenge trading, risk creep, overtrading, off-hours) and what they cost.",
        "parameters": [{ "$ref": "#/components/parameters/from" }, { "$ref": "#/components/parameters/to" }],
        "responses": { "200": { "description": "Flagged habits and clean-vs-flagged P&L." } }
      }
    }
  }
}
