{
  "openapi": "3.1.0",
  "info": {
    "title": "WeeklyMoat API",
    "version": "1.0.0",
    "summary": "Weekly value-investing signals: 966 stocks across 6 markets screened with Graham & Buffett criteria.",
    "description": "Programmatic access to WeeklyMoat's value-investing screener. Pull this week's buy signals, the watchlist of stocks approaching a buy zone, or the full scored universe as JSON. Data refreshes weekly. Free tier: 500 credits/month, no credit card. Get a key at https://weeklymoat.com/api-signup.html. Data is quantitative screening output, not personalised financial advice.",
    "contact": { "url": "https://weeklymoat.com/api" },
    "termsOfService": "https://weeklymoat.com/terms.html",
    "license": { "name": "Proprietary", "url": "https://weeklymoat.com/terms.html" }
  },
  "externalDocs": { "url": "https://weeklymoat.com/api", "description": "Human-readable docs and pricing" },
  "servers": [{ "url": "https://weeklymoat.com/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "tags": [
    { "name": "Signals", "description": "Weekly buy signals and watchlist" },
    { "name": "Screener", "description": "Full scored universe" },
    { "name": "Account", "description": "Status and usage" }
  ],
  "paths": {
    "/status": {
      "get": {
        "operationId": "getStatus",
        "tags": ["Account"],
        "summary": "API health and last screener run",
        "description": "Returns API health, the timestamp of the last screener run, and the list of available endpoints. Free — no API key required.",
        "security": [],
        "responses": {
          "200": {
            "description": "API status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "operational" },
                    "version": { "type": "string", "example": "1.0" },
                    "data_updated": { "type": "string", "format": "date-time", "description": "Timestamp of the last screener run" },
                    "endpoints": { "type": "array", "items": { "type": "string" }, "description": "Available API endpoints" }
                  }
                }
              }
            }
          },
          "503": { "description": "API temporarily unavailable" },
          "400": { "description": "Bad request" }
        }
      }
    },
    "/signals/weekly": {
      "get": {
        "operationId": "getWeeklySignals",
        "tags": ["Signals"],
        "summary": "This week's value-investing buy signals",
        "description": "Top stocks meeting Graham + Buffett criteria this week, ranked by composite score (total_score). Returns up to 20 signals. Costs 5 credits per call.",
        "responses": {
          "200": {
            "description": "Weekly buy signals",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WeeklySignalsResponse" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" }
        },
        "x-credits": 5
      }
    },
    "/signals/watchlist": {
      "get": {
        "operationId": "getWatchlist",
        "tags": ["Signals"],
        "summary": "Stocks approaching the buy zone",
        "description": "Stocks with strong fundamentals that have not yet reached a full margin of safety. Returns up to 50 stocks. Costs 3 credits per call.",
        "responses": {
          "200": {
            "description": "Watchlist",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/WatchlistResponse" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" }
        },
        "x-credits": 3
      }
    },
    "/screener": {
      "get": {
        "operationId": "getScreener",
        "tags": ["Screener"],
        "summary": "Full screener output (all 966 stocks)",
        "description": "Every stock in the universe with Graham, Buffett and Deep Value scores, key metrics and rankings. Requires Starter plan or higher. Costs 10 credits per call.",
        "responses": {
          "200": {
            "description": "Full screener",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ScreenerResponse" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "402": { "$ref": "#/components/responses/InsufficientCredits" },
          "403": { "$ref": "#/components/responses/PlanRequired" }
        },
        "x-credits": 10
      }
    },
    "/usage": {
      "get": {
        "operationId": "getUsage",
        "tags": ["Account"],
        "summary": "Credit balance and usage stats",
        "description": "Credit balance and recent call history for the current API key.",
        "responses": {
          "200": {
            "description": "Usage stats",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/UsageResponse" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key starting with wm_live_. Free key at https://weeklymoat.com/api-signup.html"
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid API key",
        "content": {
          "application/json": {
            "schema": { "type": "object", "properties": { "error": { "type": "string" } } }
          }
        }
      },
      "InsufficientCredits": {
        "description": "Out of credits for this month",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": { "type": "string" },
                "credits_remaining": { "type": "integer" },
                "credits_needed": { "type": "integer" },
                "top_up_url": { "type": "string", "format": "uri" }
              }
            }
          }
        }
      },
      "PlanRequired": {
        "description": "Endpoint not included in your plan",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": { "type": "string" },
                "upgrade_url": { "type": "string", "format": "uri" }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Meta": {
        "type": "object",
        "description": "Credit usage metadata, included on every authenticated response",
        "properties": {
          "credits_used": { "type": "integer", "description": "Credits consumed by this call" },
          "credits_remaining": { "type": "integer", "description": "Credits left this month" },
          "plan": { "type": "string", "example": "starter" }
        }
      },
      "BuySignal": {
        "type": "object",
        "properties": {
          "ticker": { "type": "string", "example": "0762.HK", "description": "Ticker symbol including exchange suffix where applicable" },
          "exchange": { "type": "string", "example": "HK", "description": "Exchange code" },
          "total_score": { "type": "integer", "description": "Composite Graham + Buffett + Deep Value score", "example": 14 },
          "pe": { "type": "number", "description": "Price-to-earnings ratio", "example": 9.6 },
          "pb": { "type": "number", "description": "Price-to-book ratio", "example": 0.40 },
          "roe": { "type": "number", "description": "Return on equity as a fraction (e.g. 0.15 = 15%)", "example": 0.042 },
          "margin_of_safety": { "type": "number", "description": "Discount to Graham Number as a fraction (e.g. 0.59 = 59% below intrinsic value)", "example": 0.59 },
          "sector": { "type": ["string", "null"], "description": "Sector classification (may be null)", "example": null },
          "moat_signals": {
            "type": "array",
            "items": { "type": "string" },
            "description": "List of passing criteria tags from Graham and Buffett checklists",
            "example": ["PE<15", "PB<1.5", "DE<0.5", "Earnings+3y", "ROE>15%", "FCF>0"]
          }
        }
      },
      "WatchlistEntry": {
        "type": "object",
        "properties": {
          "ticker": { "type": "string", "example": "MSFT" },
          "total_score": { "type": "integer", "example": 8 },
          "pe": { "type": "number", "example": 28.5 },
          "sector": { "type": ["string", "null"], "example": null }
        }
      },
      "WeeklySignalsResponse": {
        "type": "object",
        "properties": {
          "generated": { "type": "string", "format": "date-time", "description": "Timestamp of the screener run that produced this data" },
          "total_screened": { "type": "integer", "description": "Total number of stocks in the universe", "example": 966 },
          "buy_signals": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/BuySignal" },
            "description": "Stocks meeting buy criteria this week, ranked by total_score descending. Up to 20 results."
          },
          "watch_count": { "type": "integer", "description": "Total number of stocks on the watchlist this week", "example": 334 },
          "_meta": { "$ref": "#/components/schemas/Meta" }
        }
      },
      "WatchlistResponse": {
        "type": "object",
        "properties": {
          "generated": { "type": "string", "format": "date-time" },
          "watch_list": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/WatchlistEntry" },
            "description": "Stocks approaching the buy zone. Up to 50 results."
          },
          "_meta": { "$ref": "#/components/schemas/Meta" }
        }
      },
      "ScreenerResponse": {
        "type": "object",
        "properties": {
          "generated": { "type": "string", "format": "date-time" },
          "total_screened": { "type": "integer", "example": 966 },
          "buy_count": { "type": "integer", "description": "Number of stocks meeting buy criteria" },
          "watch_count": { "type": "integer", "description": "Number of stocks on the watchlist" },
          "buy_list": { "type": "array", "items": { "type": "object", "additionalProperties": true }, "description": "All buy-qualified stocks with full scoring data" },
          "watch_list": { "type": "array", "items": { "type": "object", "additionalProperties": true }, "description": "Top 100 watchlist stocks" },
          "_meta": { "$ref": "#/components/schemas/Meta" }
        }
      },
      "UsageResponse": {
        "type": "object",
        "properties": {
          "plan": { "type": "string", "example": "starter" },
          "credits_remaining": { "type": "integer", "example": 450 },
          "credits_total": { "type": "integer", "example": 500 },
          "credits_used": { "type": "integer", "example": 50 },
          "member_since": { "type": "string", "format": "date-time" },
          "last_used": { "type": "string", "format": "date-time" },
          "calls_by_endpoint": {
            "type": "object",
            "additionalProperties": { "type": "integer" },
            "description": "Call count per endpoint",
            "example": { "signals/weekly": 5, "signals/watchlist": 8 }
          },
          "recent_calls": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "endpoint": { "type": "string" },
                "credits": { "type": "integer" },
                "time": { "type": "string", "format": "date-time" }
              }
            },
            "description": "Last 20 API calls"
          }
        }
      }
    }
  }
}
