AL

alpaca-broker-money-precision

Guide for managing financial data precision when working with the Alpaca API.

Install

mkdir -p .claude/skills/alpaca-broker-money-precision && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16679" && unzip -o skill.zip -d .claude/skills/alpaca-broker-money-precision && rm skill.zip

Installs to .claude/skills/alpaca-broker-money-precision

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

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 safe DB storage. Use when handling monetary amounts, order quantities, or prices in any Alpaca integration in any language.
318 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • Parse string money fields into a decimal type
  • Serialize decimal types back to strings
  • Round or truncate amounts before API calls
  • Store money in a database as fixed-point decimal
  • Track explicit currency for multi-currency transactions

How it works

This skill advises on converting string-based monetary values from Alpaca's API into decimal types for calculations and then back to strings for API transmission, avoiding floating-point precision issues.

Inputs & outputs

You give it
JSON string representing a monetary amount or quantity
You get back
Decimal type for calculations or a string for API transmission

When to use alpaca-broker-money-precision

  • Parse monetary strings
  • Perform decimal arithmetic for finance
  • Round prices for Alpaca
  • Store financial data

About this skill

Alpaca — Money & Numeric Precision

Financial bugs are silent and expensive. Alpaca's wire format and the realities of decimal arithmetic create a few specific traps. This skill is short, opinionated, and language-agnostic.

Read alpaca-broker-integration first.

1. Numbers come as strings — keep them that way

Alpaca returns prices, quantities, notional, and money amounts as JSON strings ("100.50", "1.5", "190.2345"), and accepts them as strings on the way in. This is deliberate: it avoids the precision loss of JSON's binary floats.

Rule: parse string money fields into a decimal type, never a binary float/double. Serialize back to a string. Don't let a number ever live as an IEEE-754 float in the money path.

LanguageUseAvoid
Pythondecimal.Decimal("100.50")float("100.50")
TypeScript/JSa decimal lib (decimal.js/big.js) or string arithmeticNumber(...), parseFloat
Goshopspring/decimalfloat64 for accumulation
Java/Kotlinjava.math.BigDecimaldouble

Real-world caveat: not every Alpaca endpoint is consistent — some market-data numeric fields come as JSON numbers (e.g. bar OHLC). Prices for display/analytics can tolerate floats; money you move or store must not. Know which field you're touching.

2. Round/truncate before sending — and know the direction

Alpaca generally accepts 2 decimal places for cash amounts and up to 9 for fractional share qty/notional. If you send more precision than allowed, you risk rejection or silent rounding on their side.

Rule: explicitly round/truncate to the target precision before the API call, using a deliberate rounding mode.

  • For money you're moving out / charging, truncate (round down) to 2 dp so you never move more than intended. (e.g. floor(amount * 100) / 100.)
  • Pick the rounding mode consciously (ROUND_DOWN vs ROUND_HALF_UP) — don't inherit whatever the default float formatting does.
  • Re-round after every arithmetic step that could reintroduce precision (e.g. computing amount * percentage for a split allocation), not just at the end.
# splitting a deposit across holdings — round each slice down, track remainder
slice = truncate(total * (pct / 100), 2)

3. Fractional shares

  • qty and notional support up to 9 decimal places.
  • qty XOR notional — never both (see alpaca-broker-trading-orders).
  • Don't reconstruct qty from notional / price and send it — pass notional and let Alpaca compute the fill. Round-tripping through a price you fetched introduces drift.

4. Storage

  • Store money in your DB as fixed-point decimal, not float. A practical pattern is generous precision/scale, e.g. DECIMAL(20, 8) — wide enough for multi-currency and fractional, with headroom beyond Alpaca's 2-dp cash so you never lose data you received.
  • Store what Alpaca sent verbatim alongside any converted/derived values. If you truncate to 2 dp for the API call but received more precision back, keep both — it makes reconciliation and audits possible.
  • Keep an explicit currency column; Alpaca is multi-currency on some rails (funding wallet) even though most is USD.

5. Multi-currency notes

  • Most Broker/trading flows are USD; journals default to USD.
  • The funding wallet rail supports many currencies (USD, EUR, JPY, …) and carries FX fees. When you touch it, never assume USD — read and store the currency, and treat FX amounts as decimals end-to-end.

6. Checklist

  • Money fields parsed from strings into a decimal type; serialized back to strings.
  • No binary floats anywhere in the move-money path.
  • Amounts rounded/truncated to the allowed precision before the call, with an intentional rounding mode (round down for outgoing money).
  • Re-round after each intermediate computation.
  • DB columns are fixed-point decimal with headroom; raw Alpaca values stored verbatim.
  • Explicit currency tracked.

Related skills: order qty/notional rules → alpaca-broker-trading-orders; journal/transfer amounts → alpaca-broker-journals, alpaca-broker-funding-transfers; reconciling stored vs Alpaca values → alpaca-broker-reconciliation-idempotency.

When not to use it

  • When handling market-data numeric fields that come as JSON numbers
  • When prices are for display or analytics and can tolerate floats

Limitations

  • Not every Alpaca endpoint is consistent; some market-data numeric fields come as JSON numbers.
  • Money for display/analytics can tolerate floats; money moved or stored must not.

How it compares

This approach explicitly manages numeric precision using decimal types and rounding rules, unlike generic number handling that might use binary floats and default rounding.

Compared to similar skills

alpaca-broker-money-precision side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
alpaca-broker-money-precision (this skill)01moNo flagsIntermediate
billing-automation102moNo flagsIntermediate
paypal-integration102moNo flagsIntermediate
ccxt-php16moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

billing-automation

wshobson

Build automated billing systems for recurring payments, invoicing, subscription lifecycle, and dunning management. Use when implementing subscription billing, automating invoicing, or managing recurring payment systems.

1098

paypal-integration

wshobson

Integrate PayPal payment processing with support for express checkout, subscriptions, and refund management. Use when implementing PayPal payments, processing online transactions, or building e-commerce checkout flows.

1090

ccxt-php

ccxt

CCXT cryptocurrency exchange library for PHP developers. Covers both REST API (standard) and WebSocket API (real-time). Helps install CCXT, connect to exchanges, fetch market data, place orders, stream live tickers/orderbooks, handle authentication, and manage errors in PHP 8.1+. Use when working with crypto exchanges in PHP projects, trading bots, or web applications. Supports both sync and async (ReactPHP) usage.

18

openrouter-cost-controls

jeremylongshore

Implement budget controls and cost limits for OpenRouter. Use when managing spending or preventing overruns. Trigger with phrases like 'openrouter budget', 'openrouter spending limit', 'cost control', 'openrouter billing alert'.

05

plaid-fintech

davila7

Expert patterns for Plaid API integration including Link token flows, transactions sync, identity verification, Auth for ACH, balance checks, webhook handling, and fintech compliance best practices. Use when: plaid, bank account linking, bank connection, ach, account aggregation.

32

ccxt-csharp

ccxt

CCXT cryptocurrency exchange library for C# and .NET developers. Covers both REST API (standard) and WebSocket API (real-time). Helps install CCXT, connect to exchanges, fetch market data, place orders, stream live tickers/orderbooks, handle authentication, and manage errors in .NET projects. Use when working with crypto exchanges in C# applications, trading systems, or financial software. Supports .NET Standard 2.0+.

13

Search skills

Search the agent skills registry