{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/pruviq-com/json-schema/pruviq-com-backtest-request-schema.json",
  "title": "BacktestRequest",
  "description": "Custom strategy backtest request from Strategy Builder.",
  "x-generated": "2026-11-22",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/pruviq-com-openapi.json#/components/schemas/BacktestRequest",
  "properties": {
    "name": {
      "type": "string",
      "maxLength": 100,
      "title": "Name",
      "default": "Custom Strategy"
    },
    "direction": {
      "type": "string",
      "title": "Direction",
      "description": "short | long. Omitted → SHORT (the documented /backtest default). Unlike /simulate, which resolves an omitted direction from the strategy registry, /backtest has no strategy id to resolve from — send direction explicitly. The response's direction_source says whether it was sent or defaulted (Q-B82).",
      "default": "short"
    },
    "indicators": {
      "additionalProperties": true,
      "type": "object",
      "title": "Indicators",
      "description": "Indicator configs: {'bb': {'period': 20}, 'ema': {}, ...}",
      "default": {
        "bb": {},
        "ema": {},
        "volume": {},
        "candle": {}
      }
    },
    "entry": {
      "additionalProperties": true,
      "type": "object",
      "title": "Entry",
      "description": "Entry conditions tree: {'type': 'AND', 'conditions': [...]}"
    },
    "exit_conditions": {
      "anyOf": [
        {
          "additionalProperties": true,
          "type": "object"
        },
        {
          "type": "null"
        }
      ],
      "title": "Exit Conditions",
      "description": "Optional exit-signal conditions tree (same shape as entry). When met during an open trade, exit early (exit_reason='signal'). null = no signal exit (TP/SL/trailing/timeout only)."
    },
    "avoid_hours": {
      "items": {
        "type": "integer"
      },
      "type": "array",
      "title": "Avoid Hours",
      "description": "UTC hours to avoid (0-23)",
      "default": []
    },
    "avoid_months": {
      "anyOf": [
        {
          "items": {
            "type": "integer"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Avoid Months",
      "description": "Months to avoid entering trades (1-12). null = no month filter"
    },
    "min_vol_regime": {
      "anyOf": [
        {
          "type": "number"
        },
        {
          "type": "null"
        }
      ],
      "title": "Min Vol Regime",
      "description": "Minimum ATR ratio (current ATR / 14-period ATR MA) to allow entry. e.g., 0.7 = skip low-volatility periods. null = no filter"
    },
    "sl_pct": {
      "type": "number",
      "maximum": 50.0,
      "minimum": 0.5,
      "title": "Sl Pct",
      "description": "Stop Loss %",
      "default": 10.0
    },
    "tp_pct": {
      "type": "number",
      "maximum": 100.0,
      "minimum": 0.5,
      "title": "Tp Pct",
      "description": "Take Profit %",
      "default": 8.0
    },
    "tp_source": {
      "type": "string",
      "enum": [
        "custom_pct",
        "trailing"
      ],
      "title": "Tp Source",
      "description": "Exit mode: custom_pct = fixed TP/SL; trailing = trailing stop (tp_pct is the trail distance)",
      "default": "custom_pct"
    },
    "trailing_pct": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 50.0,
          "minimum": 0.5
        },
        {
          "type": "null"
        }
      ],
      "title": "Trailing Pct",
      "description": "Trailing stop distance %. If null and tp_source=trailing, uses tp_pct."
    },
    "max_bars": {
      "type": "integer",
      "maximum": 168.0,
      "minimum": 1.0,
      "title": "Max Bars",
      "description": "Max holding period (bars)",
      "default": 48
    },
    "top_n": {
      "anyOf": [
        {
          "type": "integer",
          "maximum": 535.0,
          "minimum": 1.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Top N",
      "description": "Number of coins (null = top 50)"
    },
    "symbols": {
      "anyOf": [
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        {
          "type": "null"
        }
      ],
      "title": "Symbols",
      "description": "Specific symbols"
    },
    "include_stablecoins": {
      "type": "boolean",
      "title": "Include Stablecoins",
      "description": "Include stablecoins (USDC, DAI…) in the top_n universe. Default false — ~0 volatility → empty backtests. Ignored when `symbols` is set (explicit picks always honored).",
      "default": false
    },
    "symbol": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Symbol",
      "description": "Single-symbol alias for `symbols`. Auto-mapped (prevents silent ignore)."
    },
    "start_date": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "Start Date",
      "description": "Backtest start date (YYYY-MM-DD)"
    },
    "end_date": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "title": "End Date",
      "description": "Backtest end date (YYYY-MM-DD)"
    },
    "timeframe": {
      "type": "string",
      "enum": [
        "1H",
        "2H",
        "4H",
        "6H",
        "12H",
        "1D",
        "1W"
      ],
      "title": "Timeframe",
      "description": "Candle timeframe: 1H, 2H, 4H, 6H, 12H, 1D, 1W",
      "default": "1H"
    },
    "fee_pct": {
      "anyOf": [
        {
          "type": "number",
          "maximum": 0.01,
          "minimum": 0.0
        },
        {
          "type": "null"
        }
      ],
      "title": "Fee Pct",
      "description": "Fee per side (0.0005 = 0.05%). None = use market_type default"
    },
    "per_coin_usd": {
      "type": "number",
      "maximum": 1000000.0,
      "minimum": 1.0,
      "title": "Per Coin Usd",
      "description": "USD per coin position (compounding=True: total portfolio capital)",
      "default": 60.0
    },
    "leverage": {
      "type": "integer",
      "maximum": 125.0,
      "minimum": 1.0,
      "title": "Leverage",
      "description": "Leverage multiplier",
      "default": 1
    },
    "max_concurrent_positions": {
      "type": "integer",
      "maximum": 1000.0,
      "minimum": 1.0,
      "title": "Max Concurrent Positions",
      "description": "Max simultaneous open positions",
      "default": 100
    },
    "compounding": {
      "type": "boolean",
      "title": "Compounding",
      "description": "True = reinvest profits (compound), False = fixed position size (simple)",
      "default": false
    }
  },
  "type": "object",
  "required": [
    "entry"
  ]
}