Provides patterns for keeping local state consistent with the Alpaca Broker API: idempotent writes, event deduplication, polling for non-event rails, and reconciliation/heal jobs. Use when building a production-grade data-correctness layer for any Alpaca integration.
Ships in alpaca-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This is the skill that separates a demo from production. Alpaca is an asynchronous, eventually-consistent system: writes settle later, events can be missed or replayed, some rails emit no events at all, and "executed" can still be reversed. Your job is to make your local database a faithful, self-healing mirror of Alpaca's state.
Read
alpaca-broker-integrationfirst for base URLs and auth (client-credentials Bearer token; legacy Basic still works), thenalpaca-broker-sse-eventsand the relevant domain skills. This skill is the architecture that ties them together.
Treat Alpaca as the source of truth and your DB as a cache that must converge to it. Every write is a request, not a fact. Every event is a hint, not a guarantee. Correctness comes from idempotent processing plus a reconciliation loop — never from assuming any single call or event succeeded exactly once.
Layer 1 — Idempotent writes : never create a duplicate when you retry
Layer 2 — Idempotent event intake: never double-process a replayed/duplicate event
Layer 3 — Reconciliation sweep : re-pull authoritative state and fix any drift
You need all three. Layer 1+2 keep you correct in the happy/retry case; Layer 3 catches everything that still slips through (downtime, bugs, missing events, corrections).
Every money/order write must be safe to retry, because you can't tell a timeout apart from a success.
client_order_id (≤128 chars) derived from your transaction ID. On a lost response, look the order up via orders:by_client_order_id before retrying.Idempotency-Key header. Same key + same body returns the original journal; same key + different body → 422. (See alpaca-broker-journals.)account_id, order_id, journal_id, transfer_id). It is your only correlation key for events and reconciliation.Events are at-least-once: replay cursors, reconnects, and corrections all cause the same event to arrive more than once.
event_id (a ULID) is the replay cursor, and on the Activity SSE the dedup key is ref_id, the documented key for at-least-once redelivery on replay and for correction/bust linkage via previous_id. On the legacy status streams event_id fills both roles.account_id is the simplest default, since Alpaca guarantees per-account event ordering; a SELECT … FOR UPDATE row lock or an optimistic version column are the alternatives.A scheduled job that re-pulls authoritative state from Alpaca and upserts it locally. This is what makes the system self-healing.
Canonical windowed heal (lesson):
GET /v2beta1/events/activities) with since/until bounds. Bounded replay is a batch job, not a subscription: the stream ends with a 200 once it reaches until, and since/until filter on business time (at). (GET /v1/accounts/activities is marked fully replaced, but it is still the only source for activities booked before 2026-02-11; use it for any window that reaches back past that date.)GET /v1/journals) and transfers for the same window.alpaca-broker-rate-limits-resilience).Why a window and not just "since last run": it absorbs corrections, late settlements, and any events dropped during a deploy — without rescanning all history every night. Choose a window longer than your longest plausible outage.
Not everything emits SSE. Where there's no event, you must poll.
GET /v1beta/.../funding_wallet/transfers/{id} on a schedule.status IN (pending, processing, …); once a record reaches a terminal status, drop it from the polling set. This bounds the work and prevents re-notifying.GET /v1/accounts/{id}/transfers?direction=OUTGOING (a list) and match the ID client-side; cache the list per account within a run.Lesson: polling implies latency. Document the expected lag (e.g. "withdrawal status updates within ~1h") so product/support set the right expectations.
Alpaca exposes several status enums (account, order, journal, transfer, funding-wallet) — each with its own vocabulary. Don't scatter raw Alpaca strings through your app.
COMPLETE → COMPLETED; REJECTED/CANCELED/RETURNED → CANCELLED).RETURNED; there is no failed. Journal statuses are lowercase. The REST TransferStatus enum and the funding-event enum aren't even the same set, so map the union of both.executed/COMPLETE is not always final — journals can be reversed by cashiering; transfers can be RETURNED after appearing done. Keep reconciling past the "happy" terminal state for a window.correct cancels the original and issues a new journal ID carrying the real funds. Reconciliation keyed on event snapshots + Alpaca IDs handles this; logic that mutates the original record in place does not.200 means accepted, not settled. Never confirm money moved to a user off the create response — confirm off the terminal event/poll.alpaca-broker-sse-events §5). Idempotency absorbs them.since_id on v2, since_ulid on v1) → silently drops every event during the gap. (Fix: persist + replay the cursor.)executed as irreversible → broken books when a reversal/correction lands.confirmed set instead of a seen set → judge/reject churn re-processes forever. Dedup on everything seen, key on the Alpaca/event ID.WRITE: local intent row (idempotency key) → Alpaca call → store Alpaca ID
LIVE: SSE consumer (cursor-replay, snapshot-keyed dedup, status-guarded upsert)
POLL: schedulers for rails with no events (non-terminal records only)
HEAL: windowed re-pull of activities/journals/transfers → upsert
MAP: Alpaca status → internal status, terminal-aware, unknown-tolerant
Related skills: event consumption mechanics → alpaca-broker-sse-events; idempotency keys per domain → alpaca-broker-journals, alpaca-broker-trading-orders; polling rails → alpaca-broker-funding-transfers; backoff & rate limits in heal jobs → alpaca-broker-rate-limits-resilience.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
alpaca, broker-api, idempotency, reconciliation, event-processing
14 skills in this plugin
/alpaca-broker-account-onboardingOpen and manage brokerage accounts via the Alpaca Broker API — account creation, KYC/CIP, identity & disclosures, agreements, document upload (incl. W-8BEN), account status lifecycle, and account updates/closure. Use when a developer is building onboarding, KYC, or account-management flows on Alpaca in any language./alpaca-trading-backtestExecute deterministic, reproducible historical backtests from a start date, end date, and strategy concept using the Alpaca CLI plus agent-written workspace code. Use when the user wants to backtest a strategy, simulate historical trades, or return trades, diagnostics, and reproducibility artifacts.
/alpaca-broker-funding-transfers/alpacahq-alpaca-skills:alpaca-broker-reconciliation-idempotencyfrom alpaca-skills
Generated from the plugin's indexed repository (alpacahq/alpaca-skills) — no native marketplace selected
npx claudepluginhub p/alpacahq-alpaca-skillsOther plugins' skills for the same job