Nyria Docs

Connect Alpaca to Nyria

Step-by-step Alpaca setup via API key — connect a paper or live account, verify it, and fire your first single- or multi-leg (up to four legs) options test order.

By the end you will have an Alpaca account (paper or live) connected to Nyria via API key, a bot wired to a strategy, and a verified test order — stock or up to a four-leg options structure.

Start with paper. Both paper and live Alpaca accounts are supported, but always validate a new strategy against the paper environment before pointing it at a funded live account. See the Alpaca integration overview for the current capability matrix.

Prerequisites

  • A Nyria account with onboarding completed. New here? Start at the Quick Start.
  • An Alpaca account. Sign up free at alpaca.markets — paper accounts come pre-provisioned with $100,000 of simulated cash.
  • A Nyria strategy you can attach a bot to. The Strategies guide walks through creating one.
  • For options testing: your Alpaca paper account must have options trading enabled at the level you intend to use (Alpaca paper supports up to Options Level 3, which covers the four-leg structures below). Toggle this in Alpaca's account settings before connecting.

Step 1: Open the broker connection modal

Sign in to the Nyria app and click the Integrations tab in the left sidebar.

Click Add Integration. The broker grid opens.

Find the Alpaca tile and click it. The Alpaca connection modal opens with environment options.

You can deep-link straight to this modal from any external page using https://app.nyria.io/integrations?brokerModal=alpaca. Useful for documentation, support emails, or onboarding flows.

Step 2: Generate an API key in Alpaca

Sign in at alpaca.markets and switch the dashboard to the environment you want to connect — Paper (toggle at the top of the dashboard) or Live.

Open the API keys panel on the dashboard home and click Generate New Keys. Copy both the API Key ID and the Secret Key — the secret is shown only once.

Step 3: Paste the key into Nyria

Back in the Nyria Alpaca modal, pick the matching account type (Paper or Live) for the key you generated. Paper keys only work against the paper environment and vice versa.

Paste the key into the APCA-API-KEY-ID field and the secret into the APCA-API-SECRET-KEY field.

Click Connect. Nyria validates the key against Alpaca's account endpoint and imports the account.

Alpaca API keys carry trading permission by design. Never share them, and revoke them from the Alpaca dashboard if you disconnect — Nyria deletes its stored copy on disconnect, but the key itself stays valid at Alpaca until you regenerate it.

Step 4: Confirm the connection in Nyria

After the key validates, the Connection successful modal opens.

Verify the masked account number shown matches the Alpaca account you intended to connect. Alpaca paper account numbers all start with PA.

Note the buying power figure — it should read close to $100,000.00 for a fresh paper account.

Click Done. The integration now appears on the Integrations page with a green Connected badge and an Alpaca · Paper label.

If you don't see the expected account, click Refresh accounts on the integration row. Nyria re-queries Alpaca's /v2/account endpoint and updates the list.

Step 5: Create a bot on the connection

A connection alone does not trade. You need a bot — the link between a strategy and an account.

Open the strategy you want to wire up. Click the Bots tab.

Click Add Bot and pick Alpaca · Paper from the account dropdown.

Set the allocation (e.g. 10% of paper buying power for a first test) and click Create. The bot defaults to paused so it cannot fire on a stray signal before you verify the wiring.

Step 6: Fire a stock test order

The fastest end-to-end check is a market order on a liquid US equity. Replace <tokenHash> with your strategy's webhook token (Integration tab → Copy Webhook URL).

curl -X POST https://trades.nyria.io/webhooks/<tokenHash> \
  -H "Content-Type: application/json" \
  -d '{
    "ticker": "SPY",
    "action": "buy",
    "sentiment": "long",
    "quantity": 1,
    "order_type": "market"
  }'

Expected response:

{
  "ok": true,
  "bot_log_id": "bl_01J8Z...",
  "skipped": false
}

Open the strategy's Logs tab. The new entry should appear within ~1 second with the routed broker order id.

Sign in to the Alpaca paper dashboard and open Orders. The same order should be present with status filled (market hours) or accepted (outside market hours).

If you sent buy, you should now hold 1 share of SPY. Send the opposite payload ("action": "sell") to close the position before moving on.

If both sides clear, your stock wiring is good.

Step 7: Fire a multi-leg options test order

Nyria's Alpaca integration accepts up to four legs per options order. Use this to test verticals, iron condors, butterflies, and similar structures. The payload below opens a SPY iron condor — short call spread plus short put spread — using Nyria's delta-target syntax so you don't have to hand-pick strikes.

curl -X POST https://trades.nyria.io/webhooks/<tokenHash> \
  -H "Content-Type: application/json" \
  -d '{
    "ticker": "SPY",
    "action": "open",
    "direction": "short",
    "order_type": "limit",
    "legs": [
      { "side": "CALL", "action": "sell_to_open", "delta_target": 0.20, "dte_min": 30, "dte_max": 45, "quantity": 1 },
      { "side": "CALL", "action": "buy_to_open",  "delta_target": 0.10, "dte_min": 30, "dte_max": 45, "quantity": 1 },
      { "side": "PUT",  "action": "sell_to_open", "delta_target": 0.20, "dte_min": 30, "dte_max": 45, "quantity": 1 },
      { "side": "PUT",  "action": "buy_to_open",  "delta_target": 0.10, "dte_min": 30, "dte_max": 45, "quantity": 1 }
    ]
  }'

What each field means once Nyria resolves it:

FieldEffect
direction: "short"Strategy is net short premium — Nyria classifies this as a credit structure when the legs net to a credit.
legs[].sideCALL or PUT. Each leg picks an option chain on the underlying.
legs[].actionbuy_to_open, sell_to_open, buy_to_close, sell_to_close. Determines order side per leg.
legs[].delta_targetNyria's option chain scanner picks the strike closest to this absolute delta on the chosen expiry.
legs[].dte_min / dte_maxDays-to-expiry window. Nyria picks the expiry with the most open interest inside the window.
legs[].quantityContracts per leg. All four must use the same quantity for a balanced structure.

Three- and four-leg structures are submitted to Alpaca as a single multi-leg order. Nyria does not stitch four single-leg orders together; it uses Alpaca's mleg order class so the legs fill atomically or not at all. If Alpaca rejects the structure (margin, level, or chain liquidity), all legs are cancelled together.

For a single-leg options test (lower margin requirement on the paper account, faster to verify), use the simpler payload from the Webhook reference:

{
  "ticker": "SPY",
  "action": "open",
  "direction": "long",
  "legs": [{ "side": "PUT", "action": "buy_to_open", "delta_target": 0.30, "dte_min": 7, "dte_max": 21, "quantity": 1 }],
  "order_type": "market"
}

Fire the payload via cURL or your alert source.

In the strategy's Logs tab, expand the bot log entry. The resolved OCC symbols, strikes, and expiries should appear under Order detail.

Cross-check on the Alpaca paper dashboard. The order will appear under Orders with class: mleg and one row per leg.

Send the matching close payload (swap sell_to_openbuy_to_close and buy_to_opensell_to_close, keep delta targets and strikes aligned) to flatten the position before unpausing the bot.

Step 8: Unpause the bot

When both stock and options test orders cleared end-to-end:

Open the strategy's Bots tab.

Toggle the Alpaca paper bot from Paused to Active.

The bot is now armed. The next alert that matches your strategy's filters will route to Alpaca paper.

Troubleshooting

Connect fails with invalid credentials

The key/secret pair didn't validate against Alpaca. The most common causes: the secret was copied with a trailing space, the key was regenerated in Alpaca after you copied it (regenerating invalidates the old pair), or the Alpaca account has not finished provisioning (brand-new sign-up where Alpaca is still creating the PA* account — wait a few minutes and retry).

Connection shows Connected but the buying power reads $0.00

This usually means the key belongs to the other environment than the account type you picked (e.g. a live key connected as Paper). Disconnect the integration, confirm which environment the Alpaca dashboard was in when you generated the key, and reconnect with the matching account type.

Stock test order returns 422 unprocessable_entity

Open the bot log entry for the call. The error_detail field will explain the rejection. Common Alpaca paper rejections:

  • symbol not tradable — the ticker is not in Alpaca's paper universe (some OTC tickers are missing). Try a major large-cap to confirm the wiring.
  • insufficient buying power — your paper account has been used for prior tests and has open positions tying up cash. Close them in the Alpaca dashboard.
  • pdt restriction — the account has been flagged Pattern Day Trader and is under $25k. Reset the paper account from the Alpaca dashboard.

Options test order returns 403 options_level_required

Your Alpaca paper account does not have the options level required for the structure. Two- and four-leg defined-risk spreads require Level 3 on Alpaca paper. Enable it from Alpaca's Account → Options settings and retry. Note that the level may take a minute to propagate.

Four-leg order partially fills

This should not happen on Alpaca — multi-leg orders fill atomically or not at all. If you see partial fills on the Nyria log but the Alpaca dashboard shows all four legs filled, refresh the Nyria log; the per-leg status may have lagged the broker-side fill by a few seconds while the order-status sync task caught up.

Key stopped working after a while

Alpaca API keys don't expire on a schedule, but they are invalidated if you regenerate keys in the Alpaca dashboard or reset the paper account. If a bot starts failing with 401 unauthorized, generate a fresh key pair and reconnect from the Integrations page — your bot config and history are preserved across reconnect.

Going from paper to a real signal source

Once the cURL probes pass, replace the manual tests with your real alert source. The webhook URL does not change — it is per-strategy, not per-broker:

What's next