---
related_nodes: ["alpaca_trading", "quote_fetch"]
---

# Alpaca Event Trigger

Starts a workflow when an Alpaca order changes state, or when a price alert crosses.

It is a trigger through node metadata: it has no input socket and emits one event on
`output`.

## When to Use

- Act on a fill without holding a workflow open waiting for one
- React to a bracket leg firing, so a closing fill can be attributed
- Wake a suspended strategy when a price reaches a level you named earlier

## Configuration

### connection

Alpaca connection id from **Settings → Connections**. Call `list_connections` with
`provider_name: "alpaca"` and use the returned `id`.

### mode

`paper` (default) or `live`. Paper and live keep separate orders, so this must match the
environment the orders were placed in.

### source

`order_updates` — order state changes, optionally narrowed:

- `event_kinds` — which events start the workflow. Empty means every event.
- `symbols` — which symbols start the workflow. Empty means every symbol.

`price_alert` — one channel:

- `key` — the channel given to a `configure_price_alert` operation on an Alpaca Trading
  node. Several alerts may share a channel, so read `alert_id` and `payload` on the event to
  tell which one fired.

## Output

Socket: `output`. Either an event or the failure that stopped one arriving.

```json
{ "kind": "data",
  "data": { "kind": "order_update", "event": "fill",
            "occurred_at": "2026-08-30T14:31:02Z",
            "execution_price": 771.18, "execution_qty": 12, "position_qty": 12,
            "order": { "id": "...", "status": "filled", "symbol": "SPY", ... } } }
```

A price alert:

```json
{ "kind": "data",
  "data": { "kind": "price_alert", "alert_id": "01M1C...", "key": "spy-exit-watch",
            "payload": { "session": "01M1B..." }, "symbol": "SPY",
            "comparison": "below", "threshold": 763.61,
            "observed": 762.90, "observed_at": "2026-08-30T18:02:11Z" } }
```

`observed` is the latest eligible IEX trade price sampled for the threshold, not a quote
midpoint. `observed_at` is the time of that sample, not the trade's execution timestamp.

A failure reaches the workflow as a run of its own, so a listener that cannot reach Alpaca
is visible in execution history rather than only in a log:

```json
{ "kind": "error",
  "error": { "source": "poll", "message": "...", "occurred_at": "..." } }
```

`source` is `listener` (the stream), `poll` (the reconcile or a price sample), or `auth`.

## Delivery

**At-least-once.** Order events arrive two ways and are merged: a websocket stream
delivers them as they happen, and a poll over Alpaca's activity log closes the gaps the
stream cannot. Alpaca permits one stream connection per account and offers no replay after
a reconnect, so without the second path every event during a drop would be lost silently.
The poll runs each time the stream connects, and then once per interval; while the stream
cannot connect, its failure arrives at once and the poll's first pass comes one interval later.

Both paths pass one dedupe, keyed on the order transition rather than on the message that
carried it, so the same fill arriving twice starts one workflow. That window is bounded,
not a guarantee: **treat a delivery as a cue to reconcile, not as proof of state.** Read
`get_order` or `get_position` before acting on what you believe you hold.

Each order event that passes the dedupe starts one run, in the order the events arrived, including
events that arrive while earlier runs are still going.

If your account also runs something else against the same Alpaca keys, the two contend for
the single stream connection. The reconcile is what keeps this correct when that happens;
the cost is latency, not lost events.

Price alerts **sample the latest eligible trade on IEX**, rather than a quote midpoint;
they do not watch prices continuously. Alpaca's latest-trade endpoint excludes conditions
that do not update bar prices, including odd lots. A price that crosses the threshold and
comes back between two samples does not fire. Alpaca sells no alert API at any tier, so this
is not a limitation that can be lifted here — if you need a guaranteed price trigger, that
is a resting stop order, which trades rather than notifies.

## Runtime Errors and Notes

- Install fails with `No Alpaca connection is selected` if the connection is unset, and
  the workflow reports it as an install error.
- A price alert trigger with no `key` fails to install; the key is the channel that pairs it
  with the operation that armed the alert.
- `alert_id` says which alert fired and `payload` says what it was about. The key alone
  cannot tell you, because a channel may carry several alerts.
- Events are delivered only while the workflow is enabled. The stream is opened by the
  first listener and closed when the last one goes, so an account nobody listens to holds
  no connection.
- The reconcile and the price sampler are background sweeps and stop when automatic tasks
  are disabled. The stream itself stays connected.
