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

# Set Phoenix TP/SL

> Requires key scope `phoenix/tpsl`.

Returns an unsigned v0 transaction for the manager to sign. Do not send `payer`: the API sets it to the key's manager and rejects a body that contains it. Unknown fields are ignored. The key's manager must be the vault's current on-chain authority or a live delegate of it, and the vault must be in the key's allowlist when the key has one. A delegate needs the Phoenix permission.

Makes the market's take-profit and stop-loss bracket on the vault's whole open position exactly what the body says. The build cancels every armed TP/SL of the market, then places the new one, so a retry converges. The first TP/SL also creates the trader's conditional-orders account in the same transaction. Both `null` removes the bracket. The trigger fills as a market order with 2% slippage. Returns 400 for an unknown market, when placing without an open position, when removing with nothing armed, or when a price is below one tick or on the wrong side of the mark.



## OpenAPI

````yaml /api-reference/openapi.json post /transactions/phoenix/tpsl
openapi: 3.1.0
info:
  title: Hedgin manager bot API
  version: 1.0.0
  description: >-
    Versioned HTTP API for approved manager bots. Reads vault state and builds
    unsigned Solana transactions. The bot signs locally with the vault's current
    authority key. Runs only on Solana mainnet-beta. Send `User-Agent:
    <client>/<version>`; the official SDK sends `hedginxyz-sdk/<version>`, which
    Hedgin records per key. Every response carries `x-hedge-sdk-latest`, the
    newest published `@hedginxyz/sdk` version.
servers:
  - url: https://hedgin.xyz/api/external/v1
    description: Production (Solana mainnet-beta)
security:
  - bearerAuth: []
tags:
  - name: Vault reads
  - name: Market reads
  - name: Jupiter transactions
  - name: Meteora DLMM transactions
  - name: Phoenix transactions
  - name: Vault and strategy transactions
  - name: Child vault transactions
  - name: Send and status
paths:
  /transactions/phoenix/tpsl:
    post:
      tags:
        - Phoenix transactions
      summary: Set Phoenix TP/SL
      description: >-
        Requires key scope `phoenix/tpsl`.


        Returns an unsigned v0 transaction for the manager to sign. Do not send
        `payer`: the API sets it to the key's manager and rejects a body that
        contains it. Unknown fields are ignored. The key's manager must be the
        vault's current on-chain authority or a live delegate of it, and the
        vault must be in the key's allowlist when the key has one. A delegate
        needs the Phoenix permission.


        Makes the market's take-profit and stop-loss bracket on the vault's
        whole open position exactly what the body says. The build cancels every
        armed TP/SL of the market, then places the new one, so a retry
        converges. The first TP/SL also creates the trader's conditional-orders
        account in the same transaction. Both `null` removes the bracket. The
        trigger fills as a market order with 2% slippage. Returns 400 for an
        unknown market, when placing without an open position, when removing
        with nothing armed, or when a price is below one tick or on the wrong
        side of the mark.
      operationId: build_phoenix_tpsl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - vault
                - symbol
                - takeProfit
                - stopLoss
              properties:
                vault:
                  $ref: '#/components/schemas/PublicKey'
                  description: Vault the transaction acts on.
                symbol:
                  type: string
                  minLength: 1
                  maxLength: 32
                  description: Market symbol from `GET /vaults/{vault}/phoenix`.
                takeProfit:
                  oneOf:
                    - $ref: '#/components/schemas/DecimalString'
                    - type: 'null'
                  description: >-
                    USD per whole asset unit. `null` removes this leg. Must be
                    above the mark price for a long's take profit or a short's
                    stop loss, and below it for the other two.
                stopLoss:
                  oneOf:
                    - $ref: '#/components/schemas/DecimalString'
                    - type: 'null'
                  description: >-
                    USD per whole asset unit. `null` removes this leg. Must be
                    above the mark price for a long's take profit or a short's
                    stop loss, and below it for the other two.
            example:
              vault: 7Np41oeYqPefeNQEHSv1UDhYrehxin3NStELsSKCT4K2
              symbol: SOL
              takeProfit: '250'
              stopLoss: '150'
      responses:
        '200':
          description: Build result. One step.
          content:
            application/json:
              schema:
                type: object
                required:
                  - vault
                  - result
                properties:
                  vault:
                    $ref: '#/components/schemas/PublicKey'
                  result:
                    $ref: '#/components/schemas/BuiltStep'
          headers:
            x-hedge-sdk-latest:
              $ref: '#/components/headers/XHedgeSdkLatest'
        '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'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '422':
          $ref: '#/components/responses/Unprocessable'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalError'
        '502':
          $ref: '#/components/responses/BadGateway'
        '503':
          $ref: '#/components/responses/ServiceUnavailable'
components:
  schemas:
    PublicKey:
      type: string
      description: >-
        Base58 Solana public key. The server decodes it and rejects anything
        that is not 32 bytes.
      pattern: ^[1-9A-HJ-NP-Za-km-z]{32,44}$
      example: So11111111111111111111111111111111111111112
    DecimalString:
      type: string
      description: >-
        Non-negative decimal in whole units: up to 15 integer digits and up to
        12 fractional digits.
      pattern: ^\d{1,15}(\.\d{1,12})?$
      example: '0.5'
    BuiltStep:
      type: object
      description: >-
        One unsigned transaction and its ticket. Builders can add action
        metadata fields next to these.
      required:
        - transaction
        - simulation
        - ticket
        - blockhash
      properties:
        transaction:
          type: string
          format: byte
          description: >-
            Unsigned Solana v0 transaction, base64. At most 1232 bytes decoded.
            The fee payer is the key's manager. Builder-added signatures, such
            as a new position keypair, are already present.
        simulation:
          $ref: '#/components/schemas/Simulation'
        ticket:
          type: string
          description: >-
            Signed build ticket. Expires 90 seconds after the build. Binds the
            exact message, key, manager, vault, action, cluster, and program.
        blockhash:
          type: string
          description: Recent blockhash in the transaction message.
        sendConcurrently:
          type: boolean
          description: >-
            Consecutive steps with `sendConcurrently: true` may be submitted
            together. A step without it is a confirmation barrier.
        next:
          $ref: '#/components/schemas/NextStep'
      additionalProperties: true
    Simulation:
      type: object
      required:
        - unitsConsumed
      properties:
        unitsConsumed:
          type: integer
          description: >-
            Compute units the build-time simulation used. `0` when simulation
            was deferred.
        deferred:
          type: boolean
          description: >-
            `true` when the step depends on an earlier step in the same batch.
            RPC preflight checks it at send time instead.
    NextStep:
      type: object
      description: >-
        A follow-up build. After this step confirms, call `POST
        /transactions/{path}` with `body` unchanged. `body` never contains
        `payer`.
      required:
        - path
        - body
      properties:
        path:
          type: string
          description: Builder action name, such as `jupiter/sweep` or `dlmm/add-range`.
          example: jupiter/sweep
        body:
          type: object
          additionalProperties: true
          description: Request body for the follow-up build.
    Error:
      type: object
      description: >-
        Every error response uses this envelope. Responses with status 500, 502,
        or 503 always carry the message `Service temporarily unavailable`.
        Responses with status 422 always carry the message `Transaction rejected
        during simulation or preflight`. In both cases `code` still names the
        cause.
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: >-
                Stable machine-readable code, such as `Validation`, `Forbidden`,
                or a decoded program error name.
              example: Validation
            message:
              type: string
              description: Human-readable detail. Never contains provider logs.
              example: vault must be a public key
  headers:
    XHedgeSdkLatest:
      description: >-
        Newest published `@hedginxyz/sdk` version. SDK 0.5.0 and later print one
        warning per client when this is newer than the installed version.
      schema:
        type: string
        pattern: ^\d+\.\d+\.\d+$
        examples:
          - 0.5.0
  responses:
    BadRequest:
      description: >-
        Invalid path, query, or body. Builder messages name the field, such as
        `amount: must be a non-negative integer string`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: Validation
              message: vault must be a public key
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    Unauthorized:
      description: Missing, malformed, unknown, revoked, or expired API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: Unauthorized
              message: Invalid API key
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    Forbidden:
      description: >-
        The key lacks the required scope, the vault is outside the key's
        allowlist, or the key's manager is not the vault's current on-chain
        authority.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: Forbidden
              message: Action is not enabled for this key
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    NotFound:
      description: Unknown route, or the vault, mint, pool, or strategy does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: NotFound
              message: Vault not found
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    Conflict:
      description: >-
        Chain state conflicts with the request. Read current state before you
        build again.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: Stale
              message: pool price moved; refresh before flipping
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    PayloadTooLarge:
      description: Request body larger than 16,384 bytes.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: BodyTooLarge
              message: Request body is too large
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    Unprocessable:
      description: >-
        Simulation or RPC preflight rejected the transaction, or it does not fit
        in Solana transactions. `code` is the decoded program error name when
        one exists.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: SlippageToleranceExceeded
              message: Transaction rejected during simulation or preflight
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    TooManyRequests:
      description: A rate limit is exhausted.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: RateLimited
              message: Too many requests, slow down
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    InternalError:
      description: >-
        Internal error, including a builder that returned an invalid transaction
        (`BuildFailed`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: Internal
              message: Service temporarily unavailable
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    BadGateway:
      description: An upstream provider (Jupiter, Meteora, or Phoenix) failed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: JupiterQuoteFailed
              message: Service temporarily unavailable
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
    ServiceUnavailable:
      description: RPC, key store, or service configuration unavailable.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: RpcUnavailable
              message: Service temporarily unavailable
      headers:
        x-hedge-sdk-latest:
          $ref: '#/components/headers/XHedgeSdkLatest'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: hv1_<id>_<secret>
      description: >-
        API key issued by a Hedgin administrator, in the form
        `hv1_<id>_<secret>`. `<id>` is 1 to 48 characters and `<secret>` is 32
        to 128 characters, both from `[A-Za-z0-9_-]`.

````

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