> ## Documentation Index
> Fetch the complete documentation index at: https://docs.myfundedperpetuals.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reverse a position

> Flips the position to the other side in one market order: a long of size 1 becomes a short of size 1, and the reverse. The server sizes the order from the live position and opens the new side at the position's leverage and margin mode. When collateral cannot cover the full new side, the opening part is reduced to what it covers. Resting exits on the old position are canceled. A position that changes before the order is placed rejects with `position_changed`.



## OpenAPI

````yaml /openapi.yaml post /v1/positions/{position_id}/reverse
openapi: 3.1.0
info:
  title: MyFundedPerps API (Beta)
  version: 1.0.0
  description: >-
    The developer API is in beta. Breaking changes may be introduced at any
    time. Programmatic access to MyFundedPerps paper-trading challenge accounts.
    API trades use the same real order books and simulated execution engine as
    the web trading interface. Every response carries an `X-Request-Id` header
    for support and log correlation.
  contact:
    url: https://myfundedperpetuals.com/contact
servers:
  - url: https://developers.myfundedperpetuals.com
    description: Live
  - url: https://sandbox.myfundedperpetuals.com
    description: Sandbox (test keys and sandbox accounts only)
security:
  - bearerAuth: []
  - bearerAuth: []
    partnerKey: []
tags:
  - name: General
  - name: Authentication
  - name: Accounts
  - name: Markets
  - name: Positions
  - name: Orders
  - name: Fills
  - name: Strategy Orders
  - name: Trader Lockout
    description: >-
      Lock your own accounts out of trading until a time you choose, the same
      Trader Lockout as Settings > Trading on the website. A lockout cannot be
      ended or shortened early, by you or by Support, and there is no unlock
      endpoint: it ends only at `expires_at`. While it runs, new orders, order
      edits, cancels, manual closes, and exit-order changes on the account are
      rejected with `422 account_trader_lockout_active` and
      `error.details.expires_at`.
  - name: Price Alerts
  - name: Script Data
    description: >-
      Small text values your own Pine scripts read with `request.data("key")`,
      such as a daily options gamma histogram or call and put walls. Script data
      belongs to the key's owner, not an account, so any of your live keys
      reaches all of it, including keys limited to some accounts. Reading needs
      read or trade scope; creating, updating, and deleting need trade scope.
      Test keys can't use these endpoints. A script someone shares with you
      reads your own script data, never theirs. You can keep up to 20 keys, each
      holding up to 65,536 UTF-16 code units, and make up to 30 writes a minute
      and 1,440 a day. Charts showing a script that reads a key update within
      seconds of a write.
  - name: Affiliate
paths:
  /v1/positions/{position_id}/reverse:
    post:
      tags:
        - Positions
      summary: Reverse a position
      description: >-
        Flips the position to the other side in one market order: a long of size
        1 becomes a short of size 1, and the reverse. The server sizes the order
        from the live position and opens the new side at the position's leverage
        and margin mode. When collateral cannot cover the full new side, the
        opening part is reduced to what it covers. Resting exits on the old
        position are canceled. A position that changes before the order is
        placed rejects with `position_changed`.
      operationId: reversePosition
      parameters:
        - $ref: '#/components/parameters/PositionId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReversePositionRequest'
      responses:
        '200':
          description: Idempotent replay.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderEnvelope'
        '201':
          description: Reversal order accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrderEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          $ref: '#/components/responses/TradeRejected'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  parameters:
    PositionId:
      name: position_id
      in: path
      required: true
      schema:
        type: string
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: >-
        Unique printable key for this intended operation. Reuse it only for an
        identical retry.
      schema:
        type: string
        minLength: 1
        maxLength: 128
  schemas:
    ReversePositionRequest:
      type: object
      additionalProperties: false
      required:
        - expected_price
      properties:
        client_order_id:
          type: string
          minLength: 1
          maxLength: 128
          description: Optional caller-assigned identity for the resulting reversal order.
        expected_price:
          type: number
          exclusiveMinimum: 0
          description: >-
            Midpoint observed by the client. Server execution never trusts this
            value for pricing.
        slippage_tolerance_bps:
          type: number
          exclusiveMinimum: 0
    OrderEnvelope:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/Order'
        queued:
          type: boolean
    Order:
      type: object
      required:
        - id
        - account_id
        - market_id
        - provider
        - symbol
        - coin
        - type
        - mode
        - side
        - size
        - expected_price
        - leverage
        - margin_mode
        - reduce_only
        - status
        - requested_at
      properties:
        id:
          type: string
        client_order_id:
          type: string
          description: Caller-assigned order identity, when supplied at placement.
        account_id:
          type: string
        market_id:
          type: string
        provider:
          type: string
        symbol:
          type: string
        coin:
          type: string
        type:
          type: string
          enum:
            - market
            - limit
            - stop_market
            - stop_limit
            - take_market
            - take_limit
            - take_profit
            - liquidation
            - close_out
        mode:
          type: string
          enum:
            - market
            - limit
            - chase
            - stop_market
            - stop_limit
            - take_market
            - take_limit
            - take_profit
            - conditional
            - liquidation
            - close_out
        side:
          type: string
          enum:
            - buy
            - sell
        size:
          type: number
          description: >-
            This order's quantity in base-asset units. On a filled order it is
            the executed quantity of that fill. On a working order that has
            partially filled, it is the remaining quantity.
        initial_size:
          type: number
          description: >-
            Quantity originally requested when the order was placed. Read it
            with filled_size on the partial_fill_root_order_id order to track a
            partially filled placement's progress.
        filled_size:
          type: number
          description: >-
            Cumulative quantity filled by fragments split from this order, each
            of which appears as its own filled order with
            partial_fill_root_order_id set to this order. It stays 0 on an order
            that filled in one execution, so use size for a fill's executed
            quantity.
        expected_price:
          type: number
        fill_price:
          type: number
          description: On a filled order, the execution price of size.
        trigger_price:
          type: number
        limit_price:
          type: number
        notional:
          type: number
          description: On a filled order, size multiplied by fill_price, in USD.
        fee:
          type: number
          description: Trading fee charged for this fill, in USD.
        realized_pnl:
          type: number
          description: >-
            P&L realized by the portion of this fill that reduced or closed a
            position, in USD, before fee. 0 on a fill that only opened or
            increased a position.
        leverage:
          type: number
        margin_mode:
          type: string
          enum:
            - cross
            - isolated
        reduce_only:
          type: boolean
        time_in_force:
          type: string
          enum:
            - gtc
            - ioc
            - fok
            - gtd
        gtd_expires_at:
          type: number
        attached_take_profit_price:
          type: number
        attached_stop_loss_price:
          type: number
          description: >-
            On an entry with an attached stop-loss, its trigger price. For a
            trailing leg (attached_stop_loss_trail), only the estimate made at
            placement; the real trigger is set from the fill price.
        attached_stop_loss_trail:
          allOf:
            - $ref: '#/components/schemas/TrailDistance'
          description: >-
            On an entry with an attached trailing stop-loss, the trail distance
            the stop-loss leg will use once the entry fills.
        chase_offset:
          type: number
        chase_cap_price:
          type: number
        trail:
          allOf:
            - $ref: '#/components/schemas/TrailDistance'
          description: >-
            Present on a trailing stop. trigger_price is the stop's current
            level, which only moves toward the market as price moves in the
            position's favor.
        trail_extreme_price:
          type: number
          description: >-
            On a trailing stop, the best book midpoint the stop has trailed from
            (highest for a long, lowest for a short).
        trigger_market_id:
          type: string
        trigger_direction:
          type: string
          enum:
            - above
            - below
        triggered_at:
          type: number
          description: >-
            Millisecond timestamp of the most recent resting-to-pending
            execution attempt.
        stop_triggered_at:
          type: number
          description: >-
            Millisecond timestamp when a conditional limit entered its limit
            leg. Absent while its trigger is still armed; once present it
            remains set.
        cancel_requested_at:
          type: number
          description: >-
            Millisecond timestamp of cancellation intent. An in-flight execution
            may still fill before cancellation settles.
        oco_sibling_order_id:
          type: string
          description: >-
            Paired TP or SL order. Fills retire matching size from the sibling;
            explicitly canceling one leg unlinks the survivor.
        take_profit_order_id:
          type: string
          description: >-
            On an entry with an attached take-profit, the exit order its fill
            created.
        stop_loss_order_id:
          type: string
          description: >-
            On an entry with an attached stop-loss, the exit order its fill
            created.
        parent_order_id:
          type: string
          description: >-
            On an exit created by an entry's attached take-profit or stop-loss,
            the entry order that created it.
        bracket_role:
          type: string
          enum:
            - take_profit
            - stop_loss
          description: >-
            Which attached exit this order is. Present together with
            parent_order_id.
        target_position_id:
          type: string
        liquidity_role:
          type: string
          enum:
            - maker
            - taker
        partial_of_order_id:
          type: string
        partial_fill_root_order_id:
          type: string
        twap_order_id:
          type: string
        scaled_order_id:
          type: string
        status:
          type: string
          enum:
            - pending
            - filled
            - rejected
            - expired
            - resting
            - canceled
        reject_reason:
          type: string
        reject_rule_id:
          type: string
        reject_details:
          type: object
          description: >-
            Numeric details about why the order was rejected, with keys in
            snake_case. Available keys depend on the rejection reason.
          additionalProperties:
            type: number
          example:
            available_usd: 100
            required_usd: 200
        cancel_reason:
          type: string
          description: >-
            Why a canceled order was canceled: user, oco, reduce_only, replaced,
            liquidation, expired, account_closed, trading_restricted,
            venue_policy, or copy. New values may be added. Absent on orders
            canceled before this field was added.
        position_side_after:
          type: string
          enum:
            - long
            - short
            - flat
          description: >-
            On a filled order, the side of the account's position in this market
            after the fill.
        position_size_after:
          type: number
          description: >-
            On a filled order, the size of the account's position in this market
            after the fill, in base-asset units. 0 when flat.
        requested_at:
          type: number
        settled_at:
          type: number
        canceled_at:
          type: number
    ErrorEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/Error'
    TradeRejectionEnvelope:
      type: object
      required:
        - error
      properties:
        error:
          $ref: '#/components/schemas/TradeRejection'
    TrailDistance:
      type: object
      additionalProperties: false
      required:
        - unit
        - value
      description: >-
        Trailing stop distance. `price` trails by a fixed amount in the market's
        quote currency; `percent` trails by a percent of the best price, with at
        most two decimals (1.5 means 1.5%).
      properties:
        unit:
          type: string
          enum:
            - price
            - percent
        value:
          type: number
          exclusiveMinimum: 0
    Error:
      type: object
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
        message:
          type: string
        request_id:
          type: string
          format: uuid
        details:
          type: array
          description: >-
            Present on request-validation failures, with one entry per invalid
            field so a request can be fixed in one pass.
          items:
            $ref: '#/components/schemas/ValidationIssue'
    TradeRejection:
      allOf:
        - $ref: '#/components/schemas/ErrorBase'
        - type: object
          properties:
            order_id:
              type: string
            client_order_id:
              type: string
            rule_id:
              type: string
            details:
              type: object
              additionalProperties: true
    ValidationIssue:
      type: object
      required:
        - field
        - issue
      properties:
        field:
          type: string
          description: >-
            Wire name of the offending request field, such as `size` or
            `operations[2].price`. The value `body` refers to the whole payload.
        issue:
          type: string
    ErrorBase:
      type: object
      required:
        - code
        - message
        - request_id
      properties:
        code:
          type: string
        message:
          type: string
        request_id:
          type: string
          format: uuid
  responses:
    BadRequest:
      description: >-
        Invalid request. Validation failures list every offending field in
        `error.details`.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Unauthorized:
      description: Missing, invalid, or revoked API key, or an invalid partner key.
      headers:
        WWW-Authenticate:
          schema:
            type: string
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Forbidden:
      description: The API key is valid but does not allow this operation.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    NotFound:
      description: Resource not found or not owned by the authenticated user.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    Conflict:
      description: >-
        The request conflicts with current state, an idempotency record, or a
        client order ID.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
    TradeRejected:
      description: The trading engine rejected the requested operation.
      headers:
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/TradeRejectionEnvelope'
    RateLimited:
      description: >-
        The per-IP request limit, a per-key GET limit, a partner budget, or an
        account-wide operation budget is exhausted.
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Scope:
          $ref: '#/components/headers/RateLimitScope'
        X-Request-Id:
          $ref: '#/components/headers/RequestId'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
  headers:
    RequestId:
      description: Stable identifier for support and log correlation.
      schema:
        type: string
        format: uuid
    RetryAfter:
      description: Seconds to wait before retrying.
      schema:
        type: integer
        minimum: 1
    RateLimitLimit:
      description: >-
        Requests per minute allowed by the request budget that ran out. Sent on
        request-budget 429s; account-wide operation budget 429s omit it.
      schema:
        type: integer
        minimum: 1
    RateLimitScope:
      description: >-
        Which request budget ran out: `ip` for the per-address limit, `api_key`
        for a per-key budget (default per-key GET limit, custom key limit, or a
        partner's per-trader-key budget), or `partner` for a partner's combined
        budget. Sent on request-budget 429s; account-wide operation budget 429s
        omit it.
      schema:
        type: string
        enum:
          - ip
          - api_key
          - partner
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: MyFundedPerps API key
      description: >-
        API key beginning with `fp_live_` (live keys, served at
        developers.myfundedperpetuals.com) or `fp_test_` (test keys, served at
        sandbox.myfundedperpetuals.com). A key presented on the other host is
        rejected with `401` and a message naming the correct host. Affiliate API
        keys are `fp_live_` keys created on the Affiliates page: they read only
        the `/v1/affiliate` endpoints and get `403` with code
        `insufficient_scope` on every other authenticated endpoint. Every other
        key gets the same `403` on `/v1/affiliate`.
    partnerKey:
      type: apiKey
      in: header
      name: X-MFP-Partner-Key
      description: >-
        Optional partner key beginning with `mfp_partner_`, issued by
        MyFundedPerps to platforms that call the live API on behalf of many
        traders. Send it beside the trader's own `fp_live_` key: the request is
        then counted against the partner's budgets instead of the per-address
        limit. It grants no access on its own. An unknown, malformed, or revoked
        partner key returns `401` with code `invalid_partner_key`. The header is
        ignored on the sandbox host and on requests without a live trader key.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.