# Alpaca — Pipedream Connect

> Commission-Free API First Stock Brokerage

- API slug: `alpaca` (use in MCP headers and tool keys)
- Auth: OAuth (Pipedream-managed)
- Categories: Web & App Development
- Website: https://alpaca.markets/
- Managed OAuth scopes: `account:write` · `trading` · `data`
- This page (HTML): https://pipedream.com/apps/alpaca
- Tools: 8 actions · 0 triggers

## Connect via MCP (recommended)

- Endpoint: `https://remote.mcp.pipedream.net/v3`
- Headers: `Authorization: Bearer <token>` · `x-pd-project-id` · `x-pd-environment` · `x-pd-external-user-id` · `x-pd-app-slug: alpaca`

```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()

// e.g. run Cancel All Orders:
const result = await mcp.callTool({
  name: "alpaca-cancel-all-orders",
  arguments: {
    isPaperAPI: true,
  },
})
```

Docs: [MCP guide](https://pipedream.com/docs/connect/mcp/developers.md)

## API proxy

For a Alpaca endpoint with no pre-built tool, the proxy forwards your request with the connected user's credentials attached.

```bash
# The path segment is the target URL, URL-safe base64 encoded:
# https://api.alpaca.markets/v2/account

curl "https://api.pipedream.com/v1/connect/{project_id}/proxy/aHR0cHM6Ly9hcGkuYWxwYWNhLm1hcmtldHMvdjIvYWNjb3VudA?external_user_id={external_user_id}&account_id=apn_xxxxxxx" \
  -H "Authorization: Bearer {access_token}" \
  -H "x-pd-environment: production"
```

Docs: [API proxy guide](https://pipedream.com/docs/connect/api-proxy.md)

## SDK

```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-cancel-all-orders",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    alpaca: { authProvisionId: "apn_xxxxxxx" },
    isPaperAPI: true,
  },
})
```

Docs: [Managed auth guide](https://pipedream.com/docs/connect/managed-auth/quickstart.md) · [Tools guide](https://pipedream.com/docs/connect/components.md)

## Actions (8)

### `alpaca-cancel-all-orders` — Cancel All Orders (Write)

Attempts to cancel all open orders. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server reject the request, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/cancel-all-orders.md

### `alpaca-cancel-order` — Cancel Order (Write)

Attempts to cancel an open order. If the order is no longer cancelable (example: status=filled), the server will reject the request, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/cancel-order.md

### `alpaca-close-all-positions` — Close All Positions (Write)

Closes (liquidates) all of the account’s open long and short positions. A response will be provided for each order that is attempted to be cancelled. If an order is no longer cancelable, the server will reject the request, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/close-all-positions.md

### `alpaca-close-position` — Close Position (Write)

Closes (liquidates) the account’s open position. Works for both long and short positions, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/close-position.md

### `alpaca-get-account-info` — Get Account Info (Read-only)

Returns the account info, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/get-account-info.md

### `alpaca-list-orders` — List Orders (Read-only)

Retrieves a list of orders for the account, filtered by the supplied query parameters, if no filter given all will be returned, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/list-orders.md

### `alpaca-list-positions` — List Positions (Write)

Retrieves a list of the account’s open positions, See the docs

Full schema: https://pipedream.com/apps/alpaca/actions/list-positions.md

### `alpaca-place-order` — Place Order (Write)

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

Full schema: https://pipedream.com/apps/alpaca/actions/place-order.md

---

- All apps: https://pipedream.com/apps — index: https://pipedream.com/llms.txt
- Pipedream docs for agents: https://pipedream.com/docs/llms.txt
