> ## 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.

# Get trade history

> Retrieve closed trades with P&L and aggregate statistics.



## OpenAPI

````yaml /api/openapi.json get /api/graph/v1/execution/history
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/execution/history:
    get:
      tags:
        - Execution
      summary: Get trade history
      description: Retrieve closed trades with P&L and aggregate statistics.
      operationId: get_trade_history_api_graph_v1_execution_history_get
      parameters:
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            maximum: 200
            minimum: 1
            description: Max trades to return
            default: 50
            title: Limit
          description: Max trades to return
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
            description: Number of records to skip
            default: 0
            title: Offset
          description: Number of records to skip
        - name: start_date
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: Start date (ISO, e.g. 2026-01-01)
            title: Start Date
          description: Start date (ISO, e.g. 2026-01-01)
        - name: end_date
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: End date (ISO, e.g. 2026-12-31)
            title: End Date
          description: End date (ISO, e.g. 2026-12-31)
      responses:
        '200':
          description: Trade history returned
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TradeHistoryResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    TradeHistoryResponse:
      properties:
        trades:
          items:
            $ref: '#/components/schemas/TradeExecution'
          type: array
          title: Trades
          description: Closed trade executions
        total:
          type: integer
          title: Total
          description: Total number of matching closed trades
          default: 0
        stats:
          additionalProperties: true
          type: object
          title: Stats
          description: >-
            Aggregate stats (total_trades, winners, losers, win_rate, total_pnl,
            avg_pnl_pct)
      type: object
      title: TradeHistoryResponse
      description: Response for closed trades query.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    TradeExecution:
      properties:
        id:
          type: string
          format: uuid
          title: Id
          description: Trade execution UUID
        debate_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Debate Id
          description: Source debate UUID that triggered this execution
        symbol:
          type: string
          title: Symbol
          description: Stock ticker symbol
        direction:
          $ref: '#/components/schemas/app__models__execution__TradeDirection'
          description: Trade direction
        execution_mode:
          $ref: '#/components/schemas/ExecutionMode'
          description: Assisted or autonomous
        status:
          $ref: '#/components/schemas/TradeExecutionStatus'
          description: Current lifecycle status
        strategy_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Strategy Name
          description: Active strategy name
        instrument_type:
          $ref: '#/components/schemas/app__models__execution__InstrumentType'
          description: Instrument type
          default: option
        contract_symbol:
          anyOf:
            - type: string
            - type: 'null'
          title: Contract Symbol
          description: OCC contract symbol
        entry_order_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Entry Order Id
          description: Alpaca entry order ID
        entry_price:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Entry Price
          description: Filled entry price
        entry_quantity:
          anyOf:
            - type: integer
            - type: 'null'
          title: Entry Quantity
          description: Filled entry quantity
        entry_filled_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Entry Filled At
          description: Entry fill timestamp
        exit_order_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Exit Order Id
          description: Alpaca exit order ID
        exit_price:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Exit Price
          description: Filled exit price
        exit_quantity:
          anyOf:
            - type: integer
            - type: 'null'
          title: Exit Quantity
          description: Filled exit quantity
        exit_filled_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Exit Filled At
          description: Exit fill timestamp
        exit_reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Exit Reason
          description: Reason for exit (e.g., 'target_hit', 'stop_loss', 'time_exit')
        realized_pnl:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Realized Pnl
          description: Realized P&L in dollars
        realized_pnl_pct:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Realized Pnl Pct
          description: Realized P&L as percentage
        max_favorable_excursion:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Max Favorable Excursion
          description: Maximum favorable excursion (best unrealized P&L)
        max_adverse_excursion:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Max Adverse Excursion
          description: Maximum adverse excursion (worst unrealized P&L)
        risk_dollars:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Risk Dollars
          description: Dollars at risk
        initial_stop:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Initial Stop
          description: Initial stop loss price
        current_stop:
          anyOf:
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: 'null'
          title: Current Stop
          description: Current (possibly adjusted) stop price
        trading_mode:
          type: string
          title: Trading Mode
          description: 'Trading mode: ''paper'' or ''live'''
          default: paper
        created_at:
          type: string
          format: date-time
          title: Created At
          description: Record creation timestamp
        updated_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updated At
          description: Last update timestamp
      type: object
      required:
        - id
        - symbol
        - direction
        - execution_mode
        - status
      title: TradeExecution
      description: |-
        Complete trade execution record.

        Tracks the full lifecycle from strategy generation through close,
        including all entry/exit details, P&L, and risk parameters.
    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
    app__models__execution__TradeDirection:
      type: string
      enum:
        - long
        - short
      title: TradeDirection
      description: Trade direction.
    ExecutionMode:
      type: string
      enum:
        - assisted
        - autonomous
      title: ExecutionMode
      description: Execution mode determining human involvement.
    TradeExecutionStatus:
      type: string
      enum:
        - strategy_generated
        - risk_validated
        - awaiting_entry
        - order_pending
        - position_open
        - exit_pending
        - closed
        - cancelled
        - rejected
        - expired
        - error
        - pending_submission
        - partially_filled
        - submission_failed
        - pending_verification
      title: TradeExecutionStatus
      description: |-
        Trade execution lifecycle status.

        Matches the DB enum for trade_execution.status column.
        Transitions are enforced by TradeManager.VALID_TRANSITIONS.
    app__models__execution__InstrumentType:
      type: string
      enum:
        - option
        - equity
      title: InstrumentType
      description: Instrument type for the trade.

````