# Place Order — Alpaca

> Places a new order for the given account. An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order, See the docs

- Key: `alpaca-place-order`
- Type: Action (Write)
- Version: 0.1.2
- App: Alpaca (`alpaca`) — https://pipedream.com/apps/alpaca.md
- This page (HTML): https://pipedream.com/apps/alpaca/actions/place-order
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/alpaca/actions/place-order/place-order.mjs

## Description

Places a new order for the given account. An order request may be rejected if the account is not authorized for trading, or if the tradable balance is insufficient to fill the order, [See the docs](https://alpaca.markets/docs/api-references/trading-api/orders/#request-a-new-order)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `isPaperAPI` | `boolean` | No | Set to true if Paper API is used. Default is false. |
| `symbol` | `string` | Yes | Symbol, asset ID, or currency pair to identify the asset to trade (ex. AAPL, BTC/USD). |
| `qty` | `string` | No | Number of shares to trade. Can be fractionable for only market and day order types. |
| `notional` | `string` | No | Dollar amount to trade. Cannot work with Qty. Can only work for market order types and day for time in force. |
| `side` | `string` | Yes | buy or sell |
| `type` | `string` | Yes | Type |
| `timeInForce` | `string` | Yes | Please see this doc for more info on what values are possible for what kind of orders. |
| `limitPrice` | `string` | No | Required if type is limit or stop_limit |
| `stopPrice` | `string` | No | Required if type is stop or stop_limit |
| `trailPrice` | `string` | No | This or trail_percent is required if type is trailing_stop |
| `trailPercent` | `string` | No | This or trail_price is required if type is trailing_stop |
| `extendedHours` | `boolean` | No | If true, order will be eligible to execute in premarket/afterhours. Only works with Type Limit and Time in Force Day. |

## 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": "alpaca",
      },
    },
  },
)

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: "alpaca-place-order",
  arguments: {
    isPaperAPI: true,
    symbol: "Symbol",
  },
})
```

**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: "alpaca-place-order",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    alpaca: { authProvisionId: "apn_xxxxxxx" },
    isPaperAPI: true,
    symbol: "Symbol",
  },
})

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": "alpaca-place-order",
    "configured_props": {
      "alpaca": { "authProvisionId": "apn_xxxxxxx" },
      "isPaperAPI": true,
      "symbol": "Symbol"
    }
  }'
```

---

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