Agent skill

Alpaca Broker Reconciliation Idempotency

by alpacahq in alpacahq/alpaca-skills

Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status…

Apache-2.0Auto-check passedBusiness, Finance & HR

Install Alpaca Broker Reconciliation Idempotency

skills CLI
$ npx skills add alpacahq/alpaca-skills --skill alpaca-broker-reconciliation-idempotency -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install alpacahq/alpaca-skills alpaca-broker-reconciliation-idempotency --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/alpacahq/alpaca-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/broker-api/reconciliation-idempotency .claude/skills/alpaca-broker-reconciliation-idempotency && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
alpaca-broker-reconciliation-idempotency
GitHub stars
154
Token cost
~2k tokens
SKILL.md length
973 words
Files
2
Skills in repo
14
Repo updated
First seen
Licence
Apache-2.0

At a glance

Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status…

  • Works in 9 steps: Three layers of defense → Layer 1 — Idempotent writes → Layer 2 — Idempotent event intake → …
  • Designing the data-correctness layer of any Alpaca integration in any language
  • SKILL.md covers The core principle, 1. Three layers of defense, 2. Layer 1 — Idempotent writes and 3. Layer 2 — Idempotent event…, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Alpaca Broker Reconciliation Idempotency is an agent skill from alpacahq/alpaca-skills. Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status state-machine mapping, and handling eventual consistency and corrections. Use when designing the data-correctness layer of any Alpaca integration in any language.

Its SKILL.md is about 2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file (for example `reference.md`).

It sits in Business, Finance & HR, covering Accounting and bookkeeping and Backend development. The repository describes itself as: Agent skills for Alpaca's Trading API and Broker API: drop-in SKILL.md files for AI coding assistants. The licence is Apache-2.0.

When your agent uses it

  • Designing the data-correctness layer of any Alpaca integration in any language
  • Tasks that involve Accounting and bookkeeping
  • Tasks that involve Backend development

Example prompts

  • “/alpaca-broker-reconciliation-idempotency”

Workflow steps

9 steps, taken from the step headings in SKILL.md.

  1. Three layers of defense
  2. Layer 1 — Idempotent writes
  3. Layer 2 — Idempotent event intake
  4. Layer 3 — Reconciliation / heal jobs
  5. Polling the rails that have no events
  6. Status state-machine mapping
  7. Eventual-consistency hazards to design for
  8. Anti-patterns (seen in the wild)
  9. Putting it together

What it can do on your machine

Read from SKILL.md and the folder at commit 39111ab. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Alpaca Broker Reconciliation Idempotency loads about 2k tokens when it runs. Until then it costs about 101 tokens; SKILL.md has 973 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~101
When it runs · the whole SKILL.md, loaded when a task matches
~2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from alpacahq/alpaca-skills at commit 39111ab, republished under its Apache-2.0 licence (© alpacahq). 973 words, ~2,035 tokens.

Download SKILL.mdSave it as .claude/skills/alpaca-broker-reconciliation-idempotency/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
alpaca-broker-reconciliation-idempotency
description
Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status state-machine mapping, and handling eventual consistency and corrections. Use when designing the data-correctness layer of any Alpaca integration in any language.

Alpaca — Reconciliation & Idempotency

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-integration, alpaca-broker-sse-events, and the relevant domain skills first. This skill is the architecture that ties them together.

The core principle

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.

1. Three layers of defense

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).

2. Layer 1 — Idempotent writes

Every money/order write must be safe to retry, because you can't tell a timeout apart from a success.

  • Orders: set your own 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.
  • Journals: send an Idempotency-Key header. Same key + same body returns the original journal; same key + different body → 422. (See alpaca-broker-journals.)
  • Local-first ordering: write your intent row (with a generated key) before the network call, so a crash mid-call leaves a record you can reconcile — never an orphaned Alpaca object you can't find.
  • Persist the returned Alpaca ID immediately (account_id, order_id, journal_id, transfer_id). It is your only correlation key for events and reconciliation.

3. Layer 2 — Idempotent event intake

Events are at-least-once: replay cursors, reconnects, and corrections all cause the same event to arrive more than once.

  • Snapshot-first, keyed on event_id. Insert the raw event with upsert / skip-on-duplicate on event_id (a ULID). A duplicate becomes a no-op. This single unique constraint is your dedup boundary.
  • Key business records on the Alpaca ID, not on a local autoincrement, with upsert semantics.
  • Guard transitions by current status. Before acting, check the record isn't already terminal — so a duplicate "executed"/"filled" doesn't re-fire a payout or notification.
  • Lock the row while mutating (SELECT … FOR UPDATE or your engine's equivalent) so concurrent events for one record serialize.
  • Advance the cursor only after success (at-least-once, made safe by the above).

4. Layer 3 — Reconciliation / heal jobs

A scheduled job that re-pulls authoritative state from Alpaca and upserts it locally. This is what makes the system self-healing.

Canonical nightly heal (lesson):

  1. For each active account, page through trade activities and non-trade activities (GET /v1/accounts/activities, paginated) for the last N days (e.g. 3) — a moving window that re-covers recent days so anything missed by SSE gets backfilled.
  2. Page through journals (GET /v1/journals) and transfers for the same window.
  3. Upsert each into your tables keyed on the Alpaca ID (insert-or-update). Re-running is safe and converges.
  4. Bound concurrency (a small worker pool) and respect rate limits (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.

Show full SKILL.md (437 more words)Show less

5. Polling the rails that have no events

Not everything emits SSE. Where there's no event, you must poll.

  • Funding-wallet per-transfer status (v1beta) is not pushed — poll GET /v1beta/.../funding_wallet/transfers/{id} on a schedule.
  • Stagger pollers (e.g. one rail at :00, another at :30) to spread API load.
  • Only poll records in a non-terminal state. Filter your query to 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.
  • Gotcha — no GET-by-id on classic wire transfers: you must 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.

6. Status state-machine mapping

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.

  • Define one explicit mapping table per domain from Alpaca status → your internal status (e.g. executed/COMPLETE → COMPLETED; rejected/canceled/returned/failed → CANCELLED).
  • Handle unknown statuses gracefully — log and skip, never crash. Alpaca adds values (and has shipped bad ones — e.g. a stray TRD activity type that consumers had to filter out).
  • Know which states are terminal (they differ per enum) so you stop polling/processing them.

7. Eventual-consistency hazards to design for

  • 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.
  • Corrections create new IDs. A journal 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.
  • Out-of-order & duplicate events are normal (see alpaca-broker-sse-events §5). Idempotency absorbs them.

8. Anti-patterns (seen in the wild)

  • ❌ Reconnecting an SSE stream without a since_id cursor → silently drops every event during the gap. (Fix: persist + replay the cursor.)
  • ❌ Treating an SSE stream as your only source → no backstop for missed events. (Fix: add the heal job.)
  • ❌ Blind retry of a journal/order without an idempotency key → double money movement.
  • ❌ Acting on executed as irreversible → broken books when a reversal/correction lands.
  • ❌ Dedup keyed on a confirmed set instead of a seen set → judge/reject churn re-processes forever. Dedup on everything seen, key on the Alpaca/event ID.

9. Putting it together

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:    nightly window 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.

© alpacahq, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in skills/broker-api/reconciliation-idempotency of alpacahq/alpaca-skills.

  • SKILL.md
  • reference.md

Open the folder on GitHubat commit 39111ab

Compare with similar skills

Alpaca Broker Reconciliation Idempotency next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Alpaca Broker Reconciliation Idempotency compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Alpaca Broker Reconciliation Idempotency this skillalpacahq/alpaca-skills154—~2kAutomated safety check: PassApache-2.0
Sync Upstreamnyaruka/phonenumbers1.6k—~2.8kAutomated safety check: PassMIT
Radiology Tablehuang-sir1/radiology-skills1.9k—~1.3kAutomated safety check: PassCustom licence
ERPClaw ERP Controlleravansaber/erpclaw116—~18kAutomated safety check: PassGPL-3.0
Odoo Agency Fleet Reviewerpipe-org/mcp-odoo421—~699Automated safety check: PassMIT
Beancount Closebex-co/beancount-io297—~1.4kAutomated safety check: PassMIT

Similar skills

  • Sync Upstream

    nyaruka/phonenumbers

    Sync this Go port with a new upstream google/libphonenumber release — regenerate the embedded metadata and reconcile the ported Java logic.

    1.6k GitHub stars~2.8k tokensUpdated 9 days ago
    Business, Finance & HRAuto-check passed
  • Radiology Table

    huang-sir1/radiology-skills

    Create/audit editable publication tables with source reconciliation; not figures or statistical inference.

    1.9k GitHub stars~1.3k tokensUpdated 20 days ago
    Business, Finance & HRAuto-check passed
  • ERPClaw ERP Controller

    avansaber/erpclaw

    Operates the ERPClaw self-hosted ERP in plain language: accounting, invoicing, inventory, purchasing, tax, HR, payroll and reports, treating the ERP as the single source of truth.

    116 GitHub stars~18k tokensUpdated 2 days ago
    Business, Finance & HRAuto-check passed
  • Odoo Agency Fleet Review

    erpipe-org/mcp-odoo

    Review many client Odoo databases at once through odoo-mcp's cross-instance tools — fleet-wide accounting health, per-client aging, partial-failure triage — for agencies and partners managing 5–50…

    421 GitHub stars~699 tokensUpdated 1 mo ago
    Business, Finance & HRAuto-check passed
  • Beancount Close

    bex-co/beancount-io

    Close an accounting period in a Beancount ledger by reconciling each active account through beancount-reconcile, checking assertions and recurring gaps, reviewing flags, then proposing a commit with…

    297 GitHub stars~1.4k tokensUpdated today
    Business, Finance & HRAuto-check passed
  • Forward Implementation First

    Vuk97/forward-implementation-first

    Keeps an agent building and validating real output instead of servicing its own bookkeeping.

    176 GitHub stars~1.8k tokensUpdated 1 mo ago
    Business, Finance & HRAuto-check passed

More from alpacahq/alpaca-skills

All 14 skills in this repo
  • Alpaca Broker Account Onboarding

    alpacahq/alpaca-skills

    Open and manage brokerage accounts via the Alpaca Broker API — account creation, KYC/CIP, identity & disclosures, agreements, document upload (incl.

    154 GitHub stars~2.3k tokensUpdated 1 mo ago
    Auto-check passed
  • Alpaca Broker Funding Transfers

    alpacahq/alpaca-skills

    Move money between an Alpaca brokerage account and the EXTERNAL banking world via the Broker API — ACH relationships, wire recipient banks, classic transfers (deposits/withdrawals), the v1beta…

    154 GitHub stars~2.4k tokensUpdated 1 mo ago
    Auto-check passed
  • Alpaca Broker Integration

    alpacahq/alpaca-skills

    Entry point for integrating with the Alpaca Broker API (plus Market Data and Trading APIs) in any programming language.

    154 GitHub stars~3k tokensUpdated 1 mo ago
    Auto-check passed
  • Alpaca Broker Journals

    alpacahq/alpaca-skills

    Move cash (JNLC) and securities (JNLS) BETWEEN accounts inside your own Alpaca omnibus via the Broker API — single, batch, and reverse-batch journals, the Idempotency-Key header, journal status…

    154 GitHub stars~2.1k tokensUpdated 1 mo ago
    Auto-check passed
  • Alpaca Broker Money Precision

    alpacahq/alpaca-skills

    Handle money and numeric precision correctly with the Alpaca API — numbers-as-strings on the wire, decimals vs floats, rounding/truncation before sending amounts, fractional-share precision, and…

    154 GitHub stars~1.2k tokensUpdated 1 mo ago
    Auto-check passed
  • Make Alpaca API clients resilient — rate-limit header handling, HTTP 429 backoff, exponential retry, bounded concurrency/worker pools, pagination loops, batch sizing, and timeouts.

    154 GitHub stars~1.4k tokensUpdated 1 mo ago
    Auto-check passed

Questions about Alpaca Broker Reconciliation Idempotency

What does Alpaca Broker Reconciliation Idempotency do?

Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status…. Alpaca Broker Reconciliation Idempotency is an agent skill from alpacahq/alpaca-skills. Keep local state correct against the Alpaca Broker API — idempotency keys, ID-keyed upserts, event snapshotting and dedup, polling rails that have no events, nightly reconciliation/heal jobs, status state-machine mapping, and handling eventual consistency and corrections.

When should I use Alpaca Broker Reconciliation Idempotency?

Alpaca Broker Reconciliation Idempotency fits situations like: designing the data-correctness layer of any Alpaca integration in any language; tasks that involve Accounting and bookkeeping; tasks that involve Backend development.

How do I install Alpaca Broker Reconciliation Idempotency in Claude Code?

Run `npx skills add alpacahq/alpaca-skills --skill alpaca-broker-reconciliation-idempotency -a claude-code`. Or copy the skill folder (skills/broker-api/reconciliation-idempotency in alpacahq/alpaca-skills) into .claude/skills/alpaca-broker-reconciliation-idempotency in your project. Claude Code loads it when a task matches its description.

How do I install Alpaca Broker Reconciliation Idempotency in Codex?

Run `npx skills add alpacahq/alpaca-skills --skill alpaca-broker-reconciliation-idempotency -a codex`. Or copy the skill folder (skills/broker-api/reconciliation-idempotency in alpacahq/alpaca-skills) into .agents/skills/alpaca-broker-reconciliation-idempotency in your project. Codex loads it when a task matches its description.

Can I use Alpaca Broker Reconciliation Idempotency in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add alpacahq/alpaca-skills --skill alpaca-broker-reconciliation-idempotency -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/alpaca-broker-reconciliation-idempotency, .gemini/skills/alpaca-broker-reconciliation-idempotency, .github/skills/alpaca-broker-reconciliation-idempotency and .opencode/skills/alpaca-broker-reconciliation-idempotency in your project.

What does Alpaca Broker Reconciliation Idempotency need to run?

SKILL.md names no scripts, command-line tools or credentials: Alpaca Broker Reconciliation Idempotency is instructions for the agent only.

Does Alpaca Broker Reconciliation Idempotency access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Alpaca Broker Reconciliation Idempotency safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Alpaca Broker Reconciliation Idempotency use?

Alpaca Broker Reconciliation Idempotency is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Alpaca Broker Reconciliation Idempotency use?

About 2k tokens (SKILL.md is roughly 8.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Alpaca Broker Reconciliation Idempotency?

Skills that share tags, products or a category with Alpaca Broker Reconciliation Idempotency: Sync Upstream (nyaruka/phonenumbers, 1.6k stars), Radiology Table (huang-sir1/radiology-skills, 1.9k stars), ERPClaw ERP Controller (avansaber/erpclaw, 116 stars) and Odoo Agency Fleet Review (erpipe-org/mcp-odoo, 421 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Alpaca Broker Reconciliation Idempotency?

alpacahq (a GitHub organization) maintains it in alpacahq/alpaca-skills, which has 154 GitHub stars. The repository holds 14 skills in this directory. The repository was last updated on September 8, 2026.

Source: alpacahq/alpaca-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.