{
  "openapi": "3.1.0",
  "info": {
    "title": "Taiwan Market Signal API",
    "version": "0.1.0",
    "description": "Source-linked Taiwan listed-company facts from official TWSE OpenAPI feeds. Source: Taiwan Stock Exchange / FSC Securities and Futures Bureau; released under Taiwan Open Government Data License 1.0.",
    "license": {
      "name": "Taiwan Open Government Data License 1.0",
      "url": "https://data.gov.tw/license"
    }
  },
  "servers": [
    {
      "url": "https://taiwan-market-signal.bytoken2023.workers.dev"
    }
  ],
  "paths": {
    "/v1/companies": {
      "get": {
        "operationId": "searchTaiwanCompanies",
        "summary": "Search Taiwan listed companies by code, Chinese name, or industry",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            },
            "example": "台積"
          }
        ],
        "responses": {
          "200": {
            "description": "Matching companies"
          },
          "400": {
            "description": "Missing query"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/company/{code}/latest-signal": {
      "get": {
        "operationId": "getTaiwanCompanyLatestSignal",
        "summary": "Get latest official market and revenue facts for a Taiwan company",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4,6}$"
            },
            "example": "2330"
          }
        ],
        "responses": {
          "200": {
            "description": "Latest company signal"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/company/{code}/history": {
      "get": {
        "operationId": "getTaiwanCompanySignalHistory",
        "summary": "Get stored daily snapshots for a Taiwan company",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4,6}$"
            },
            "example": "2330"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 30
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Stored company snapshots"
          },
          "503": {
            "description": "History storage unavailable"
          }
        }
      }
    },
    "/v1/x402/company/{code}/latest-signal": {
      "get": {
        "operationId": "buyLatestSignal",
        "summary": "Buy the latest official company signal",
        "price": "$0.02",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4,6}$"
            }
          }
        ],
        "x-payment-protocol": "x402",
        "x-price-usdc": "$0.02",
        "responses": {
          "200": {
            "description": "Paid product response"
          },
          "402": {
            "description": "x402 payment required"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/x402/company/{code}/company-brief": {
      "get": {
        "operationId": "buyCompanyBrief",
        "summary": "Buy a compact official-data company brief",
        "price": "$0.05",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4,6}$"
            }
          }
        ],
        "x-payment-protocol": "x402",
        "x-price-usdc": "$0.05",
        "responses": {
          "200": {
            "description": "Paid product response"
          },
          "402": {
            "description": "x402 payment required"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/x402/compare-companies": {
      "get": {
        "operationId": "buyCompanyComparison",
        "summary": "Buy a side-by-side comparison of two companies",
        "price": "$0.08",
        "parameters": [
          {
            "name": "codes",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "2330,2317"
          }
        ],
        "x-payment-protocol": "x402",
        "x-price-usdc": "$0.08",
        "responses": {
          "200": {
            "description": "Paid product response"
          },
          "402": {
            "description": "x402 payment required"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/x402/market/anomalies": {
      "get": {
        "operationId": "buyMarketAnomalies",
        "summary": "Buy a ranked Taiwan market anomaly scan",
        "price": "$0.10",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          }
        ],
        "x-payment-protocol": "x402",
        "x-price-usdc": "$0.10",
        "responses": {
          "200": {
            "description": "Paid product response"
          },
          "402": {
            "description": "x402 payment required"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    },
    "/v1/x402/company/{code}/supply-chain-impact": {
      "get": {
        "operationId": "buySupplyChainImpact",
        "summary": "Buy an industry-peer supply-chain impact proxy",
        "price": "$0.15",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{4,6}$"
            }
          }
        ],
        "x-payment-protocol": "x402",
        "x-price-usdc": "$0.15",
        "responses": {
          "200": {
            "description": "Paid product response"
          },
          "402": {
            "description": "x402 payment required"
          },
          "404": {
            "description": "Company not found"
          },
          "502": {
            "description": "Official upstream source unavailable"
          }
        }
      }
    }
  }
}