alpaca-broker-rate-limits-resilience-sh-phsy92
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "alpaca-broker-rate-limits-resilience-sh-phsy92":https://skillpi.com/zh/skills/deepskill-043964f33ca36b2eb5d65b7409905b09336d0b9de55dac5835d0482e4ee99ffa。安装前核对上游来源和版本:https://skillhub.cn/skills/user_3c6cb52e/alpaca-broker-rate-limits-resilience-sh-phsy92。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
专用于 Alpaca 券商限频与韧性处理的 Skill,帮助 AI Agent 应对速率限制并提高任务执行的鲁棒性与恢复能力。
介绍来源: third_party · user_3c6cb52e · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 适合谁
- 来源文档未说明。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: Alpaca券商限频与韧性
slug: alpaca-broker-rate-limits-resilience
version: 1.0.0
displayName: Alpaca券商限频与韧性
description: >
Alpaca券商限频与韧性专用技能,帮助AI Agent高效完成相关任务。
summary: "Alpaca券商限频与韧性专用技能,帮助AI Agent高效完成相关任务。"
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 — Rate Limits & Resilience
Alpaca's APIs are rate-limited and occasionally flaky under load. Any client that does more than a handful of calls — especially bulk jobs, backfills, and reconciliation sweeps — needs disciplined retry, backoff, and concurrency control. These patterns are transport-level and apply in any language.
Read
alpaca-broker-integrationfirst.
1. Rate-limit headers — read them on every response
Alpaca returns standard headers:
| Header | Meaning |
|---|---|
X-RateLimit-Limit |
requests allowed in the window |
X-RateLimit-Remaining |
requests left in the current window |
X-RateLimit-Reset |
unix timestamp (seconds) when the window resets |
Parse them on every response, not just on errors. Two uses:
- Proactive: when
Remainingdrops below a threshold (e.g. ≤ 50), log a warning and/or slow down — you're about to get throttled. - Reactive: on
429, useResetto wait exactly until the window opens.
Limits vary by endpoint and plan; market-data limits differ from broker limits. Don't hardcode a number — react to the headers.
2. The retry loop (pseudocode)
MAX_ATTEMPTS = 10
INITIAL_DELAY_MS = 1000
for attempt in 1..MAX_ATTEMPTS:
res = http(request) # with a sane timeout (see §5)
remaining, reset_at = parse_rate_headers(res.headers)
if remaining <= 50: log_warn("approaching rate limit", reset_at)
if res.status == 429:
# wait until the window resets, plus a small buffer
wait = (reset_at - now()) if reset_at else INITIAL_DELAY_MS * 2^(attempt-1)
sleep(max(0, wait) + 1000) # +1s buffer past reset
continue
if res.status in (500, 502, 503, 504) or network_error:
sleep(INITIAL_DELAY_MS * 2^(attempt-1)) # exponential backoff
continue
return res # success or non-retryable 4xx
raise last_error
Key points:
- On
429, wait untilX-RateLimit-Reset+ a ~1s buffer — don't blindly exponential-backoff when the API told you exactly when to retry. - Exponential backoff (
base * 2^(attempt-1)) for network errors and 5xx. With base 1s and 10 attempts the tail is minutes — fine for background jobs, too slow for user-facing calls (use fewer attempts there). - Don't retry non-retryable 4xx (
400/403/422) — those won't fix themselves; surface them. - Optionally add jitter to backoff to avoid thundering-herd when many workers retry together.
3. Bounded concurrency
Parallelism speeds bulk jobs but is the fastest way to hit limits. Use a fixed worker pool, not unbounded fan-out.
- Start small (e.g. 5–8 concurrent requests) and tune against the rate-limit headers. A real lesson from production: a pool was reduced from 10 → 5 to ease both Alpaca and downstream-DB load.
- Cache per-entity reads within a run (e.g. an account's buying power, or a per-account transfer list) so you don't refetch the same thing across items in a batch.
- For per-item throttling, a small fixed sleep between calls (e.g. 100ms) is a crude-but-effective floor when you can't easily coordinate a pool.
4. Pagination loops
List endpoints page forward with a token — never assume one response is complete.
- Activities (
/v1/accounts/activities): page via theX-Next-Page-Tokenresponse header; loop until it's empty. Usepage_size(≤100) and adirection. - Market-data bars (
/v2/stocks/bars): page vianext_page_tokenin the body → pass back aspage_token. Rememberlimitcounts across all symbols and results sort by symbol-then-time, so a single page may contain only the first symbol(s) — keep paging. - Wrap each page fetch in the retry loop from §2.
token = null
loop:
page = fetch(url + (token ? "&page_token="+token : "")) # via retry loop
accumulate(page.items)
token = page.next_token # header or body, per endpoint
if not token: break
5. Timeouts & batch sizing
- Always set an HTTP timeout (e.g. 15–30s). A hung connection without a timeout stalls a whole worker pool. (SSE streams are the exception — they're meant to stay open; see
alpaca-broker-sse-events.) - Use a shared HTTP client / connection pool rather than constructing one per request, so keep-alive and connection reuse work.
- When writing reconciliation results to your own store, chunk bulk inserts (e.g. 500 rows per statement) to stay under DB statement-size limits and keep transactions reasonable.
6. Resilience checklist for a bulk/cron job
- [ ] Rate-limit headers parsed every response; proactive warn near the limit.
- [ ]
429→ wait untilX-RateLimit-Reset+ buffer. - [ ] Exponential backoff (+ jitter) for 5xx/network; capped attempts.
- [ ] Non-retryable 4xx surfaced, not retried.
- [ ] Bounded worker pool; per-run caching of repeated reads.
- [ ] Pagination loop until the token is empty.
- [ ] HTTP timeout on every call; shared client.
- [ ] Bulk DB writes chunked and idempotent (upsert) — see
alpaca-broker-reconciliation-idempotency. - [ ] Structured logging with a trace/correlation ID per item for debugging partial failures.
Related skills: safe re-runs of jobs → alpaca-broker-reconciliation-idempotency; the heal/poll jobs that use these patterns → alpaca-broker-reconciliation-idempotency; market-data pagination specifics → alpaca-broker-market-data.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Alpaca 券商 API 限频与韧性处理方案,直接解决量化交易中的核心痛点
- 内容详实,涵盖限频头解析、重试机制、并发控制、分页循环等关键场景
待提升项
-
触发词不全 原报告严重程度:重大
description 仅描述了 Skill 的用途,但未提供具体的触发词或触发条件,用户难以准确判断何时调用该 Skill。
改进建议:建议在 description 或 skill_body 开头补充明确的触发词,例如:'当需要处理 Alpaca API 限频、重试、并发控制或分页时调用此 Skill'。
待提升项
-
缺少 When to Use/示例章节 原报告严重程度:轻微
Skill 结构清晰,但缺少明确的 When to Use 章节和端到端的完整示例,用户可能难以快速理解适用场景。
改进建议:建议在 skill_body 开头增加 When to Use 章节,说明适用场景(如批量作业、回填、对账扫描等),并提供一个端到端的完整示例。
亮点
- 结构清晰,包含多个逻辑章节和详细的伪代码示例
- 提供了完整的韧性检查清单,便于用户逐项验证
亮点
- 提供了详细的限频处理逻辑和重试机制,覆盖主要异常场景
- 强调了非可重试 4xx 的处理,避免无效重试
- 提供了并发控制和分页循环的最佳实践
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- github.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。