{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tradingpal-io/json-schema/tradingpal-io-similar-schema.json",
  "title": "Similar",
  "description": "The similar trades of one current setup's order: its record and the matched trades, closest first.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tradingpal-io-openapi.json#/components/schemas/Similar",
  "type": "object",
  "properties": {
    "api_version": {
      "type": "string",
      "const": "v1",
      "description": "The contract version, always v1. Field names in v1 do not change, and v1 stays available at least 12 months after a v2 ships."
    },
    "as_of_session": {
      "type": [
        "string",
        "null"
      ],
      "description": "The last trading session the data describes, as an ISO date. Setups change nightly, so say it when presenting data and do not cache setups across days. Null on routes that do not read a dated artifact (account, tickers, history, families, universe and the demo index).",
      "format": "date"
    },
    "data_version": {
      "type": [
        "string",
        "null"
      ],
      "description": "Identifier of the stored artifact the answer came from: the candidate-book generation for patterns, the sealed manifest for family records. Null when the route reads no versioned artifact."
    },
    "source": {
      "type": "object",
      "description": "Who produced the data. Constant on every response.",
      "properties": {
        "name": {
          "type": "string",
          "description": "Always \"TradingPal\"."
        },
        "url": {
          "type": "string",
          "description": "Always https://tradingpal.io.",
          "format": "uri"
        }
      }
    },
    "disclaimer": {
      "type": "string",
      "const": "Educational breakout-pattern analysis from TradingPal, not investment advice. Past results do not guarantee future outcomes.",
      "description": "The educational-use disclaimer, constant on every response. Repeat it when presenting a setup as something the user might act on."
    },
    "symbol": {
      "type": "string",
      "description": "The symbol asked for."
    },
    "setup_id": {
      "type": "string",
      "description": "The setup asked for."
    },
    "direction": {
      "type": "string",
      "description": "The order whose similar trades these are.",
      "enum": [
        "bullish",
        "bearish"
      ]
    },
    "trigger_price": {
      "type": [
        "number",
        "null"
      ],
      "description": "That order's trigger."
    },
    "available": {
      "type": "boolean",
      "description": "False when the evening search holds no answer for the order yet."
    },
    "similar_trades": {
      "$ref": "#/$defs/SimilarRecord",
      "description": "The record of the matched trades. Null when available is false."
    },
    "matches": {
      "type": "array",
      "description": "The similar trades, closest match first.",
      "items": {
        "type": "object",
        "description": "One earlier trade.",
        "properties": {
          "symbol": {
            "type": "string",
            "description": "Its stock."
          },
          "company_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Its company."
          },
          "listed": {
            "type": "boolean",
            "description": "False for a stock that no longer trades."
          },
          "pattern_type": {
            "type": "string",
            "description": "Its pattern type."
          },
          "direction": {
            "type": "string",
            "description": "Its side."
          },
          "entry_date": {
            "type": "string",
            "description": "Entry session.",
            "format": "date"
          },
          "exit_date": {
            "type": "string",
            "description": "Exit session.",
            "format": "date"
          },
          "entry_price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Entry."
          },
          "stop_price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Stop."
          },
          "target_price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Target."
          },
          "exit_price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Exit."
          },
          "outcome": {
            "type": "string",
            "description": "win or loss."
          },
          "return_pct": {
            "type": [
              "number",
              "null"
            ],
            "description": "Return in percent before costs."
          },
          "r_multiple": {
            "type": [
              "number",
              "null"
            ],
            "description": "R multiple."
          },
          "hold_bars": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Daily bars held."
          },
          "similarity_distance": {
            "type": [
              "number",
              "null"
            ],
            "description": "How far its shape was from this order's; smaller is closer."
          }
        }
      }
    },
    "searched_session": {
      "type": [
        "string",
        "null"
      ],
      "description": "The session the resting order was searched for."
    },
    "through": {
      "type": [
        "string",
        "null"
      ],
      "description": "The last session the search covered."
    },
    "page_url": {
      "type": [
        "string",
        "null"
      ],
      "description": "The setup on the TradingPal site."
    }
  },
  "required": [
    "api_version",
    "as_of_session",
    "source",
    "disclaimer",
    "symbol",
    "setup_id",
    "available",
    "matches"
  ],
  "$defs": {
    "SimilarRecord": {
      "type": [
        "object",
        "null"
      ],
      "title": "SimilarRecord",
      "description": "How the earlier trades whose pattern looked most like this order's did: each on any stock, same side, entered and exited before this order. Quote summary whole; never the win rate alone.",
      "properties": {
        "count": {
          "type": "integer",
          "description": "How many similar trades were found (up to 50)."
        },
        "wins": {
          "type": [
            "integer",
            "null"
          ],
          "description": "How many of them won."
        },
        "losses": {
          "type": [
            "integer",
            "null"
          ],
          "description": "How many of them lost."
        },
        "win_rate_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "wins / count as a percent."
        },
        "avg_return_pct": {
          "type": [
            "number",
            "null"
          ],
          "description": "Their average return per trade, in percent before costs."
        },
        "avg_r": {
          "type": [
            "number",
            "null"
          ],
          "description": "Their average R multiple."
        },
        "locked": {
          "type": "boolean",
          "description": "True when the record is held back because the reader is not on Premium."
        },
        "floor": {
          "type": "object",
          "description": "The Edge Filter similar-trades check on this order: state none, judged or refused, with count and wins."
        },
        "summary": {
          "type": "string",
          "description": "The record in one sentence, to quote whole."
        }
      }
    }
  }
}