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

# Post Backtest

> Submit a backtest job.

Two modes:
  * **Async** (default, `wait_for_result=false`): returns HTTP 202 +
    `job_id` immediately. Client polls `GET /v1/backtest/{job_id}`.
    Best for UI and long jobs; survives client disconnects.
  * **Sync-style** (`wait_for_result=true`): the API holds the
    connection while a worker processes the job, then returns HTTP
    200 with the completed result inline. Matches the curl-friendly
    pattern PolyBackTest data customers expect. Caps at 30 s of
    wait; longer than that and you get a 504 + the job_id so you
    can keep polling.

Tier gates (rate limit already checked in `authed_key`):
  * `market_limit` cap from the tier prevents Free users from
    queueing a 500-market scan.
  * Per-key concurrent in-flight cap (`tier.concurrent_backtests`):
    users can't flood the queue with their own work and starve
    others.



## OpenAPI

````yaml post /v1/backtest
openapi: 3.1.0
info:
  title: PolyQuantLab API
  version: 0.1.0
  description: >-
    Sub-second Polymarket orderbook data, walk-the-book backtests, paper
    trading, and the live arb audit. Same endpoints the PolyQuantLab dashboard
    uses internally — Bearer-token auth, JSON-over-HTTPS, predictable
    pagination.
  contact:
    email: contact@polyquantlab.com
    url: https://polyquantlab.com/contact
  license:
    name: Proprietary
servers:
  - url: https://api.polyquantlab.com
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /v1/backtest:
    post:
      summary: Post Backtest
      description: |-
        Submit a backtest job.

        Two modes:
          * **Async** (default, `wait_for_result=false`): returns HTTP 202 +
            `job_id` immediately. Client polls `GET /v1/backtest/{job_id}`.
            Best for UI and long jobs; survives client disconnects.
          * **Sync-style** (`wait_for_result=true`): the API holds the
            connection while a worker processes the job, then returns HTTP
            200 with the completed result inline. Matches the curl-friendly
            pattern PolyBackTest data customers expect. Caps at 30 s of
            wait; longer than that and you get a 504 + the job_id so you
            can keep polling.

        Tier gates (rate limit already checked in `authed_key`):
          * `market_limit` cap from the tier prevents Free users from
            queueing a 500-market scan.
          * Per-key concurrent in-flight cap (`tier.concurrent_backtests`):
            users can't flood the queue with their own work and starve
            others.
      operationId: post_backtest_v1_backtest_post
      parameters:
        - name: wait_for_result
          in: query
          required: false
          schema:
            type: boolean
            description: >-
              If true, hold the HTTP connection until the backtest finishes (up
              to 30 s) and return the completed result inline — like a
              synchronous endpoint. If 30 s isn't enough, you'll get a 504 with
              the job_id so you can poll GET /v1/backtest/{job_id} instead. Use
              false (default) for UI / long jobs.
            default: false
            title: Wait For Result
          description: >-
            If true, hold the HTTP connection until the backtest finishes (up to
            30 s) and return the completed result inline — like a synchronous
            endpoint. If 30 s isn't enough, you'll get a 504 with the job_id so
            you can poll GET /v1/backtest/{job_id} instead. Use false (default)
            for UI / long jobs.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BacktestRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostBacktestVBacktestPostResponse'
              example:
                job_id: bt_8421ae0c
                status: queued
                submitted_at: '2026-06-06T03:54:11+00:00'
                strategy:
                  type: threshold_entry
                  threshold: 0.3
                  direction: below
                  side: buy_yes
                params:
                  position_size: 7.5
                  fill_mode: walk_book
                  max_fill_price: 0.985
                  taker_fee_rate: 0.072
                universe:
                  ticker: BTC
                  event_type: 5m
                  market_limit: 50
                result: null
                error: null
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    BacktestRequest:
      properties:
        strategy:
          additionalProperties: true
          type: object
          title: Strategy
          examples:
            - direction: below
              side: buy_yes
              size_usd: 100
              threshold: 0.3
              type: threshold_entry
            - lookback: 30
              size_usd: 100
              type: mean_reversion
              z_threshold: 2
        event_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Event Type
        ticker:
          anyOf:
            - type: string
            - type: 'null'
          title: Ticker
        since:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Since
        until:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Until
        market_limit:
          type: integer
          maximum: 500
          title: Market Limit
          default: 50
      type: object
      required:
        - strategy
      title: BacktestRequest
    PostBacktestVBacktestPostResponse:
      type: object
      properties:
        job_id:
          type: string
        status:
          type: string
          enum:
            - queued
            - running
            - complete
            - failed
        submitted_at:
          type: string
          format: date-time
        strategy:
          type: object
          properties:
            type:
              type: string
            threshold:
              type: number
              format: double
            direction:
              type: string
              enum:
                - BUY_YES
                - BUY_NO
                - BUY_BOTH
              description: >-
                Which side to buy. `BUY_BOTH` only used for `tier=logical` (buy
                both legs for guaranteed payoff).
            side:
              type: string
              enum:
                - buy_yes
                - sell_yes
                - buy_no
                - sell_no
                - BUY_YES
                - SELL_YES
                - BUY_NO
                - SELL_NO
          required:
            - type
            - threshold
            - direction
            - side
        params:
          type: object
          properties:
            position_size:
              type: number
              format: double
            fill_mode:
              type: string
              enum:
                - mid
                - walk_book
            max_fill_price:
              type: number
              format: double
            taker_fee_rate:
              type: number
              format: double
          required:
            - position_size
            - fill_mode
            - max_fill_price
            - taker_fee_rate
        universe:
          type: object
          properties:
            ticker:
              type: string
              enum:
                - BTC
                - ETH
                - SOL
            event_type:
              type: string
              enum:
                - 5m
                - 15m
                - 1h
                - 4h
                - daily_up_down
            market_limit:
              type: integer
              format: int64
          required:
            - ticker
            - event_type
            - market_limit
        result:
          type: 'null'
        error:
          type: 'null'
      required:
        - job_id
        - status
        - submitted_at
        - strategy
        - params
        - universe
        - result
        - error
    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
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key

````