# Create Order — BitMEX

> Submit a new trading order in your BitMEX account. See the documentation

- Key: `bitmex-create-order`
- Type: Action (Write)
- Version: 0.0.2
- App: BitMEX (`bitmex`) — https://pipedream.com/apps/bitmex.md
- This page (HTML): https://pipedream.com/apps/bitmex/actions/create-order
- Hints: destructive
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/bitmex/actions/create-order/create-order.mjs

## Description

Submit a new trading order in your BitMEX account. [See the documentation](https://www.bitmex.com/api/explorer/#!/Order/Order_new)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `symbol` | `string` | Yes | Instrument symbol. Send a bare series (e.g. XBT) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. XBT:quarterly. Timeframes are nearest, daily, weekly, monthly, quarterly, biquarterly, and perpetual. Symbols are case-insensitive. Options are loaded from the connected account. |
| `strategy` | `string` | No | Order strategy. e.g. 'OneWay', 'Long', 'Short' |
| `side` | `string` | No | Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless orderQty is negative |
| `orderQty` | `integer` | No | Order quantity in units of the instrument (i.e. contracts, for spot it is base currency in minor currency for spot (e.g. XBt quantity for XBT)) |
| `price` | `string` | No | Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders |
| `displayQty` | `integer` | No | Optional quantity to display in the book. Use 0 for a fully hidden order. |
| `stopPx` | `string` | No | Optional trigger price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. Use a price below the current price for stop-sell orders and buy-if-touched orders. Use execInst of 'MarkPrice' or 'LastPrice' to define the current price used for triggering. |
| `clOrdID` | `string` | No | Optional Client Order ID. This clOrdID will come back on the order and any related executions. |
| `clOrdLinkID` | `string` | No | Optional Client Order Link ID for contingent orders |
| `pegOffsetValue` | `string` | No | Optional trailing offset from the current price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders; use a negative offset for stop-sell orders and buy-if-touched orders. Optional offset from the peg price for 'Pegged' orders. |
| `pegPriceType` | `string` | No | Optional peg price type. Valid options: MarketPeg, PrimaryPeg, TrailingStopPeg |
| `ordType` | `string` | No | Order type. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, Pegged. Defaults to 'Limit' when price is specified. Defaults to 'Stop' when stopPx is specified. Defaults to 'StopLimit' when price and stopPx are specified. |
| `timeInForce` | `string` | No | Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. |
| `execInst` | `string` | No | Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed, LastWithinMark. 'AllOrNone' instruction requires displayQty to be 0. 'MarkPrice', 'IndexPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. 'LastWithinMark' instruction valid for 'Stop' and 'StopLimit' with instruction 'LastPrice'. IndexPrice, LastWithMark, Close and ReduceOnly are not applicable to spot trading symbols. |
| `contingencyType` | `string` | No | Optional contingency type for use with clOrdLinkID. Valid options: OneCancelsTheOther, OneTriggersTheOther. |
| `text` | `string` | No | Optional order annotation. e.g. 'Take profit' |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "bitmex",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "bitmex-create-order",
  arguments: {
    symbol: "Symbol",
    strategy: "Strategy",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "bitmex-create-order",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    bitmex: { authProvisionId: "apn_xxxxxxx" },
    symbol: "Symbol",
    strategy: "Strategy",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "bitmex-create-order",
    "configured_props": {
      "bitmex": { "authProvisionId": "apn_xxxxxxx" },
      "symbol": "Symbol",
      "strategy": "Strategy"
    }
  }'
```

---

- App: https://pipedream.com/apps/bitmex.md · All apps: https://pipedream.com/apps
