{
  "openapi": "3.1.0",
  "info": {
    "title": "Blockchain Compound Analytics JSON API",
    "version": "1.0.0",
    "description": "Free deterministic, non-predictive portfolio and exit-plan math. API v1 contract. Request values are transmitted to Cloudflare when using this API, unlike the browser-local website calculator."
  },
  "servers": [
    {
      "url": "https://blockchaincompound.com"
    }
  ],
  "paths": {
    "/api/v1/portfolio/analyze": {
      "post": {
        "summary": "Analyze manual portfolio exposure and hypothetical shock",
        "operationId": "analyzePortfolioV1",
        "description": "Manual-input scenario math only. No live market data, recommendation, persistence or trading.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AnalyzeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic result with apiVersion v1 and original modelVersion 1.0.0",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "apiVersion",
                    "data"
                  ],
                  "properties": {
                    "apiVersion": {
                      "const": "v1"
                    },
                    "data": {
                      "type": "object",
                      "description": "Canonical engine output, documented in docs/API-V1.md"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Malformed or unreadable JSON"
          },
          "405": {
            "description": "Method not allowed"
          },
          "413": {
            "description": "Request exceeds 16 KiB"
          },
          "415": {
            "description": "Unsupported media type"
          },
          "422": {
            "description": "Invalid inputs or out-of-range calculations"
          },
          "500": {
            "description": "Unexpected server failure"
          }
        }
      }
    },
    "/api/v1/portfolio/exit-plan": {
      "post": {
        "summary": "Calculate sequential hypothetical portfolio sales",
        "operationId": "calculateExitPlanV1",
        "description": "Manual-input scenario math only. No live market data, recommendation, persistence or trading.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExitRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic result with apiVersion v1 and original modelVersion 1.0.0",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "apiVersion",
                    "data"
                  ],
                  "properties": {
                    "apiVersion": {
                      "const": "v1"
                    },
                    "data": {
                      "type": "object",
                      "description": "Canonical engine output, documented in docs/API-V1.md"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Malformed or unreadable JSON"
          },
          "405": {
            "description": "Method not allowed"
          },
          "413": {
            "description": "Request exceeds 16 KiB"
          },
          "415": {
            "description": "Unsupported media type"
          },
          "422": {
            "description": "Invalid inputs or out-of-range calculations"
          },
          "500": {
            "description": "Unexpected server failure"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Asset": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "symbol",
          "quantity",
          "costPerUnit",
          "price"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9_-]{1,40}$",
            "description": "Unique user-assigned portfolio ID"
          },
          "symbol": {
            "type": "string",
            "pattern": "^[a-zA-Z0-9 ._-]{1,24}$",
            "description": "Manually entered label, not verified against a market catalog"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1000000000000
          },
          "costPerUnit": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000000,
            "description": "Average USD acquisition cost per unit"
          },
          "price": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000000,
            "description": "Manually supplied USD reference price"
          },
          "shockPct": {
            "type": [
              "number",
              "null"
            ],
            "minimum": -100,
            "maximum": 300,
            "description": "Optional asset-specific percentage change"
          }
        }
      },
      "Sale": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "assetId",
          "quantity",
          "targetPrice"
        ],
        "properties": {
          "assetId": {
            "type": "string",
            "description": "ID of existing asset"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0,
            "maximum": 1000000000000
          },
          "targetPrice": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000000
          },
          "fee": {
            "type": "number",
            "minimum": 0,
            "maximum": 1000000000000,
            "default": 0
          }
        }
      },
      "AnalyzeRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "assets"
        ],
        "properties": {
          "assets": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/Asset"
            }
          },
          "marketChangePct": {
            "type": "number",
            "minimum": -100,
            "maximum": 300,
            "default": -40
          }
        }
      },
      "ExitRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "assets"
        ],
        "properties": {
          "assets": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/Asset"
            }
          },
          "sales": {
            "type": "array",
            "minItems": 0,
            "maxItems": 60,
            "items": {
              "$ref": "#/components/schemas/Sale"
            },
            "default": []
          }
        }
      }
    }
  }
}
