Create order

This page will help you get started with sending create order requests through websocket connection

Channel: orders

Before creating orders to this channel, authentication is required.

The payload is identical to that used in POST /orders REST API

Notes:

  • request_id: an optional string that the Server will send back to the client in cases there is error.

  • Server only sends error message if the order cannot be created (by any error)

    • This error message only be sent exclusively though the same WebSocket connection which receives the create message
  • Server does not send a response upon a successful order submission

    • Instead, client must subscribe (sub) to orders channel to see if identify when the order is successfully placed (using order's nonce) because the update message from orders channel is always come first.
    • All clients subscribe to the orders channel will see the order created message.
  • Client might send many create messages to create multiple orders, however the ordering of created orders are not guarantee. Example:

    • Client send create order X, Y, Z
    • Y can be created first, then X is created, Z cannot be created (for some reason)
    • Client will see the message Y is created first, then X is created

// Request
{
  "op": "create_order",
  "request_id": "your-unique-id-here", // optional, should be less than 36 characters (enough for an uuid
  "channel": "orders",
  "data": {
    "side": "BUY",
    "type": "LIMIT",
    "time_in_force": "GTC",
    "product_index": 2,
    "price": "2394.8",
    "size": "0.51",
    "nonce": "1740589329415243076", // this nonce can be used to detect successful order creatation
    "post_only": false,
    "reduce_only": false,
    "signature": "0x12345678"
  }
}
// example of order created message 
// note that this response ONLY be sent when you already "sub" to orders channel before
{
  "channel": "orders",
  "type": "update",
  "data": [
    {
      "avg_price": "0",
      "cancel_reason": "",
      "cancel_reject_reason": "",
      "cancel_requested": false,
      "cancel_requested_at": "0",
      "client_order_id": "",
      "created_at_ts": "1740589955539636000",
      "expired_at": "0",
      "filled_fees": "0",
      "filled_size": "0",
      "id": "4838b931-ddb7-4b8d-be22-bbe2f5b9935a",
      "initial_margin": "6.0064766903749975",
      "is_liquidation": false,
      "last_trades": [],
      "liquidation_fee_rate": "0",
      "maker_fee_rate": "0.0002",
      "nonce": "1740589955129439587",
      "order_stop_type": "STOP_NONE",
      "post_only": false,
      "price": "2399.2",
      "product_id": "ETH-PERP",
      "reduce_only": false,
      "reject_reason": "",
      "scheduled_at": "0",
      "sender": "0xa01f2319baf9e8a344486ebafa96fb3c9f5bda05",
      "side": "BUY",
      "size": "0.05",
      "status": "PENDING", // PENDING is the status of just created order
      "stop_price": "0",
      "stop_price_option": "NONE",
      "stp": "CANCEL_TAKER",
      "taker_fee_rate": "0.0004",
      "time_in_force": "GTC",
      "type": "LIMIT",
      "updated_at": "1740589955539636000"
    }
  ],
  "timestamp": "1740589955539636000"
}
// return when any error happens
{
  "channel": "orders",
  "type": "error",
  "message": "not authenticated",
  "code": 401, // same code with rest api
  "request_id": "your-unique-id-here",
  "payload": { // payload is echo back to client for detect the failed order, or client can use request_id
    "side": "BUY",
    "type": "LIMIT",
    "time_in_force": "GTC",
    "product_index": 2,
    "price": "2394.8",
    "size": "0.51",
    "nonce": "1740589329415243076",
    "post_only": false,
    "reduce_only": false,
    "signature": "0x12345678"
  }
}

📘

Orders

Check out Get an order response for the order struct returned from this endpoint and Matching Engine for what various order statuses mean.