Alpaca Paper Live Key Separation 标志

Alpaca Paper Live Key Separation

社区
HimanshuJ16
alpaca-paper-live-key-separation

当机器人连接 Alpaca Trading API,且必须确保模拟环境密钥绝不用于实盘端点时使用;按环境固定基础 URL,检查密钥前缀,探测 /v2/account,并要求显式设置 ALLOW_LIVE_TRADING 标志。

Add to TypingMind

概览

发布者HimanshuJ16
代码仓库Algo-Trading-Skills
技能名称alpaca-paper-live-key-separation
星标数
50
复刻数
7
附带文件
5
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 5 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 HimanshuJ16 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Alpaca Paper Live Key Separation AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/alpaca-paper-live-key-separation
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/alpaca-paper-live-key-separation .claude/skills/alpaca-paper-live-key-separation
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Alpaca Paper Live Key Separation,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Alpaca Paper Live Key Separation。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Alpaca Paper Live Key Separation 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

When to Use

Invoke this whenever a bot connects to the Alpaca Trading API (or any broker with distinct paper/live environments). Connecting a paper strategy to Alpaca's live endpoint (https://api.alpaca.markets) using live API keys — or passing live order signals into a paper endpoint — is a catastrophic operational error. Pinning the base URL per environment, inspecting the key prefix, probing /v2/account for tradability, and requiring an explicit ALLOW_LIVE_TRADING environment variable are all mandatory before any order is submitted.

The base URL is the control that actually separates the environments. Alpaca serves paper accounts from https://paper-api.alpaca.markets and live accounts from https://api.alpaca.markets; a live account is not reachable through the paper host. Every other check in this skill is defence-in-depth layered on that pin — treat them as corroboration, never as a substitute.

When NOT to Use

  • Brokers without separate paper/live endpoints: If a single API base URL serves both environments and differentiation is done purely via credentials, this skill's URL-matching logic does not apply. Use broker-specific auth patterns instead (see headless-broker-auth-patterns).
  • Backtesting or simulation engines: When running historical replays or simulated fills with no network calls to a real broker API, environment segregation is irrelevant.
  • Non-Alpaca brokers with different credential schemes: The PK.../AK... prefix convention is Alpaca-specific. Brokers using different key formats (e.g., IBKR account IDs DU.../U...) require their own validation logic. For a broker-agnostic host allow-list, see sandbox-credential-leakage-prevention.
  • Read-only market data access: If the integration only consumes market data endpoints (not order routing), live capital loss is not a risk and the order guard is unnecessary.

Prerequisites

  • Distinct environment variable names for paper vs live credentials (e.g. ALPACA_PAPER_KEY_ID vs ALPACA_LIVE_KEY_ID).
  • Base URL configuration (https://paper-api.alpaca.markets for paper vs https://api.alpaca.markets for live).
  • Explicit ALLOW_LIVE_TRADING=true environment flag for live execution mode.

Workflow

  1. Load & Normalise the Environment Mode:

    • Coerce the configured environment into a known PAPER/LIVE value before any comparison. A value matching neither must raise, never fall through — an unrecognised mode that skips both branches is an authorisation, not a no-op.
  2. Inspect Credential Prefixes:

    • PK... indicates Alpaca paper credentials; AK... indicates live credentials.
    • Use this to reject a credential carrying the opposite environment's prefix. Do not require a positive prefix match: the convention is widely observed but is not documented by Alpaca, so an unrecognised key format must not be treated as proof of anything (see references/standards.md).
  3. Base URL & Mode Verification:

    • Match configuration mode against endpoint URLs:
      • PAPER mode → https://paper-api.alpaca.markets
      • LIVE mode → https://api.alpaca.markets
    • Match the exact URL against an allow-list, case-normalised. Anything else — including a look-alike host such as https://api.alpaca.markets.attacker.example — is rejected. Never use a substring or startswith test here.
  4. Live Execution Safety Gate (ALLOW_LIVE_TRADING):

    • Block initialization in LIVE mode unless ALLOW_LIVE_TRADING=true is explicitly set. Strip the value before comparing — a trailing newline from a .env loader should not silently block a legitimate live deployment.
    • Emit a WARNING when live trading is authorised, so the transition is visible in the log record.
  5. Account API Probe:

    • Issue GET /v2/account on startup and reject a response that is not a mapping.
    • Verify the account is tradable: status must be ACTIVE (or PAPER_ONLY, which is valid only in paper mode). A missing status is a veto, not an assumed ACTIVE.
    • Veto if any order-blocking flag is set: trading_blocked, account_blocked, or trade_suspended_by_user. Alpaca documents the first and last as "the account is not allowed to place orders" — a guard that ignores them authorises orders the broker will reject.
    • Resolve the environment only from signals that actually exist. GET /v2/account does not return an is_paper field (verified against Alpaca's account schema and the official alpaca-py TradeAccount model). Use, in order: an is_paper bool if your SDK wrapper injects one; status == "PAPER_ONLY"; an account_number beginning PA (observed, unofficial — treat as a positive paper signal only, never as proof an account is live).
    • If none of those resolve, the environment is undeterminable — log it and fall back on the already-verified base URL. Do not treat "undeterminable" as live: that vetoes every legitimate paper deployment, because the real API never supplies the field.
  6. Order Submission Veto Guard:

    • Wrap order routing calls in AlpacaEnvironmentManager.guard_order(), vetoing any outbound order if environment checks fail or key/URL mismatches occur.
    • Validate the order itself at the gate — reject a non-positive, non-finite, or non-numeric qty, an empty symbol, and any side outside buy/sell.

Full step-by-step procedure with broker-specific detail: see references/workflows.md. Broker/framework coverage table for this skill: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Hardcoding Base URLs: Hardcoding https://api.alpaca.markets in code and relying only on switching API keys in .env.
  • Shared Credential Variable Names: Using generic ALPACA_KEY_ID for both paper and live testing, leading to accidental live deployment.
  • Trusting a nonexistent is_paper field: Alpaca's /v2/account response has no is_paper key. Code written against it reads None on every call — so a guard that treats a missing value as live bricks paper trading, and one that treats it as paper waves live accounts through. Resolve the environment from fields the API really returns, and treat "unknown" as unknown.
  • Letting an unrecognised environment fall through: if mode == PAPER … elif mode == LIVE … with no else returns success for any third value, so a typo'd or foreign enum member authorises a live order with no ALLOW_LIVE_TRADING check. Normalise the mode up front and raise on anything unknown.
  • Defaulting a missing status to ACTIVE: A truncated or error-shaped account payload then reads as a healthy account. An unreadable account is a veto.
  • Ignoring the blocked flags: trading_blocked / account_blocked / trade_suspended_by_user mean the broker will refuse the order. Catching that locally turns a confusing broker rejection into a clear pre-trade veto.
  • Strict is True on a loosely-typed payload: An adapter that hands back "true"/"false" as strings defeats if account_data.get("trading_blocked") is True, so an explicitly blocked account reads as unblocked. Accept the string forms and fail closed on a value you cannot interpret.
  • Substring URL matching: base_url.startswith("https://api.alpaca.markets") also accepts https://api.alpaca.markets.attacker.example. Compare against an exact allow-list.
  • Missing Live Confirmation Flag: Allowing live trading without an explicit boolean environment variable guard (ALLOW_LIVE_TRADING=true).

Verification

  • Configure paper keys with the live URL and confirm AlpacaEnvironmentManager raises EnvironmentMismatchError.
  • Attempt live mode initialization without ALLOW_LIVE_TRADING=true and confirm execution is blocked.
  • Construct a config with an unrecognised environment value and confirm it raises rather than validating.
  • Simulate an account probe returning is_paper=False when configured in paper mode and confirm the startup veto.
  • Simulate a realistic paper payload with no is_paper field (status=ACTIVE, account_number=PA…) and confirm it is accepted, not vetoed.
  • Simulate trading_blocked=true and confirm the order guard vetoes.
  • Simulate a probe response with no status field and confirm the veto.
  • Submit qty=0, qty=NaN, and side="long" through guard_order() and confirm each is rejected.
  • Run the unit test suite python -m unittest discover -s skills/alpaca-paper-live-key-separation/scripts and confirm a 100% pass rate.

Related Skills

  • paper-to-live-promotion-checklist
  • headless-broker-auth-patterns
  • kill-switch-and-drawdown-circuit-breakers
  • sandbox-credential-leakage-prevention
  • sandbox-vs-production-endpoint-drift

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Alpaca Paper Live Key Separation AI 技能有什么作用?

当机器人连接 Alpaca Trading API,且必须确保模拟环境密钥绝不用于实盘端点时使用;按环境固定基础 URL,检查密钥前缀,探测 /v2/account,并要求显式设置 ALLOW_LIVE_TRADING 标志。

为什么在 TypingMind 中使用 Alpaca Paper Live Key Separation?

因为您只需安装一次,就能搭配任何模型使用。Alpaca Paper Live Key Separation 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Alpaca Paper Live Key Separation?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/alpaca-paper-live-key-separation。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Alpaca Paper Live Key Separation?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Alpaca Paper Live Key Separation 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Alpaca Paper Live Key Separation 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Alpaca Paper Live Key Separation AI 技能免费吗?

是的。HimanshuJ16 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇