alpaca-broker-reconciliation-idempotency

Design idempotent writes, event dedup, and reconciliation jobs for Alpaca Broker API integrations.

4|Updated Aug 28, 2026
One-click install
npx skills add https://github.com/alan-d-smith/synthetix-alpha --skill alpaca-broker-reconciliation-idempotency-alan-d-smith
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: alpaca-broker-reconciliation-idempotency
Source: https://github.com/alan-d-smith/synthetix-alpha/tree/main/.agents/skills/alpaca-broker-reconciliation-idempotency
Command: npx skills add https://github.com/alan-d-smith/synthetix-alpha --skill alpaca-broker-reconciliation-idempotency-alan-d-smith

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Alpaca is an asynchronous, eventually-consistent system where writes settle later, events can be missed or replayed, and some rails emit no events at all. This Skill prevents duplicate money movement, missed events, and drifting local state by making your database a self-healing mirror of Alpaca's authoritative state. ## Core Features & Use Cases - Three-layer correctness architecture: idempotent writes with client order IDs and Idempotency-Key headers, idempotent event intake keyed on event_id, and nightly reconciliation sweeps that re-pull and upsert authoritative state. - Polling and status mapping: poll rails with no SSE events (funding-wallet transfers, classic wire transfers) only for non-terminal records, and map Alpaca status enums to internal states with terminal-aware, unknown-tolerant handling. - Use Case: You are building a brokerage app on the Alpaca Broker API and need to guarantee that a retried journal never double-moves money, a replayed SSE event never re-fires a payout, and a missed event during a deploy is backfilled by a nightly heal job over trade activities, journals, and transfers. ## Quick Start Use this skill to design the idempotency, event deduplication, and nightly reconciliation layer for my Alpaca Broker API integration.

Frequently Asked Questions about alpaca-broker-reconciliation-idempotency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Alpaca API writes idempotent?▼

Set your own client_order_id on orders and look it up via orders:by_client_order_id before retrying. For journals, send an Idempotency-Key header so the same key and body returns the original journal. Write a local intent row with the key before the network call so crashes leave a reconcilable record.

How do I handle duplicate Alpaca SSE events?▼

Alpaca events are at-least-once, so insert each raw event with upsert or skip-on-duplicate keyed on event_id, making duplicates no-ops. Guard business transitions by checking the record is not already terminal, lock the row while mutating, and advance the replay cursor only after successful processing.

Does Alpaca push events for all transfer types?▼

No. Funding-wallet per-transfer status in v1beta is not pushed and must be polled via GET on the transfers endpoint. Classic wire transfers also lack a GET-by-id, so you must list outgoing transfers per account and match the ID client-side. Poll only non-terminal records.

Why is an Alpaca executed or COMPLETE status not final?▼

Journals can be reversed by cashiering and transfers can be RETURNED after appearing done, and corrections issue new journal IDs carrying the real funds. Keep reconciling past the apparent terminal state for a window and confirm money movement from terminal events or polls, never from the 200 create response.

How often should I run Alpaca reconciliation jobs?▼

Run a nightly heal job that pages through trade activities, non-trade activities, journals, and transfers for a moving window of recent days, upserting each record keyed on its Alpaca ID. The window absorbs corrections, late settlements, and events dropped during deploys without rescanning all history.