{
 "openapi": "3.1.0",
 "info": {
  "title": "Metrand API",
  "version": "1.0.0",
  "summary": "Write, check and backtest trading strategies on the Metrand engine.",
  "description": "The public API of Metrand. Every request carries an API key (`Authorization: Bearer mtr_…`), made under Account → API keys; a key acts as its user, narrowed by its scopes, and all of a workspace's keys share its plan's limits. Failures are RFC 9457 problem details with a stable `code`. Backtests are jobs: `POST /backtests` answers at once, `Prefer: wait=N` holds the answer up to N seconds (20 at most), and identical requests share one result. Version 1 only ever grows: fields, endpoints and enum values may be added, nothing is renamed or removed. Guide: https://metrand.com/docs/api.",
  "contact": {
   "url": "https://metrand.com"
  }
 },
 "servers": [
  {
   "url": "https://metrand.com/api/v1"
  }
 ],
 "security": [
  {
   "apiKey": []
  }
 ],
 "tags": [
  {
   "name": "account"
  },
  {
   "name": "reference"
  },
  {
   "name": "strategies"
  },
  {
   "name": "backtests"
  }
 ],
 "paths": {
  "/me": {
   "get": {
    "operationId": "getMe",
    "summary": "Who the key acts as",
    "description": "The key, its user and workspace, the plan's limits and today's use.",
    "tags": [
     "account"
    ],
    "responses": {
     "200": {
      "description": "The key's context.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Me"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     }
    }
   }
  },
  "/catalog": {
   "get": {
    "operationId": "getCatalog",
    "summary": "Engine op catalog",
    "description": "Every op a strategy graph may use, with its kind, parameters and ports: the engine's own catalog.",
    "tags": [
     "reference"
    ],
    "responses": {
     "200": {
      "description": "The catalog.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Catalog"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "read"
   }
  },
  "/templates": {
   "get": {
    "operationId": "listTemplates",
    "summary": "Strategy templates",
    "description": "The templates a strategy can start from, each with its graph and its latest measurement on the reference market.",
    "tags": [
     "reference"
    ],
    "responses": {
     "200": {
      "description": "The templates.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "object",
          "data",
          "next_cursor"
         ],
         "properties": {
          "object": {
           "type": "string",
           "const": "list"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Template"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ],
           "description": "Pass as `cursor` for the next page; null on the last."
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     }
    },
    "x-required-scope": "read"
   }
  },
  "/markets": {
   "get": {
    "operationId": "listMarkets",
    "summary": "Markets an exchange lists",
    "description": "USDT perpetuals of the exchange, sorted by symbol. No prices. The whole list comes at once: it is not paged and `next_cursor` is always null.",
    "tags": [
     "reference"
    ],
    "responses": {
     "200": {
      "description": "The markets.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "object",
          "data",
          "next_cursor"
         ],
         "properties": {
          "object": {
           "type": "string",
           "const": "list"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/MarketRef"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ],
           "description": "Pass as `cursor` for the next page; null on the last."
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "name": "exchange",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "binance",
        "bybit"
       ],
       "default": "binance"
      }
     }
    ]
   }
  },
  "/markets/{exchange}/{symbol}": {
   "get": {
    "operationId": "getMarket",
    "summary": "One market's rules",
    "description": "Timeframes, lot rules, leverage tiers and standard fees of one market.",
    "tags": [
     "reference"
    ],
    "responses": {
     "200": {
      "description": "The market.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Market"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "name": "exchange",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "binance",
        "bybit"
       ]
      }
     },
     {
      "name": "symbol",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "example": "BTCUSDT"
      }
     }
    ]
   }
  },
  "/strategies/validate": {
   "post": {
    "operationId": "validateGraph",
    "summary": "Check a graph",
    "description": "Whether the engine compiles a graph, and the history it needs. A graph that does not compile is an answer (`valid: false`), not an error.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "200": {
      "description": "The verdict.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Validation"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "422": {
      "$ref": "#/components/responses/422"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "research",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "dsl"
        ],
        "properties": {
         "dsl": {
          "$ref": "#/components/schemas/Graph"
         }
        }
       }
      }
     }
    }
   }
  },
  "/strategies": {
   "get": {
    "operationId": "listStrategies",
    "summary": "List strategies",
    "description": "The workspace's strategies, newest first.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "200": {
      "description": "A page of strategies.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "object",
          "data",
          "next_cursor"
         ],
         "properties": {
          "object": {
           "type": "string",
           "const": "list"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Strategy"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ],
           "description": "Pass as `cursor` for the next page; null on the last."
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "422": {
      "$ref": "#/components/responses/422"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/limit"
     },
     {
      "$ref": "#/components/parameters/cursor"
     },
     {
      "name": "archived",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      }
     }
    ]
   },
   "post": {
    "operationId": "createStrategy",
    "summary": "Create a strategy",
    "description": "A new strategy with its first version, from a template or a graph. Graphs beyond what the app's composer builds need a plan with the expert editor.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "201": {
      "description": "Created.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "$ref": "#/components/schemas/Strategy"
          },
          {
           "type": "object",
           "properties": {
            "version": {
             "$ref": "#/components/schemas/StrategyVersion"
            }
           }
          }
         ]
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       },
       "Location": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "413": {
      "$ref": "#/components/responses/413"
     },
     "422": {
      "$ref": "#/components/responses/422"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "strategies:write",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "name"
        ],
        "properties": {
         "name": {
          "type": "string",
          "minLength": 2,
          "maxLength": 80
         },
         "template": {
          "type": "string",
          "description": "A template key from GET /templates; or give `dsl`."
         },
         "dsl": {
          "$ref": "#/components/schemas/Graph"
         }
        }
       }
      }
     }
    }
   }
  },
  "/strategies/{id}": {
   "get": {
    "operationId": "getStrategy",
    "summary": "Get a strategy",
    "description": "One strategy with its version count and newest version.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "200": {
      "description": "The strategy.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Strategy"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/strategyId"
     }
    ]
   }
  },
  "/strategies/{id}/versions": {
   "get": {
    "operationId": "listVersions",
    "summary": "List versions",
    "description": "A strategy's versions, newest first, without their graphs.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "200": {
      "description": "A page of versions.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "object",
          "data",
          "next_cursor"
         ],
         "properties": {
          "object": {
           "type": "string",
           "const": "list"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/StrategyVersion"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ],
           "description": "Pass as `cursor` for the next page; null on the last."
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "422": {
      "$ref": "#/components/responses/422"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/strategyId"
     },
     {
      "$ref": "#/components/parameters/limit"
     },
     {
      "$ref": "#/components/parameters/cursor"
     }
    ]
   },
   "post": {
    "operationId": "createVersion",
    "summary": "Save a version",
    "description": "An immutable version, named by its content hash. Saving a graph the strategy already has returns that version (200) instead of a new one (201).",
    "tags": [
     "strategies"
    ],
    "responses": {
     "201": {
      "description": "A new version.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StrategyVersion"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "200": {
      "description": "The version this graph already is.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StrategyVersion"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     },
     "422": {
      "$ref": "#/components/responses/422"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "strategies:write",
    "parameters": [
     {
      "$ref": "#/components/parameters/strategyId"
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "dsl"
        ],
        "properties": {
         "dsl": {
          "$ref": "#/components/schemas/Graph"
         }
        }
       }
      }
     }
    }
   }
  },
  "/strategies/{id}/versions/{hash}": {
   "get": {
    "operationId": "getVersion",
    "summary": "Get a version",
    "description": "One version with its graph.",
    "tags": [
     "strategies"
    ],
    "responses": {
     "200": {
      "description": "The version.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StrategyVersion"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/strategyId"
     },
     {
      "name": "hash",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9a-f]{6,64}$",
       "description": "A version's content hash (64 hex characters); a unique prefix of at least 6 is accepted."
      }
     }
    ]
   }
  },
  "/backtests": {
   "get": {
    "operationId": "listBacktests",
    "summary": "List backtests",
    "description": "The workspace's backtests, newest first: those asked for here and those run in the app.",
    "tags": [
     "backtests"
    ],
    "responses": {
     "200": {
      "description": "A page of backtests.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "object",
          "data",
          "next_cursor"
         ],
         "properties": {
          "object": {
           "type": "string",
           "const": "list"
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Backtest"
           }
          },
          "next_cursor": {
           "type": [
            "string",
            "null"
           ],
           "description": "Pass as `cursor` for the next page; null on the last."
          }
         }
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "422": {
      "$ref": "#/components/responses/422"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/limit"
     },
     {
      "$ref": "#/components/parameters/cursor"
     },
     {
      "name": "strategy",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "version",
      "in": "query",
      "schema": {
       "type": "string",
       "pattern": "^[0-9a-f]{6,64}$",
       "description": "A version's content hash (64 hex characters); a unique prefix of at least 6 is accepted."
      },
      "description": "Needs `strategy`."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "$ref": "#/components/schemas/BacktestStatus"
      }
     }
    ]
   },
   "post": {
    "operationId": "createBacktest",
    "summary": "Run a backtest",
    "description": "Accepts a backtest of a saved version as a job. It is charged against the workspace's daily backtests when accepted and given back if it fails for a reason that is not the request's. An identical request (same strategy and version, market, resolved window, costs and engine release) returns the backtest that has or is computing that result, at no charge (`Backtest-Reused: true`).",
    "tags": [
     "backtests"
    ],
    "responses": {
     "202": {
      "description": "Not finished yet: accepted now, or an identical backtest still under way (`Backtest-Reused: true`).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Backtest"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       },
       "Location": {
        "schema": {
         "type": "string"
        }
       },
       "Backtest-Reused": {
        "schema": {
         "type": "string",
         "const": "true"
        }
       },
       "Preference-Applied": {
        "schema": {
         "type": "string"
        },
        "description": "`wait=N` when the request waited; absent when it was answered at once."
       }
      }
     },
     "201": {
      "description": "Accepted and ended within the wait (succeeded or failed).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Backtest"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       },
       "Location": {
        "schema": {
         "type": "string"
        }
       },
       "Preference-Applied": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "200": {
      "description": "An identical backtest already had this result.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Backtest"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       },
       "Backtest-Reused": {
        "schema": {
         "type": "string",
         "const": "true"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     },
     "413": {
      "$ref": "#/components/responses/413"
     },
     "422": {
      "$ref": "#/components/responses/422"
     },
     "503": {
      "$ref": "#/components/responses/503"
     }
    },
    "x-required-scope": "research",
    "parameters": [
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     },
     {
      "$ref": "#/components/parameters/Prefer"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BacktestRequest"
       }
      }
     }
    }
   }
  },
  "/backtests/{id}": {
   "get": {
    "operationId": "getBacktest",
    "summary": "Get a backtest",
    "description": "A backtest and, once it succeeded, its result.",
    "tags": [
     "backtests"
    ],
    "responses": {
     "200": {
      "description": "The backtest.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Backtest"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/backtestId"
     }
    ]
   }
  },
  "/backtests/{id}/cancel": {
   "post": {
    "operationId": "cancelBacktest",
    "summary": "Cancel a backtest",
    "description": "Cancels a backtest still waiting in the queue and gives its charge back. One that started runs to its end.",
    "tags": [
     "backtests"
    ],
    "responses": {
     "200": {
      "description": "Canceled.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Backtest"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     }
    },
    "x-required-scope": "research",
    "parameters": [
     {
      "$ref": "#/components/parameters/backtestId"
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ]
   }
  },
  "/backtests/{id}/trades": {
   "get": {
    "operationId": "listBacktestTrades",
    "summary": "A backtest's trades",
    "description": "Every trade the backtest kept, in the order they closed.",
    "tags": [
     "backtests"
    ],
    "responses": {
     "200": {
      "description": "A page of trades.",
      "content": {
       "application/json": {
        "schema": {
         "allOf": [
          {
           "type": "object",
           "required": [
            "object",
            "data",
            "next_cursor"
           ],
           "properties": {
            "object": {
             "type": "string",
             "const": "list"
            },
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/Trade"
             }
            },
            "next_cursor": {
             "type": [
              "string",
              "null"
             ],
             "description": "Pass as `cursor` for the next page; null on the last."
            }
           }
          },
          {
           "type": "object",
           "properties": {
            "total": {
             "type": "integer",
             "description": "Trades the backtest made."
            },
            "stored": {
             "type": [
              "integer",
              "null"
             ],
             "description": "Trades kept; a very long backtest keeps the first ones."
            }
           }
          }
         ]
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     },
     "422": {
      "$ref": "#/components/responses/422"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/backtestId"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 1000,
       "default": 25
      }
     },
     {
      "$ref": "#/components/parameters/cursor"
     }
    ]
   }
  },
  "/backtests/{id}/equity": {
   "get": {
    "operationId": "getBacktestEquity",
    "summary": "A backtest's equity curve",
    "description": "The account's equity over the backtest, thinned to at most `points` points (10 to 5,000; 500 when left out): each part of the curve keeps its lowest and highest point, so drawdowns survive.",
    "tags": [
     "backtests"
    ],
    "responses": {
     "200": {
      "description": "The curve.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Equity"
        }
       }
      },
      "headers": {
       "RateLimit-Limit": {
        "$ref": "#/components/headers/RateLimit-Limit"
       },
       "RateLimit-Remaining": {
        "$ref": "#/components/headers/RateLimit-Remaining"
       },
       "RateLimit-Reset": {
        "$ref": "#/components/headers/RateLimit-Reset"
       },
       "X-Request-Id": {
        "$ref": "#/components/headers/X-Request-Id"
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/401"
     },
     "403": {
      "$ref": "#/components/responses/403"
     },
     "429": {
      "$ref": "#/components/responses/429"
     },
     "404": {
      "$ref": "#/components/responses/404"
     },
     "409": {
      "$ref": "#/components/responses/409"
     },
     "422": {
      "$ref": "#/components/responses/422"
     }
    },
    "x-required-scope": "read",
    "parameters": [
     {
      "$ref": "#/components/parameters/backtestId"
     },
     {
      "name": "points",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 10,
       "maximum": 5000,
       "default": 500
      }
     }
    ]
   }
  },
  "/openapi.json": {
   "get": {
    "operationId": "getOpenApi",
    "summary": "This document",
    "security": [],
    "tags": [
     "reference"
    ],
    "responses": {
     "200": {
      "description": "The OpenAPI document.",
      "content": {
       "application/json": {}
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "apiKey": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "mtr_<12>_<43>",
    "description": "An API key from Account → API keys."
   }
  },
  "headers": {
   "RateLimit-Limit": {
    "description": "Requests a minute the workspace may make.",
    "schema": {
     "type": "integer"
    }
   },
   "RateLimit-Remaining": {
    "description": "Requests left in this minute.",
    "schema": {
     "type": "integer"
    }
   },
   "RateLimit-Reset": {
    "description": "Seconds until the minute resets.",
    "schema": {
     "type": "integer"
    }
   },
   "X-Request-Id": {
    "description": "This request's id; errors repeat it.",
    "schema": {
     "type": "string"
    }
   }
  },
  "parameters": {
   "limit": {
    "name": "limit",
    "in": "query",
    "schema": {
     "type": "integer",
     "minimum": 1,
     "maximum": 100,
     "default": 25
    }
   },
   "cursor": {
    "name": "cursor",
    "in": "query",
    "schema": {
     "type": "string"
    },
    "description": "`next_cursor` of the previous page of the same list; any other cursor is refused (422)."
   },
   "strategyId": {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   },
   "backtestId": {
    "name": "id",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    }
   },
   "IdempotencyKey": {
    "name": "Idempotency-Key",
    "in": "header",
    "schema": {
     "type": "string",
     "maxLength": 255
    },
    "description": "The same key and body from the same API key within 24 hours return the first answer (`Idempotent-Replayed: true`). Successes and refusals of the request as written (422) are kept; any other answer is not, so a retry runs again."
   },
   "Prefer": {
    "name": "Prefer",
    "in": "header",
    "schema": {
     "type": "string",
     "example": "wait=30"
    },
    "description": "`wait=N` (N ≤ 20; more is read as 20) holds the answer until the backtest ends or N seconds pass, and the answer says `Preference-Applied: wait=N`. A workspace has at most two requests waiting at once, and the server a few in all: one past them is answered at once (`202`, no `Preference-Applied`), to be read again."
   }
  },
  "responses": {
   "401": {
    "description": "No key, or one that is unknown, revoked or expired (`unauthenticated`, `invalid_api_key`).",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "403": {
    "description": "The key lacks the scope (`insufficient_scope`), its user's role or the plan does not allow it (`forbidden`, `plan_required`), or the address is not allowed (`ip_not_allowed`).",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "404": {
    "description": "Nothing with that id in this workspace (`not_found`).",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "409": {
    "description": "The resource's state does not allow it (`conflict`, `idempotency_in_progress`).",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "413": {
    "description": "The request body is over 1 MB (`payload_too_large`).",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "422": {
    "description": "A field is not valid (`validation_failed`, with `errors`), or an idempotency key was reused with another body.",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "429": {
    "description": "Too many requests (`rate_limited`), the daily quota is spent (`quota_exceeded`) or the backtest lane is full (`too_many_jobs`). `Retry-After` says when.",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   },
   "503": {
    "description": "A service it needs is unavailable (`service_unavailable`, `market_data_unavailable`); nothing was charged.",
    "content": {
     "application/problem+json": {
      "schema": {
       "$ref": "#/components/schemas/Problem"
      }
     }
    }
   }
  },
  "schemas": {
   "Problem": {
    "type": "object",
    "required": [
     "type",
     "title",
     "status",
     "code",
     "detail"
    ],
    "properties": {
     "type": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "status": {
      "type": "integer"
     },
     "code": {
      "type": "string",
      "enum": [
       "unauthenticated",
       "invalid_api_key",
       "forbidden",
       "insufficient_scope",
       "plan_required",
       "ip_not_allowed",
       "not_found",
       "method_not_allowed",
       "conflict",
       "idempotency_in_progress",
       "payload_too_large",
       "unsupported_media_type",
       "validation_failed",
       "idempotency_key_reused",
       "rate_limited",
       "quota_exceeded",
       "too_many_jobs",
       "market_data_unavailable",
       "service_unavailable",
       "internal_error"
      ]
     },
     "detail": {
      "type": "string"
     },
     "request_id": {
      "type": [
       "string",
       "null"
      ]
     },
     "errors": {
      "type": "object",
      "additionalProperties": {
       "type": "array",
       "items": {
        "type": "string"
       }
      }
     },
     "required_scope": {
      "type": "string"
     }
    }
   },
   "Me": {
    "type": "object",
    "properties": {
     "object": {
      "const": "me"
     },
     "key": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "name": {
        "type": "string"
       },
       "prefix": {
        "type": "string"
       },
       "scopes": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/Scope"
        }
       },
       "expires_at": {
        "type": [
         "string",
         "null"
        ],
        "format": "date-time"
       }
      }
     },
     "user": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "role": {
        "type": "string",
        "enum": [
         "viewer",
         "trader",
         "operator",
         "admin"
        ]
       }
      }
     },
     "workspace": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "name": {
        "type": "string"
       },
       "plan": {
        "type": "string",
        "enum": [
         "free",
         "pro",
         "expert",
         "enterprise"
        ]
       }
      }
     },
     "limits": {
      "type": "object",
      "properties": {
       "requests_per_minute": {
        "type": "integer"
       },
       "backtests_running": {
        "type": "integer"
       },
       "backtests_waiting": {
        "type": "integer"
       },
       "backtests_per_day": {
        "type": "integer"
       },
       "max_backtest_bars": {
        "type": "integer"
       }
      }
     },
     "usage": {
      "type": "object",
      "properties": {
       "backtests_today": {
        "type": [
         "integer",
         "null"
        ]
       }
      }
     }
    }
   },
   "Scope": {
    "type": "string",
    "enum": [
     "read",
     "research",
     "strategies:write"
    ]
   },
   "Catalog": {
    "type": "object",
    "properties": {
     "object": {
      "const": "catalog"
     },
     "ops": {
      "type": "array",
      "items": {
       "type": "object",
       "description": "One engine op: kind, op, params, ports, aliases."
      }
     }
    }
   },
   "Graph": {
    "type": "object",
    "required": [
     "nodes",
     "output"
    ],
    "description": "A strategy graph: nodes (each with id, kind, op and params), edges between their ports, and the output node. The op catalog lists what each node may be.",
    "properties": {
     "nodes": {
      "type": "array",
      "minItems": 1,
      "maxItems": 200,
      "items": {
       "type": "object",
       "required": [
        "id",
        "kind",
        "op"
       ],
       "properties": {
        "id": {
         "type": "string"
        },
        "kind": {
         "type": "string"
        },
        "op": {
         "type": "string"
        },
        "params": {
         "type": "object"
        },
        "instrument": {
         "type": "string"
        }
       }
      }
     },
     "edges": {
      "type": "array",
      "maxItems": 400,
      "items": {
       "type": "object",
       "required": [
        "from",
        "to"
       ],
       "properties": {
        "from": {
         "type": "string"
        },
        "to": {
         "type": "string"
        },
        "port": {
         "type": "string"
        }
       }
      }
     },
     "output": {
      "type": "string"
     }
    }
   },
   "Template": {
    "type": "object",
    "properties": {
     "object": {
      "const": "template"
     },
     "key": {
      "type": "string"
     },
     "title": {
      "type": "string"
     },
     "style": {
      "type": "string"
     },
     "summary": {
      "type": "string"
     },
     "dsl": {
      "$ref": "#/components/schemas/Graph"
     },
     "measured": {
      "type": [
       "object",
       "null"
      ]
     }
    }
   },
   "MarketRef": {
    "type": "object",
    "properties": {
     "object": {
      "const": "market"
     },
     "exchange": {
      "type": "string"
     },
     "symbol": {
      "type": "string"
     }
    }
   },
   "Market": {
    "type": "object",
    "properties": {
     "object": {
      "const": "market"
     },
     "exchange": {
      "type": "string"
     },
     "symbol": {
      "type": "string"
     },
     "kind": {
      "const": "usdt_perpetual"
     },
     "intervals": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "lot": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "step": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "min_qty": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "min_notional": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "tick_size": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "max_leverage": {
      "type": [
       "string",
       "null"
      ]
     },
     "margin_tiers": {
      "type": [
       "array",
       "null"
      ],
      "items": {
       "type": "object",
       "properties": {
        "notional_cap": {
         "type": "string",
         "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
         "description": "A decimal as a string."
        },
        "maintenance_rate": {
         "type": "string",
         "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
         "description": "A decimal as a string."
        },
        "max_leverage": {
         "type": "string",
         "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
         "description": "A decimal as a string."
        }
       }
      }
     },
     "standard_fees_bps": {
      "type": "object",
      "properties": {
       "taker": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "maker": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       }
      }
     }
    }
   },
   "Validation": {
    "type": "object",
    "properties": {
     "object": {
      "const": "validation"
     },
     "valid": {
      "type": "boolean"
     },
     "error": {
      "type": [
       "string",
       "null"
      ]
     },
     "data_requirements": {
      "type": [
       "object",
       "null"
      ]
     }
    }
   },
   "Strategy": {
    "type": "object",
    "properties": {
     "object": {
      "const": "strategy"
     },
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "archived_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "version_count": {
      "type": "integer"
     },
     "latest_version": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "hash": {
        "type": "string",
        "pattern": "^[0-9a-f]{6,64}$",
        "description": "A version's content hash (64 hex characters); a unique prefix of at least 6 is accepted."
       },
       "created_at": {
        "type": "string",
        "format": "date-time"
       }
      }
     }
    }
   },
   "StrategyVersion": {
    "type": "object",
    "properties": {
     "object": {
      "const": "strategy_version"
     },
     "strategy_id": {
      "type": "string",
      "format": "uuid"
     },
     "strategy_name": {
      "type": "string"
     },
     "hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{6,64}$",
      "description": "A version's content hash (64 hex characters); a unique prefix of at least 6 is accepted."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "data_requirements": {
      "type": [
       "object",
       "null"
      ]
     },
     "dsl": {
      "$ref": "#/components/schemas/Graph"
     },
     "parameter_schema": {
      "type": [
       "array",
       "object",
       "null"
      ]
     }
    }
   },
   "BacktestStatus": {
    "type": "string",
    "enum": [
     "queued",
     "running",
     "succeeded",
     "failed",
     "canceled"
    ]
   },
   "Costs": {
    "type": "object",
    "description": "Fees and slippage in basis points of each fill's notional, the starting equity and the leverage. Left out, each is the exchange's standard.",
    "properties": {
     "taker_bps": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
     },
     "maker_bps": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
     },
     "slippage_bps": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
     },
     "start_equity": {
      "type": "number",
      "minimum": 10
     },
     "leverage": {
      "type": "number",
      "minimum": 1,
      "maximum": 125
     }
    }
   },
   "BacktestRequest": {
    "type": "object",
    "required": [
     "strategy",
     "market"
    ],
    "properties": {
     "strategy": {
      "type": "object",
      "required": [
       "id",
       "version"
      ],
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "version": {
        "type": "string",
        "pattern": "^[0-9a-f]{6,64}$",
        "description": "A version's content hash (64 hex characters); a unique prefix of at least 6 is accepted."
       }
      }
     },
     "market": {
      "type": "object",
      "required": [
       "symbol"
      ],
      "properties": {
       "exchange": {
        "type": "string",
        "enum": [
         "binance",
         "bybit"
        ],
        "default": "binance"
       },
       "symbol": {
        "type": "string",
        "example": "BTCUSDT",
        "description": "A market the exchange lists (`GET /markets`); any other is refused with 422 before anything is charged."
       },
       "interval": {
        "type": "string",
        "default": "1h",
        "description": "A timeframe (1m … 1M) or range bars (`r1.5` = 1.5%, `r100t` = 100 price steps)."
       }
      }
     },
     "window": {
      "type": "object",
      "description": "Either `start` (and optionally `end`) or `bars` (and optionally `end`). Times are RFC 3339 or epoch milliseconds; a window ends at the last bar closed by `end` (now when left out).",
      "properties": {
       "start": {
        "type": [
         "string",
         "integer"
        ]
       },
       "end": {
        "type": [
         "string",
         "integer"
        ]
       },
       "bars": {
        "type": "integer",
        "minimum": 10,
        "default": 500
       }
      }
     },
     "costs": {
      "$ref": "#/components/schemas/Costs"
     }
    }
   },
   "Backtest": {
    "type": "object",
    "properties": {
     "object": {
      "const": "backtest"
     },
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "status": {
      "$ref": "#/components/schemas/BacktestStatus"
     },
     "origin": {
      "type": "string",
      "enum": [
       "api",
       "app"
      ]
     },
     "strategy": {
      "type": "object",
      "properties": {
       "id": {
        "type": "string",
        "format": "uuid"
       },
       "version": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "market": {
      "type": "object",
      "properties": {
       "exchange": {
        "type": [
         "string",
         "null"
        ]
       },
       "symbol": {
        "type": [
         "string",
         "null"
        ]
       },
       "interval": {
        "type": [
         "string",
         "null"
        ]
       }
      }
     },
     "window": {
      "type": "object",
      "properties": {
       "start": {
        "type": [
         "string",
         "null"
        ],
        "format": "date-time"
       },
       "end": {
        "type": [
         "string",
         "null"
        ],
        "format": "date-time"
       },
       "bars": {
        "type": [
         "integer",
         "null"
        ]
       }
      }
     },
     "costs": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "taker_bps": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "maker_bps": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "slippage_bps": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "start_equity": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       },
       "leverage": {
        "type": "string",
        "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
        "description": "A decimal as a string."
       }
      }
     },
     "result": {
      "type": [
       "object",
       "null"
      ],
      "description": "Once succeeded.",
      "properties": {
       "report": {
        "type": "object",
        "description": "The engine's report: net P&L, return, drawdown, win rate, fills, fees, funding, the config it ran on, and what the bars were traded on inside them."
       },
       "break_even": {
        "type": [
         "object",
         "null"
        ]
       },
       "measured_on": {
        "type": "object",
        "properties": {
         "start": {
          "type": [
           "string",
           "null"
          ],
          "format": "date-time"
         },
         "end": {
          "type": [
           "string",
           "null"
          ],
          "format": "date-time"
         },
         "bars": {
          "type": [
           "integer",
           "null"
          ]
         },
         "interval": {
          "type": [
           "string",
           "null"
          ]
         },
         "source_interval": {
          "type": [
           "string",
           "null"
          ]
         },
         "source": {
          "type": "string"
         },
         "source_label": {
          "type": [
           "string",
           "null"
          ]
         }
        }
       },
       "trades": {
        "type": "object",
        "properties": {
         "count": {
          "type": "integer"
         },
         "stored": {
          "type": [
           "integer",
           "null"
          ]
         }
        }
       }
      }
     },
     "error": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "code": {
        "type": "string",
        "description": "validation_failed, backtest_failed, market_data_unavailable, service_unavailable or internal_error."
       },
       "message": {
        "type": "string"
       }
      }
     },
     "provenance": {
      "type": [
       "object",
       "null"
      ],
      "properties": {
       "fingerprint": {
        "type": "string"
       },
       "release": {
        "type": [
         "string",
         "null"
        ]
       },
       "method": {
        "type": "integer"
       }
      }
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "started_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "finished_at": {
      "type": [
       "string",
       "null"
      ],
      "format": "date-time"
     },
     "links": {
      "type": "object",
      "properties": {
       "self": {
        "type": "string"
       },
       "trades": {
        "type": "string"
       },
       "equity": {
        "type": "string"
       }
      }
     }
    }
   },
   "Trade": {
    "type": "object",
    "properties": {
     "seq": {
      "type": "integer"
     },
     "side": {
      "type": "string",
      "enum": [
       "long",
       "short"
      ]
     },
     "entry_at": {
      "type": "string",
      "format": "date-time"
     },
     "exit_at": {
      "type": "string",
      "format": "date-time"
     },
     "entry_price": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "A decimal as a string."
     },
     "exit_price": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "A decimal as a string."
     },
     "qty": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "A decimal as a string."
     },
     "pnl": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "Net of fees and funding."
     },
     "fees": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "A decimal as a string."
     },
     "funding": {
      "type": "string",
      "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
      "description": "A decimal as a string."
     },
     "reason": {
      "type": "string",
      "description": "tp, sl, signal, eod, liquidation, …"
     },
     "ambiguous_bar": {
      "type": "boolean",
      "description": "Its bar reached both stop and target and no finer candles could say which came first."
     }
    }
   },
   "Equity": {
    "type": "object",
    "properties": {
     "object": {
      "const": "equity"
     },
     "backtest_id": {
      "type": "string",
      "format": "uuid"
     },
     "points": {
      "type": "array",
      "items": {
       "type": "array",
       "prefixItems": [
        {
         "type": "integer",
         "description": "Epoch ms."
        },
        {
         "type": "string",
         "pattern": "^-?[0-9]+(\\.[0-9]+)?$",
         "description": "A decimal as a string."
        }
       ],
       "minItems": 2,
       "maxItems": 2
      }
     },
     "total_points": {
      "type": "integer"
     }
    }
   }
  }
 }
}
