alpaca-broker-money-precision-zcg3

Skill for Alpaca brokerage amount precision, helping an AI Agent efficiently perform tasks related to handling monetary precision for the Alpaca brokerage.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "alpaca-broker-money-precision-zcg3" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-a255348c444ecdbe79728c820c584e365d6ee645421bdd5ebd0b3125dfd6b0e0. Verify the upstream source and version against https://skillhub.cn/skills/user_3c6cb52e/alpaca-broker-money-precision-zcg3 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Skill for Alpaca brokerage amount precision, helping an AI Agent efficiently perform tasks related to handling monetary precision for the Alpaca brokerage.

0 Downloads

Introduction source: third_party · user_3c6cb52e · 1.0.0 Reference

SkillPi interpretation

Tasks
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.
Audience
Not specified in the source documentation.
Inputs and outputs
Not specified in the source documentation.
Software, accounts and paid services
Not specified in the source documentation.
Limits and differences
Not specified in the source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: Alpaca券商金额精度
slug: alpaca-broker-money-precision
version: 1.0.0
displayName: Alpaca券商金额精度
description: >
  Alpaca券商金额精度专用技能,帮助AI Agent高效完成相关任务。
summary: "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..."
license: MIT
category: 量化交易
framework:
  - Claude Code
  - Codex
  - Hermes Agent
  - OpenClaw
  - QClaw
  - WorkBuddy
platform: multi-platform
homepage: https://github.com/1991513ccie-png
repository: https://github.com/1991513ccie-png

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.

Language Use Avoid
Python decimal.Decimal("100.50") float("100.50")
TypeScript/JS a decimal lib (decimal.js/big.js) or string arithmetic Number(...), parseFloat
Go shopspring/decimal float64 for accumulation
Java/Kotlin java.math.BigDecimal double

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.

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 针对 Alpaca 券商金额精度问题,提供专业的数值处理规范,解决金融场景下的核心痛点
  • 涵盖 decimal vs float、精度控制、舍入策略、存储建议等关键内容,实用性强
Trigger Precision75/100

Areas to improve

  • description写错位置 Reported severity: Minor

    frontmatter 中 description 字段为空,实质描述内容位于 skill_body 内部

    Recommendation: 建议将核心描述移至 frontmatter 的 description 字段,以便平台正确识别触发条件

Highlights

  • description 明确指出 'Alpaca券商金额精度专用技能',触发词精准
Structure and Standards80/100

Areas to improve

  • 缺少When to Use章节 Reported severity: Minor

    文档结构清晰但未提供显式的 'When to Use' 使用场景说明

    Recommendation: 建议增加 'When to Use' 章节,明确说明适用场景和触发条件

Highlights

  • 文档结构清晰,分 6 个章节,每节有具体规则、代码示例、表格对比
  • frontmatter 完整,单文件未超长
Execution Reliability75/100

Areas to improve

  • 工具来源未明确说明 Reported severity: Minor

    提供了多语言实现建议但未明确说明工具来源(如 decimal.js 的版本或安装方式)

    Recommendation: 建议补充关键工具库的来源、版本或安装说明,提升执行可靠性

Highlights

  • 提供了多语言的具体实现建议(Python decimal、JS decimal.js、Go shopspring/decimal、Java BigDecimal)
  • 覆盖了主要异常场景(精度超限、舍入方向、存储类型)
Evidence Verifiability (mean of the first four)79/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • github.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Not specified in the source documentation.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.