{
 "openapi": "3.1.0",
 "info": {
  "title": "OpenProp Agent API",
  "version": "1.1.0",
  "description": "Trade ONE OpenProp account (evaluation, funded or free practice) with a personal API key. Same engine and same rules as the web terminal. An API key can never withdraw, request a payout or change an address.\n\nAuth: `Authorization: Bearer opk_...` (create the key in Dashboard \u2192 API & Agents; shown once). Scopes: `read` (account, positions, orders, history, rules) and `trade` (place, cancel, close, TP/SL).\n\nLimits per key: 5 requests/s (burst 20), 2 orders/s (burst 6), 2 concurrent event waits.\n\nRules: equity at or below the floor (size \u2212 3%) ends the account; an evaluation passes at size + 9%; long + short notional per market is capped (5 \u00d7 size on BTC); reducing or closing is always allowed. Fees 3.3 bps per side; market orders fill after ~300 ms on the real Lighter order book."
 },
 "servers": [
  {
   "url": "https://{server}/pf-api",
   "variables": {
    "server": {
     "default": "your-openprop-server",
     "description": "Shown on openprop /agents/ page"
    }
   }
  }
 ],
 "security": [
  {
   "key": []
  }
 ],
 "components": {
  "securitySchemes": {
   "key": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "opk_..."
   }
  },
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "string"
     },
     "code": {
      "type": "string",
      "enum": [
       "bad_request",
       "unauthorized",
       "revoked",
       "forbidden_scope",
       "not_found",
       "rate_limited",
       "rejected",
       "duplicate",
       "engine",
       "engine_timeout",
       "gone",
       "method"
      ]
     },
     "hint": {
      "type": "string",
      "description": "One plain sentence on what to do next (when available)."
     }
    }
   },
   "Order": {
    "type": "object",
    "required": [
     "market",
     "side"
    ],
    "properties": {
     "market": {
      "type": "string",
      "example": "BTC"
     },
     "side": {
      "type": "string",
      "enum": [
       "buy",
       "sell"
      ],
      "description": "Hedge mode: buy opens/increases the long, sell opens/increases the short."
     },
     "type": {
      "type": "string",
      "enum": [
       "market",
       "limit",
       "stop",
       "stop_limit"
      ],
      "default": "market"
     },
     "size_usd": {
      "type": "number",
      "description": "Notional in USD (give size_usd OR size OR margin_usd + leverage)"
     },
     "size": {
      "type": "number",
      "description": "Size in coin"
     },
     "margin_usd": {
      "type": "number"
     },
     "leverage": {
      "type": "number",
      "description": "Checked against the account maximum (max position / size)"
     },
     "price": {
      "type": "number",
      "description": "Limit price (limit, stop_limit)"
     },
     "trigger_price": {
      "type": "number",
      "description": "Trigger (stop, stop_limit)"
     },
     "take_profit": {
      "type": "number"
     },
     "stop_loss": {
      "type": "number"
     },
     "reduce_only": {
      "type": "boolean"
     },
     "position": {
      "type": "string",
      "example": "BTC:long",
      "description": "With reduce_only: the position to reduce"
     },
     "client_order_id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_.:-]{1,48}$",
      "description": "Idempotency key. Same id on the same account = same answer, never a second order."
     }
    }
   }
  }
 },
 "paths": {
  "/v1/account": {
   "get": {
    "summary": "Account summary",
    "description": "Size, equity, balance, net P&L, floor, target, remaining loss before the floor, trader split.",
    "responses": {
     "200": {
      "description": "Account",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/rules_status": {
   "get": {
    "summary": "Rules status",
    "description": "remaining_loss_before_floor, remaining_to_target, max_position_usd, open_notional_usd, available_notional_usd per market, max_leverage. Call before every order.",
    "responses": {
     "200": {
      "description": "Rules status",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/evaluation": {
   "get": {
    "summary": "The rules this account was bought with",
    "responses": {
     "200": {
      "description": "Key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    },
    "description": "Size, risk level (tight/low/medium), max_loss_pct, profit_target_pct, floor, target, trader_split, price_paid (locked at purchase). Never changes for this account. Returns 404 until the server opens it (API_AGENTS_V2)."
   }
  },
  "/v1/pricing": {
   "get": {
    "summary": "Today's evaluation prices (read-only)",
    "responses": {
     "200": {
      "description": "Key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    },
    "description": "Live multiplier, displayed pass rate, price per size and split; per risk level when configurable evaluations are open. Prices are locked at purchase. Returns 404 until the server opens it."
   }
  },
  "/v1/positions": {
   "get": {
    "summary": "Open positions",
    "description": "Hedge mode: keys like BTC:long and BTC:short.",
    "responses": {
     "200": {
      "description": "Positions",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/orders": {
   "get": {
    "summary": "Open orders",
    "responses": {
     "200": {
      "description": "Orders",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   },
   "post": {
    "summary": "Place an order",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/Order"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Accepted; fills included when filled within ~1.5 s",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "Key without the trade scope",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "Refused by the trading engine or the rules (message explains why)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "client_order_id already in progress",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "504": {
      "description": "No answer from the engine: check /orders before retrying",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/orders/{order_id}/cancel": {
   "post": {
    "summary": "Cancel one order",
    "parameters": [
     {
      "name": "order_id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Cancelled",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "Key without the trade scope",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "Refused by the trading engine or the rules (message explains why)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "client_order_id already in progress",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "504": {
      "description": "No answer from the engine: check /orders before retrying",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/orders/cancel": {
   "post": {
    "summary": "Cancel one or all orders",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "order_id": {
          "type": "string",
          "description": "order id or 'all'"
         },
         "market": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Cancelled",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "Key without the trade scope",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "Refused by the trading engine or the rules (message explains why)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "client_order_id already in progress",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "504": {
      "description": "No answer from the engine: check /orders before retrying",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/positions/close": {
   "post": {
    "summary": "Close at market",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "position": {
          "type": "string",
          "example": "BTC:long"
         },
         "size": {
          "type": "number",
          "description": "Partial close (with position)"
         },
         "market": {
          "type": "string",
          "description": "'BTC' or 'all'"
         },
         "client_order_id": {
          "type": "string"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Closed",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "Key without the trade scope",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "Refused by the trading engine or the rules (message explains why)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "client_order_id already in progress",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "504": {
      "description": "No answer from the engine: check /orders before retrying",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/positions/tpsl": {
   "post": {
    "summary": "Set or clear TP/SL",
    "requestBody": {
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "position"
        ],
        "properties": {
         "position": {
          "type": "string"
         },
         "take_profit": {
          "type": [
           "number",
           "null"
          ]
         },
         "stop_loss": {
          "type": [
           "number",
           "null"
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "Key without the trade scope",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "Refused by the trading engine or the rules (message explains why)",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "client_order_id already in progress",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "504": {
      "description": "No answer from the engine: check /orders before retrying",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/markets": {
   "get": {
    "summary": "Markets and last prices",
    "responses": {
     "200": {
      "description": "Markets",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/history": {
   "get": {
    "summary": "Last 50 fills and events",
    "responses": {
     "200": {
      "description": "History",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/key": {
   "get": {
    "summary": "This key (scopes, account, last use)",
    "responses": {
     "200": {
      "description": "Key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/events": {
   "get": {
    "summary": "Events since a cursor (long-poll)",
    "description": "Returns fills and account events newer than `since` (ms). Keep the returned `cursor` and pass it back to resume after a restart. `wait` (0\u201312 s) holds the request until something happens.",
    "parameters": [
     {
      "name": "since",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "wait",
      "in": "query",
      "schema": {
       "type": "number",
       "maximum": 12
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Events + cursor",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/v1/events/stream": {
   "get": {
    "summary": "Server-sent events (direct API connection)",
    "description": "text/event-stream with `fill`, `event`, `rules_status` (every 10 s) and `revoked`. Each fill/event has `id: <ts>`; reconnect with Last-Event-ID to resume. Through the /pf-api relay use /v1/events (long-poll) instead.",
    "responses": {
     "200": {
      "description": "SSE stream",
      "content": {
       "text/event-stream": {}
      }
     },
     "400": {
      "description": "Invalid request",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "Missing, unknown or revoked key",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "Rate limited",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "error": {
           "type": "string"
          },
          "code": {
           "type": "string",
           "enum": [
            "bad_request",
            "unauthorized",
            "revoked",
            "forbidden_scope",
            "not_found",
            "rate_limited",
            "rejected",
            "duplicate",
            "engine",
            "engine_timeout",
            "gone",
            "method"
           ]
          }
         }
        }
       }
      }
     }
    }
   }
  },
  "/mcp": {
   "post": {
    "summary": "MCP server (streamable HTTP, JSON responses)",
    "description": "JSON-RPC 2.0. Tools: get_account, get_rules_status, get_positions, get_markets, get_history, place_order, close_position, cancel_order, set_tpsl. Auth by Bearer key (or ?key= for clients that cannot send headers).",
    "responses": {
     "200": {
      "description": "JSON-RPC response",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     }
    }
   }
  }
 }
}