{
  "openapi": "3.0.3",
  "info": {
    "title": "Stocks to Buy Now Research Institutional Signals API",
    "version": "1.3.0",
    "description": "Paid REST event feed. Filter connected categories independently or together. See README.md for cursor recovery and category field semantics."
  },
  "servers": [
    {
      "url": "https://us-central1-stocker-fcda2.cloudfunctions.net/institutionalSignalsApi"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Category": {
        "type": "object",
        "required": [
          "id",
          "group",
          "label",
          "status",
          "description"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "group": {
            "type": "string",
            "enum": [
              "primary",
              "supporting"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "enabled",
              "pending"
            ]
          }
        }
      },
      "Signal": {
        "type": "object",
        "required": [
          "id",
          "asset_class",
          "symbols"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "category": {
            "type": "string",
            "description": "Legacy stock events may omit this; default stock_research."
          },
          "group": {
            "type": "string"
          },
          "asset_class": {
            "type": "string",
            "enum": [
              "equity",
              "options"
            ]
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "research": {
            "type": "string",
            "nullable": true
          },
          "company_name": {
            "type": "string",
            "nullable": true
          },
          "direction": {
            "type": "string",
            "nullable": true
          },
          "published_at": {
            "type": "string",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "nullable": true
          },
          "review_at": {
            "type": "string",
            "nullable": true
          },
          "model_version": {
            "type": "string",
            "nullable": true
          },
          "premium_status": {
            "type": "string",
            "nullable": true
          },
          "reference_price": {
            "type": "number",
            "nullable": true
          },
          "target_price": {
            "type": "number",
            "nullable": true
          },
          "risk_rating": {
            "type": "number",
            "nullable": true
          },
          "estimated_eps_surprise_pct": {
            "type": "number",
            "nullable": true
          },
          "option_legs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "symbol": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "call",
                    "put"
                  ]
                },
                "strike": {
                  "type": "number",
                  "nullable": true
                },
                "premium": {
                  "type": "number",
                  "nullable": true
                },
                "expiry": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          },
          "calendar_event": {
            "type": "object",
            "nullable": true
          },
          "contract": {
            "type": "object",
            "description": "Unusual-volume call contract fields; see category guide."
          },
          "disclosures": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "partial": {
            "type": "boolean"
          }
        }
      },
      "Event": {
        "type": "object",
        "required": [
          "schema_version",
          "id",
          "cursor",
          "type",
          "signal"
        ],
        "properties": {
          "schema_version": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "cursor": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "signal.created",
              "signal.updated",
              "signal.removed"
            ]
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "captured_at": {
            "type": "string",
            "format": "date-time"
          },
          "categories": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "symbols": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "signal": {
            "$ref": "#/components/schemas/Signal"
          }
        }
      },
      "EventPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor",
          "has_more"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            }
          },
          "next_cursor": {
            "type": "string",
            "description": "Last scanned event, even if no matches were returned."
          },
          "has_more": {
            "type": "boolean",
            "description": "Continue immediately when true, including on empty filtered pages."
          }
        }
      }
    }
  },
  "paths": {
    "/v1/events": {
      "get": {
        "summary": "Read published signal events in capture order",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$"
            },
            "description": "Last processed cursor for this exact filter selection. Omit to start/replay available subscription history. Keep separate cursors for separate selections."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          },
          {
            "name": "categories",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated connected category IDs from /v1/catalog (OR). Omit for all. Pending/unknown IDs return 400."
          },
          {
            "name": "symbols",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated ticker symbols (OR), case-insensitive, up to 25. ANDed with category/group filters."
          },
          {
            "name": "group",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "primary",
                "supporting"
              ]
            },
            "description": "Research group, not a separate billing tier."
          }
        ],
        "responses": {
          "200": {
            "description": "Event page: data array, next_cursor string, has_more boolean",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventPage"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cursor/limit/filter or category not connected."
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "Paid subscription required"
          },
          "429": {
            "description": "Rate limited; respect Retry-After"
          },
          "503": {
            "description": "Temporarily unavailable"
          }
        }
      }
    },
    "/v1/catalog": {
      "get": {
        "summary": "List research categories and connection status (paid key required)",
        "responses": {
          "200": {
            "description": "Category catalog",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "categories": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Category"
                      }
                    },
                    "delivery": {
                      "type": "string",
                      "enum": [
                        "rest_polling"
                      ]
                    },
                    "poll_interval_seconds": {
                      "type": "integer"
                    },
                    "max_page_size": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "Paid subscription required"
          },
          "429": {
            "description": "Rate limited; respect Retry-After"
          },
          "503": {
            "description": "Temporarily unavailable"
          }
        }
      }
    },
    "/v1/signals": {
      "get": {
        "summary": "List latest verified signals with optional literal text search",
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]+$"
            },
            "description": "Current-list cursor, separate from event cursors. Omit to refresh the list within subscription history."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 100
            }
          },
          {
            "name": "categories",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated connected category IDs from /v1/catalog (OR). Omit for all. Pending/unknown IDs return 400."
          },
          {
            "name": "symbols",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated ticker symbols (OR), case-insensitive, up to 25. ANDed with category/group filters."
          },
          {
            "name": "group",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "primary",
                "supporting"
              ]
            },
            "description": "Research group, not a separate billing tier."
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            },
            "description": "Case-insensitive literal substring of title, research text or symbols."
          }
        ],
        "responses": {
          "200": {
            "description": "Current signal page. Empty pages may still have more records.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "next_cursor",
                    "has_more"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "next_cursor": {
                      "type": "string"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid cursor/limit/filter or category not connected."
          },
          "401": {
            "description": "Invalid or revoked API key"
          },
          "403": {
            "description": "Paid subscription required"
          },
          "429": {
            "description": "Rate limited; respect Retry-After"
          },
          "503": {
            "description": "Temporarily unavailable"
          }
        },
        "description": "Requires current-signal writer deployment. No historical backfill. Current-state pagination is not a stable snapshot; deduplicate signal IDs and track removals through /v1/events."
      }
    },
    "/v1/calendar": {
      "get": {
        "summary": "Read the saved app market calendar",
        "description": "Paid access required. Saved schedule, not a live feed. Returns coverage and checked dates. No cursor.",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "indices",
                "macro",
                "fed",
                "filings",
                "trading"
              ]
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Calendar: schema_version, basis, checked, coverage, categories, data"
          },
          "400": {
            "description": "Invalid filter"
          },
          "401": {
            "description": "Invalid API key"
          },
          "403": {
            "description": "Active paid subscription required"
          },
          "429": {
            "description": "Rate limited"
          },
          "503": {
            "description": "Service unavailable"
          }
        }
      }
    }
  }
}
