> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sequency.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert Scenario Policy

> Set one template's action policy (§9.1).

``gate_min_n`` cannot be set below §10's display floor: below it the stats
endpoint returns NO estimate at all, so a lower gate would be a gate on a
statistic that structurally does not exist. Migration 194 carries the same CHECK
— this is the friendly 422, not the safety net.



## OpenAPI

````yaml /api/openapi.json put /api/graph/v1/pattern-events/scenario-policies
openapi: 3.1.0
info:
  title: Sequency Graph API
  description: >

    # Sequency Graph-Native Trading API


    Graph-native API for trading intelligence, built on FalkorDB.


    ## Features


    - **Screener**: Filter stocks using graph-native queries with relationship
    expansion

    - **Stock Detail**: Complete stock context with all relationships

    - **Confluence Scoring**: Setup quality assessment with weighted components

    - **Strategy Matching**: Find matching options strategies via graph
    traversal

    - **Market Context**: Current market-wide context for trading decisions


    ## Data Sources


    All data is sourced from the FalkorDB knowledge graph, populated by:

    - Pattern detector (Go) - Technical indicators, patterns

    - Graph sync service - Levels, volume profiles, news, day classification
  version: 1.0.0
servers: []
security: []
paths:
  /api/graph/v1/pattern-events/scenario-policies:
    put:
      tags:
        - pattern-events
      summary: Upsert Scenario Policy
      description: >-
        Set one template's action policy (§9.1).


        ``gate_min_n`` cannot be set below §10's display floor: below it the
        stats

        endpoint returns NO estimate at all, so a lower gate would be a gate on
        a

        statistic that structurally does not exist. Migration 194 carries the
        same CHECK

        — this is the friendly 422, not the safety net.
      operationId: upsert_scenario_policy_api_graph_v1_pattern_events_scenario_policies_put
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScenarioPolicyUpdate'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                additionalProperties: true
                type: object
                title: >-
                  Response Upsert Scenario Policy Api Graph V1 Pattern Events
                  Scenario Policies Put
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    ScenarioPolicyUpdate:
      properties:
        template_id:
          type: string
          title: Template Id
        symbol_scope:
          type: string
          title: Symbol Scope
          default: '*'
        action:
          type: string
          title: Action
          default: log
        gate_min_n:
          type: integer
          title: Gate Min N
          default: 30
        gate_expectancy_floor_r:
          type: number
          minimum: 0
          title: Gate Expectancy Floor R
          default: 0
        gate_recency_days:
          type: integer
          maximum: 1825
          minimum: 1
          title: Gate Recency Days
          default: 120
      type: object
      required:
        - template_id
      title: ScenarioPolicyUpdate
      description: >-
        One row of the §9.1 action ladder.


        ``enabled_by`` is deliberately NOT a field: escalation must be
        attributable to

        the authenticated operator, and a client-supplied name would let it be
        forged.

        The handler stamps it from ``request.state.user``, and migration 194's
        CHECK

        constraint refuses an ``auto_arm`` row without it — belt and braces,
        because the

        database must hold the line for a psql session too.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````