PhoenixPerpetualsDocs API v1
Get an API key

API reference ยท Orders

POST/v1/accounts/{account_id}/orders/test

Preview an order⁠.

Read

What an order would do now, sent nowhere: whether it would fill, rest or be refused (and why), its price, fee, margin, the position after it and the room under the exposure cap. Any key may call it.

Path parameters#

Request body#

  • marketstringrequired

    A market id: the asset and USD; an option adds its venue or hours after a dot.

  • sidestringrequired

    The order's side.

    One ofbuysell

  • typestringrequired

    market: now, at the best price within your worst price. limit: at your price or better. stop_market: a market order once the last price reaches the stop. stop_limit: a limit once the last price reaches the stop.

    One ofmarketlimitstop_marketstop_limit

  • sizedecimal string

    The size, in the base asset: a multiple of the market's size step. Give size or notional_usd.

  • notional_usddecimal string

    The size as a value in USD, rounded down to the size step.

  • limit_pricedecimal string

    The limit price (limit and stop_limit): a multiple of the tick size.

  • stop_pricedecimal string

    The trigger price (stop_market and stop_limit).

  • worst_pricedecimal string

    Market orders: the worst price you accept. Give worst_price or max_slippage_pct.

  • max_slippage_pctdecimal string

    Market orders: how far from the best price you accept, in percent (the default and bounds are in GET /v1/markets).

  • It may only reduce or close your position, never open or add to one.

  • post_onlyboolean

    Limit orders: refused if it would fill at once.

  • gtc: until canceled. gtd: until expires_at. ioc and fok: fill now or end (a fill is always the whole order). Default: ioc for market orders, gtc otherwise.

    One ofgtcgtdiocfok

  • expires_atinteger, Unix ms

    With gtd: when it ends, from orders.gtd_min_seconds to orders.gtd_max_days ahead (GET /v1/limits).

  • Your own id for the order: unique in this environment, 1 to 64 letters, digits and . _ : -

  • exitsOrderExits

    Exits placed when the order fills: the stop-loss for the filled size first, then the take-profits. From then on they are the position's exits. An empty object removes them.

    Show 2 fields
    • take_profitarray of object

      Limit orders on the profit side, each at price, or at distance or percent from the fill.

      Show 4 fields
      • pricedecimal string

        An exact price.

      • distancedecimal string

        A price difference from the fill price.

      • percentdecimal string

        A percent of the fill price.

      • size_pctdecimal string

        Its share of the filled size, in percent (absent: the take-profits split it evenly).

    • stop_lossobject or null

      A stop on the loss side, at price, or at distance or percent from the fill; it may trail and move to break-even (as in a position's exits).

      Show 7 fields
      • pricedecimal string

        An exact price.

      • distancedecimal string

        A price difference from the fill price.

      • percentdecimal string

        A percent of the fill price.

      • typestring

        The stop's type (default stop_market).

        One ofstop_marketstop_limit

      • stop_limit: how many ticks past the stop its limit sits.

      • trailobject

        As a position's exits take it: { distance } or { percent }, with activation_price to start only once the price reaches it.

        Show 3 fields
        • distancedecimal string

          How far behind the best price.

        • percentdecimal string

          How far behind, in percent of the best price.

        • activation_pricedecimal string

          Start once the price reaches this.

      • As a position's exits take it: one of trigger_distance, trigger_percent, trigger_price, and offset_ticks.

        Show 4 fields

Responses#

200OK
  • resultstringrequired

    What the order would do now: fill at once, rest, or be refused (reject says why).

    One ofwould_fillwould_restwould_reject

  • rejectobject or nullrequired
    Show 3 fields
    • codestringrequired

      The error code it would get.

    • messagestring or nullrequired

      What it means.

    • detailsobject

      More about it.

  • marketstringrequired

    A market id: the asset and USD; an option adds its venue or hours after a dot.

  • sidestringrequired

    The order's side.

    One ofbuysell

  • typestringrequired

    The order's type.

    One ofmarketlimitstop_marketstop_limit

  • sizedecimal string or nullrequired

    Its size (after a notional_usd is rounded to the size step).

  • executionobject or nullrequired
    Show 3 fields
    • marketablebooleanrequired

      It would fill at once.

    • expected_pricedecimal stringrequired

      The price it would fill at (at once) or rest at.

    • worst_pricedecimal string or nullrequired

      A market order's worst price.

  • notionaldecimal string or nullrequired

    Its value in USD.

  • feedecimal string or nullrequired

    The fee its fill would pay.

  • marginobject or nullrequired
    Show 5 fields
    • modestringrequired

      The margin mode the position would use.

      One ofisolatedcross

    • leverageintegerrequired

      The leverage it would use.

    • requireddecimal stringrequired

      The margin the order needs.

    • available_beforedecimal string or nullrequired

      The margin available now.

    • available_afterdecimal string or nullrequired

      What would remain available.

  • position_afterobject or nullrequired
    Show 3 fields
    • sizedecimal stringrequired

      The position's size after the fill.

    • sidestring or nullrequired

      Its side; null when flat.

      One oflongshort

    • average_pricedecimal string or nullrequired

      Its average price.

  • exposureobject or nullrequired
    Show 3 fields
    • capdecimal stringrequired

      The market's exposure cap across your accounts of this product.

    • open_beforedecimal stringrequired

      Your open value on the market now.

    • room_afterdecimal stringrequired

      What would remain under the cap.

400The request is malformed.
{
  "error": {
    "type": "invalid_request",
    "code": "invalid_request",
    "message": "The request is not valid.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#invalid_request"
  }
}
401The request has no Authorization header.
{
  "error": {
    "type": "authentication",
    "code": "missing_api_key",
    "message": "No API key: send it as Authorization: Bearer <key>.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#missing_api_key"
  }
}
403The key only works from the addresses you listed.
{
  "error": {
    "type": "permission",
    "code": "ip_not_allowed",
    "message": "This address is not on the key's allowlist.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#ip_not_allowed"
  }
}
404The account does not exist in this environment, or the key does not reach it.
{
  "error": {
    "type": "not_found",
    "code": "account_not_found",
    "message": "No account with that id is reachable with this key.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#account_not_found"
  }
}
405The path exists, with other methods (see the Allow header).
{
  "error": {
    "type": "method",
    "code": "method_not_allowed",
    "message": "This route does not take that method.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#method_not_allowed"
  }
}
409The account exists but is not open on the trading engine yet.
{
  "error": {
    "type": "conflict",
    "code": "account_not_ready",
    "message": "This account is still being opened.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": true,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#account_not_ready"
  }
}
413The body is over the size limit.
{
  "error": {
    "type": "payload",
    "code": "payload_too_large",
    "message": "The body is too large.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#payload_too_large"
  }
}
414The URL is over the length limit.
{
  "error": {
    "type": "payload",
    "code": "uri_too_long",
    "message": "The address is too long.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#uri_too_long"
  }
}
415A body was sent without Content-Type: application/json.
{
  "error": {
    "type": "payload",
    "code": "unsupported_media_type",
    "message": "The body must be JSON.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": false,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#unsupported_media_type"
  }
}
429A request budget is used up (details.scope says which).
{
  "error": {
    "type": "rate_limit",
    "code": "rate_limited",
    "message": "Too many requests: slow down.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": true,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#rate_limited"
  }
}
500An error we did not expect.
{
  "error": {
    "type": "server",
    "code": "internal_error",
    "message": "Something went wrong on our side.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": true,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#internal_error"
  }
}
503A service this call needs did not answer.
{
  "error": {
    "type": "server",
    "code": "temporarily_unavailable",
    "message": "This cannot be done right now. Try again in a moment.",
    "request_id": "req_0f9c2a7d8e1b4c6a9f3e5d7b1a2c4e6f",
    "retryable": true,
    "doc_url": "https://docs.phoenixperpsfunding.com/reference/errors#temporarily_unavailable"
  }
}

Errors#

Codes this endpoint can return. Match on the code, never on the message.

Guides, endpoints, fields and error codes.