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

# Post apiv1positions tp sl



## OpenAPI

````yaml /proto-openapi/api/openapi.yaml post /api/v1/positions/{positionId}/tp-sl
openapi: 3.0.3
info:
  title: Monaco Protocol API
  description: REST API for the Monaco Protocol hybrid CLOB exchange.
  version: 1.0.0
servers:
  - url: https://staging.apimonaco.xyz
    description: Staging server (Testnet)
security: []
tags:
  - name: AccountsService
  - name: ApplicationsService
  - name: AuthService
  - name: BuildercodeRewardsService
  - name: CopyTradingService
  - name: DelegatedAgentsService
  - name: FaucetService
  - name: FeesService
  - name: HealthService
  - name: ManagedMarketsService
    description: |-
      Wallet-authenticated maker assignments. The signed session must match both
       configured maker user and application. Owner IDs are process fences, never auth.
       Only wallet sessions are supported; delegated-agent sessions receive 403.
  - name: MarginAccountsService
    description: |-
      Current public isolated-margin semantics:
       - a user has one parent margin account per application scope
       - opening orders create or reuse isolated position buckets under that parent
       - parent account creation is handled internally by margin workflows
  - name: MarketService
  - name: OrderbookService
  - name: OrdersService
  - name: PositionsService
    description: |-
      Current public isolated-margin semantics:
       - positions link to a parent margin account and, when applicable, a bucket id
       - opening orders create or reuse isolated position buckets under the parent
       - users can open another isolated position by reusing the parent account with a different market bucket
  - name: PulseService
  - name: SweeperService
  - name: TraderCodeService
  - name: TradesService
  - name: WhitelistService
  - name: WithdrawalsService
paths:
  /api/v1/positions/{positionId}/tp-sl:
    post:
      tags:
        - PositionsService
      operationId: attach_position_tp_sl
      parameters:
        - name: positionId
          in: path
          required: true
          schema:
            type: string
            default: 2b1a5f9c-0000-4000-8000-000000000002
          example: 2b1a5f9c-0000-4000-8000-000000000002
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AttachPositionTpSlRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachPositionTpSlResponse'
        '429':
          description: >-
            Order rate limit exceeded — each attach draws one item from the
            per-account order-creation budget it shares with order creates (and
            the budget the account family shares); retry after the interval in
            details.retryAfter
      security:
        - monacoSignature: []
        - monacoHttpSignature: []
components:
  schemas:
    AttachPositionTpSlRequest:
      type: object
      properties:
        trailingStop:
          allOf:
            - $ref: '#/components/schemas/TrailingStopLeg'
          description: >-
            Trailing stop (0XM-2827). May be attached alone or alongside
            take_profit /
             stop_loss; it never takes part in oco and coexists with fixed legs.
          nullable: true
        takeProfit:
          $ref: '#/components/schemas/TpSlLeg'
        stopLoss:
          $ref: '#/components/schemas/TpSlLeg'
        oco:
          type: boolean
          description: >-
            One-cancels-the-other. Defaults to false. When true, both
            take_profit and
             stop_loss are required and the sibling is cancelled after either triggers.
          nullable: true
    AttachPositionTpSlResponse:
      type: object
      properties:
        positionId:
          type: string
          nullable: true
        takeProfitOrderId:
          type: string
          nullable: true
        stopLossOrderId:
          type: string
          nullable: true
        status:
          type: string
          nullable: true
        message:
          type: string
          nullable: true
        trailingStopOrderId:
          type: string
          nullable: true
    TrailingStopLeg:
      type: object
      properties:
        trailBps:
          type: integer
          description: Retracement in basis points, integer, 10 to 2000 inclusive.
          format: int32
          nullable: true
        activationPrice:
          type: string
          description: |-
            Optional mark level that starts tracking. Omitted: tracking starts
             immediately at the current mark. Present: rejected if the mark has
             already reached it; once reached, the watermark seeds at this level.
          nullable: true
        quantity:
          type: string
          description: >-
            Deliberate partial size; mutually exclusive with close_position.
            Omit both
             to close the full live position at trigger time. Same contract as TpSlLeg.
          nullable: true
        closePosition:
          type: boolean
          nullable: true
        slippageToleranceBps:
          type: integer
          description: >-
            Slippage cap for the triggered MARKET close, 0 to 10000 bps (TP/SL
            parity).
          format: int32
          nullable: true
        expiresAt:
          type: string
          nullable: true
      description: >-
        Trailing stop leg (0XM-2827). Reduce-only MARKET close whose trigger
        trails
         the best mark price reached since it armed (the "watermark") by `trail_bps`:
         for a long, trigger = watermark x (1 - trail_bps/10000) and fires when mark
         falls to or below it; for a short, trigger = watermark x (1 + trail_bps/10000)
         and fires when mark rises to or above it. The trigger only ever moves in the
         position's favour. One trailing stop per position; a second attach is
         rejected with a conflict, never a replace. Fires through the same market
         close path as a TP/SL (1,200 bps protective band, optional slippage cap).
    TpSlLeg:
      type: object
      properties:
        triggerPrice:
          type: string
          nullable: true
        orderType:
          type: string
          nullable: true
        limitPrice:
          type: string
          nullable: true
        quantity:
          type: string
          nullable: true
        timeInForce:
          type: string
          nullable: true
        slippageToleranceBps:
          type: integer
          format: int32
          nullable: true
        expiresAt:
          type: string
          nullable: true
        closePosition:
          type: boolean
          description: >-
            Resolve the full live position size when triggered. Mutually
            exclusive
             with quantity. For compatibility, omitting both quantity and this field
             also means full-position close.

             Attaching a full-close leg to a position SUPERSEDES that position's
             previously active full-close legs of the same condition type: they are
             cancelled in the same engine step that creates the replacement, so moving
             a take-profit or stop-loss is one call with no window in which the
             position holds both levels or neither. Fixed-quantity legs never
             participate — laddered partial exits stack — and a superseded leg's
             OCO sibling is left active rather than dropped. An entry order's
             full-close legs compete for the same slot once armed: the leg set most
             recently wins. So an attach retires an armed entry-order leg, leaves one
             still pending on an unfilled order alone, and when that order fills its
             leg is cancelled instead of armed if this attach came later.
          nullable: true
  securitySchemes:
    monacoSignature:
      type: apiKey
      description: >-
        Ed25519 session-key request signing. Every authenticated request carries
        three headers: `X-Monaco-PublicKey` (64-char lowercase-hex session
        public key), `X-Monaco-Timestamp` (Unix milliseconds, within 30s of
        server time), and `X-Monaco-Signature` (hex ed25519 signature). The
        signature is over `METHOD\npath?query\ntimestamp_ms\nSHA256_hex(body)`,
        where the body hash is the SHA-256 of the empty byte string when there
        is no body. Obtain the session keypair from `POST
        /api/v1/auth/challenge` followed by `POST /api/v1/auth/verify`.
      name: X-Monaco-Signature
      in: header
    monacoHttpSignature:
      type: apiKey
      description: >-
        RFC 9421 Ed25519 session-key request signatures. Send Signature-Input,
        Signature, and Content-Digest together; never combine them with
        X-Monaco-* credentials. The monaco signature covers @method, @path,
        @query, and content-digest in that order, with created (Unix seconds
        within 30s of server time), keyid (registered lowercase-hex session
        public key), and alg=ed25519 parameters. Content-Digest uses RFC 9530
        sha-256 over the exact body bytes, including the empty body. Query
        coverage retains ordering and percent encoding. Timestamp freshness does
        not reject repeated identical requests; use endpoint idempotency where
        supported. Existing legacy signing remains supported during server-first
        migration; SDK RFC 9421 signing is opt-in. See
        https://docs.0xmonaco.com/reference/http-message-signatures for the
        complete profile and trust model.
      name: Signature
      in: header

````

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