alpaca
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAlpaca
Alpaca
<!-- BEGIN:skill-intro -->
Tools for trading on Alpaca against the Trading API: place and manage stock, crypto, and options orders; read account balances, positions, portfolio history, and activities; look up assets, market hours, and option contracts; and read watchlists. 25 scripts across account, orders, positions, assets, options, and watchlists. Trades run against Alpaca's paper (simulated) environment by default; live real-money trading requires an explicit opt-in (see Auth). Money and quantity values are returned as strings to preserve decimal precision — never coerce them to numbers. Order placement is async-confirmed: acknowledges receipt with a status that can change server-side, so re-query before asserting a fill.
<!-- legal:disclaimer -->
placeOrdergetOrderIndependent, unofficial connector for Alpaca. Not affiliated with, endorsed by, or sponsored by Alpaca. "Alpaca" is a trademark of its owner, used only to identify the service this connector works with.
<!-- /legal:disclaimer -->
<!-- END:skill-intro --><!-- BEGIN:skill-intro -->
基于Alpaca Trading API的交易工具:下单及管理股票、加密货币和期权订单;查看账户余额、持仓、投资组合历史和交易活动;查询资产、市场营业时间和期权合约;以及读取观察列表。涵盖账户、订单、持仓、资产、期权和观察列表的25个脚本。默认情况下,交易在Alpaca的模拟(paper)环境中运行;实盘交易需要明确选择开通(参见认证部分)。金额和数量值以字符串形式返回,以保留小数精度——切勿将其强制转换为数字。下单采用异步确认机制:仅确认接收订单,订单状态可能在服务器端发生变化,因此在确认成交前需重新调用查询。
<!-- legal:disclaimer -->
placeOrdergetOrder本工具为Alpaca的独立非官方连接器,与Alpaca无关联、未获其认可或赞助。“Alpaca”是其所有者的商标,仅用于标识本连接器适配的服务。
<!-- /legal:disclaimer -->
<!-- END:skill-intro -->When to use this
使用场景
<!-- BEGIN:skill-use-cases -->
- Inspect the account — read balances and buying power, list open positions and unrealized P&L, review portfolio history and account activities (fills, dividends, fees), or check whether the market is open.
- Place and manage orders — buy or sell stocks, crypto, or options (market/limit/stop/bracket/OCO/OTO/multi-leg); replace or cancel open orders; close or liquidate positions; exercise an options position.
- Look things up — resolve a symbol's tradability/shortability/fractionability, list assets or option contracts, and read watchlists.
<!-- BEGIN:skill-use-cases -->
- 账户查询——查看账户余额、购买力,列出未平仓持仓及未实现盈亏,回顾投资组合历史和账户活动(成交、分红、手续费),或检查市场是否开市。
- 订单管理——买卖股票、加密货币或期权(市价/限价/止损/括号订单/OCO/OTO/多腿期权);修改或取消未成交订单;平仓或清算持仓;行权期权持仓。
- 信息查询——确认标的代码的可交易性/可卖空性/可拆分性,列出资产或期权合约,以及读取观察列表。
Setup
安装配置
This is an agentskills.io skill.
If the connector has not been installed as a skill yet, install it first with (or your harness's own skill-install mechanism), then continue here. Installing the skill copies these files, not dependencies. Before running the CLI, a local MCP server, or auth commands, run here once. Importing the published package as a dependency in your own project instead? That already resolves everything — see .
npx skills add zapier/connectors --skill alpacazapier-sdknpm install --omit=devnpm installreferences/use-as-sdk.mdThe connector runs on Node.js 22.18+. Pick the reference that matches how you're running it, and load it before doing anything else:
| You have... | Load |
|---|---|
An MCP-aware client — tools may already be loaded (e.g. | |
Terminal / subprocess access (you can run | |
| Only your own code, importing this package as a dependency | |
| No tool access, no terminal, no ability to import this package — you write your own code that calls the Alpaca API directly (e.g. a code-execution sandbox) | |
这是一款agentskills.io工具。
如果尚未将该连接器作为工具安装,请先执行进行安装(或使用您的工具管理机制),然后继续后续步骤。安装工具仅复制这些文件,不包含依赖项。运行CLI、本地MCP服务器或认证命令前,请在此目录执行一次。若您的项目是通过导入已发布包作为依赖项,则已解决所有依赖问题——详见。
npx skills add zapier/connectors --skill alpacazapier-sdknpm install --omit=devnpm installreferences/use-as-sdk.md该连接器运行于**Node.js 22.18+**环境。请根据您的运行方式选择对应的参考文档,并在操作前加载:
| 运行环境 | 参考文档 |
|---|---|
支持MCP的客户端——工具可能已加载(例如 | |
可访问终端/子进程(能运行 | |
| 仅使用自有代码,通过导入包作为依赖项 | |
| 无工具访问权限、无终端、无法导入包——需自行编写调用Alpaca API的代码(例如代码执行沙箱) | |
Scripts
脚本列表
<!-- BEGIN:skill-connections-note? -->
<!-- END:skill-scripts-table -->
<!-- BEGIN:disambiguation-and-refusals? -->
All scripts use the single connection . Trading tools hit the paper host by default (live requires an opt-in — see Auth).
<!-- END:skill-connections-note -->
<!-- BEGIN:skill-scripts-table -->
alpaca| Script | Script name | Connections | Description |
|---|---|---|---|
| | | Get account balances, buying power, equity, and trading-permission flags. |
| | | Get the account's trading configuration flags. |
| | | Get the account's equity and P&L time series over a period. |
| | | List account activities — fills, dividends, fees, transfers — by type and date. |
| | | Place an order to buy or sell a stock, crypto pair, or option. |
| | | Replace (modify) an open order's quantity, price, or time-in-force. |
| | | Cancel one open order by id. |
| | | Attempt to cancel every open order (per-order status list). |
| | | List orders, filtered by status, symbols, or side. |
| | | Get one order by id, including status and fill details. |
| | | Get one order by the client_order_id you assigned. |
| | | List all open positions with market value, cost basis, and P&L. |
| | | Get one open position by symbol or asset id. |
| | | Close (liquidate) one position, fully or partially. |
| | | Liquidate every open position (optionally cancel open orders first). |
| | | Exercise a held options position by option symbol or contract id. |
| | | List tradable assets, filtered by class, status, or exchange. |
| | | Get one asset by symbol, asset id, or CUSIP (tradability flags). |
| | | Get the market clock — is it open now, and the next open/close. |
| | | Get market trading days with open/close times over a date range. |
| | | List option contracts for underlyings, filtered by expiration/type/strike. |
| | | Get one option contract by OCC symbol or contract id. |
| | | List the account's watchlists. |
| | | Get one watchlist by id, including its asset symbols. |
| | | Get one watchlist by name, including its asset symbols. |
<!-- BEGIN:skill-connections-note? -->
<!-- END:skill-scripts-table -->
<!-- BEGIN:disambiguation-and-refusals? -->
所有脚本均使用单一连接。交易工具默认访问模拟环境(实盘交易需选择开通——参见认证部分)。
<!-- END:skill-connections-note -->
<!-- BEGIN:skill-scripts-table -->
alpaca| 脚本 | 脚本名称 | 连接配置 | 描述 |
|---|---|---|---|
| | | 获取账户余额、购买力、权益和交易权限标识。 |
| | | 获取账户的交易配置标识。 |
| | | 获取账户在一段时间内的权益和盈亏时间序列。 |
| | | 按类型和日期列出账户活动——成交、分红、手续费、转账等。 |
| | | 下单买卖股票、加密货币对或期权。 |
| | | 修改未成交订单的数量、价格或有效期限。 |
| | | 根据ID取消单个未成交订单。 |
| | | 尝试取消所有未成交订单(返回每个订单的状态列表)。 |
| | | 按状态、标的代码或买卖方向筛选订单列表。 |
| | | 根据ID获取单个订单,包括状态和成交详情。 |
| | | 根据您分配的client_order_id获取单个订单。 |
| | | 列出所有未平仓持仓,包含市值、成本基准和盈亏。 |
| | | 根据标的代码或资产ID获取单个未平仓持仓。 |
| | | 平仓(清算)单个持仓,可全部或部分平仓。 |
| | | 清算所有未平仓持仓(可选择先取消未成交订单)。 |
| | | 根据期权代码或合约ID行权持有的期权持仓。 |
| | | 按类别、状态或交易所筛选可交易资产列表。 |
| | | 根据标的代码、资产ID或CUSIP获取单个资产(包含可交易标识)。 |
| | | 获取市场时钟——当前是否开市,以及下一次开市/闭市时间。 |
| | | 获取一段时间内的市场交易日及开市/闭市时间。 |
| | | 按到期日/类型/行权价筛选标的资产的期权合约列表。 |
| | | 根据OCC代码或合约ID获取单个期权合约。 |
| | | 列出账户的观察列表。 |
| | | 根据ID获取单个观察列表,包含其资产标的代码。 |
| | | 根据名称获取单个观察列表,包含其资产标的代码。 |
Disambiguation & refusals
歧义处理与拒绝规则
Disambiguation before a write. Trade and position tools key on an exact symbol or id, not a company name. Before acting on something the user named loosely:
- Symbols / assets — if the user gives a company name ("Apple") rather than a ticker, resolve it first with or
getAsset. If exactly one asset matches, act on it; if several plausibly match, list them (symbol + name + exchange) and ask which. Never guess a ticker.listAssets - Watchlists — resolve by name with or
getWatchlistByName. Names are unique per account, so one exact (case-insensitive) match is the answer — act on it, don't over-ask. If nothing matches, say so. This connector reads watchlists but does not create or modify them (see Unsupported operations).listWatchlists - Orders / positions — take an or
order_idthe user already has (fromsymbol/listOrders). If they describe an order vaguely ("cancel my Tesla order"), list the candidates first and confirm before canceling.listPositions
Unsupported operations — say so and stop; don't fake it with another tool. This connector deliberately does not:
- Move money — no deposits, withdrawals, transfers, bank links, or funding. Those live on Alpaca's Broker API and are out of scope.
- Read market data — quotes, bars, snapshots, news, corporate actions, and option chains are out of scope. This connector wraps Alpaca's Trading API only, not the Market Data API (); there are no price/history or streaming tools.
data.alpaca.markets - Create or modify watchlists, or change account configuration — this connector reads watchlists (/
listWatchlists/getWatchlist) and account settings (getWatchlistByName) but does not create, update, or delete them.getAccountConfigurations - Trade against a live account by default — trading is paper (simulated) unless the user has explicitly enabled live (see Auth). If asked to trade real money, confirm live is enabled rather than assuming.
- Manage the stock screener, OAuth apps, or account documents — not exposed.
If asked for any of these, tell the user it's unsupported and stop — don't substitute an unrelated tool and report success for an action you didn't perform.
<!-- END:disambiguation-and-refusals -->写入操作前的歧义处理。交易和持仓工具依赖精确的标的代码或ID,而非公司名称。当用户给出模糊名称时:
- 标的代码/资产——若用户给出公司名称(如“Apple”)而非代码,需先通过或
getAsset解析。若仅匹配到一个资产,则直接操作;若匹配到多个可能资产,则列出它们(代码+名称+交易所)并询问用户选择。切勿猜测标的代码。listAssets - 观察列表——通过或
getWatchlistByName按名称解析。每个账户的名称是唯一的,不区分大小写,匹配到一个结果即可直接操作,无需额外询问。若无匹配结果,告知用户即可。本连接器仅读取观察列表(参见不支持的操作),不支持创建或修改。listWatchlists - 订单/持仓——使用用户已获取的或
order_id(来自symbol/listOrders)。若用户模糊描述订单(如“取消我的特斯拉订单”),需先列出候选订单并确认后再取消。listPositions
**不支持的操作——直接告知用户并终止操作;切勿用其他工具替代。**本连接器明确不支持以下操作:
- 资金转移——不支持存款、取款、转账、银行链接或资金存入。这些属于Alpaca的Broker API范畴,不在本工具范围内。
- 市场数据读取——报价、K线、快照、新闻、公司行动和期权链均不在范围内。本连接器仅封装Alpaca的Trading API,不包含Market Data API();无价格/历史或流数据工具。
data.alpaca.markets - 创建或修改观察列表、更改账户配置——本连接器仅读取观察列表(/
listWatchlists/getWatchlist)和账户设置(getWatchlistByName),不支持创建、更新或删除。getAccountConfigurations - 默认实盘交易——默认使用模拟交易,实盘交易需用户明确开通(参见认证部分)。若用户要求实盘交易,需确认已开通实盘权限,切勿默认假设。
- 股票筛选器、OAuth应用或账户文档管理——未开放此类功能。
若用户请求上述操作,告知用户不支持并终止操作——切勿用无关工具替代并虚假报告操作成功。
<!-- END:disambiguation-and-refusals -->Auth
认证
Every shape passes auth as one connection selector, not the secret — a string. Every connector accepts (Zapier-managed auth — routes through Zapier's auth, retries, and governance layer); some also accept one or more direct-token resolvers (naming and count vary per connector) — check this connector's own resolvers rather than assuming. The prefix is optional; a bare value goes to the first resolver that claims it — a UUID-shaped bare value always claims . Each script declares the connections it needs and the resolvers each accepts. The exact syntax for passing a connection (and how to see this connector's resolver list) differs by shape — see the reference you loaded above.
[<resolver>:]<value>zapier:<connection-id><resolver>:zapier:Checking what's already configured first? Don't dump environment values to do it — or prints the value along with the name, leaking a live credential into the transcript if one is set. Check names only () or test a known name directly ().
<!-- BEGIN:skill-auth-notes -->
envenv | grep <name>env | cut -d= -f1 | grep -i <name>[ -n "$VAR_NAME" ]Zapier-managed auth () is experimental for Alpaca — the direct resolver () is the verified path.
<!-- END:skill-auth-notes -->
zapier:<connection-id>alpaca:<PREFIX>No connection yet? Pick one — and follow the reference's own flow to obtain it; never just ask the user for a connection id or token as if they already have one memorized:
| Load | |
|---|---|
| Pass the credential directly | |
| Route it through a Zapier connection | |
所有操作均通过一个连接选择器传递认证信息,而非密钥——格式为字符串。每个连接器均接受(Zapier托管的认证——通过Zapier的认证、重试和治理层路由);部分连接器还支持一种或多种直接令牌解析器(命名和数量因连接器而异)——请查看本连接器的解析器列表,切勿假设。前缀为可选;无前缀的值将匹配第一个可处理的解析器——UUID格式的值默认匹配。每个脚本都会声明所需的连接及支持的解析器。传递连接的具体语法(以及查看本连接器解析器列表的方式)因运行环境而异——请查看您加载的参考文档。
[<resolver>:]<value>zapier:<connection-id><resolver>:zapier:想要检查已配置的内容?切勿直接打印环境变量——或会同时打印名称和值,若包含实盘凭证则会泄露。仅检查名称()或直接测试已知名称()。
<!-- BEGIN:skill-auth-notes -->
envenv | grep <name>env | cut -d= -f1 | grep -i <name>[ -n "$VAR_NAME" ]Zapier托管的认证()针对Alpaca仍处于实验阶段——直接解析器()为已验证的方式。
<!-- END:skill-auth-notes -->
zapier:<connection-id>alpaca:<PREFIX>尚未配置连接?请选择一种方式,并按照参考文档的流程获取连接——切勿直接向用户索要连接ID或令牌,假设他们已记住这些信息:
| 方式 | 参考文档 |
|---|---|
| 直接传递凭证 | |
| 通过Zapier连接路由 | |
Output format
输出格式
Every script returns a envelope:
{ data, meta }- — the script's result (the shape its
datadeclares; see the reference you loaded above for how to inspect a script's exact schema in your shape).outputSchema - — what validating
meta.outputDataValidationdid:data- — validated, nothing removed.
{ skipped: false, droppedPaths: null } - — validated, but those paths were stripped from
{ skipped: false, droppedPaths: [...], instruction }: fields the script returned from the API that thedatadoesn't declare. If you need them, re-run with output validation skipped.outputSchema - — validation was bypassed;
{ skipped: true }is the raw, unchecked script output.data
Reading dropped fields / . To receive the raw, unvalidated result, opt out of output validation (the exact syntax differs by shape — see the reference you loaded above). Input validation is never skipped.
skipOutputDataValidationTrimming the result / . To shrink a large result down to the fields you need, pass a jq expression that post-processes (again, exact syntax per shape). The jq runs against only, NOT the envelope, so write it rooted at (run the script's — or your shape's equivalent — to see its output schema). The transformed value replaces , is preserved, and the result is NOT re-validated against the output schema.
<!-- BEGIN:skill-references-table -->filterOutputDatadatadata{ data, meta }data--helpdatameta每个脚本均返回格式的结果:
{ data, meta }- ——脚本的执行结果(符合其
data定义的结构;请查看您加载的参考文档,了解如何在您的环境中查看脚本的精确输出 schema)。outputSchema - ——对
meta.outputDataValidation的验证结果:data- ——已验证,无内容移除。
{ skipped: false, droppedPaths: null } - ——已验证,但
{ skipped: false, droppedPaths: [...], instruction }中的部分路径被移除:脚本从API返回的字段未在data中声明。若需要这些字段,请跳过输出验证重新运行。outputSchema - ——已跳过验证;
{ skipped: true }为脚本的原始未校验输出。data
读取被移除的字段 / 。若要接收原始未校验结果,请选择跳过输出验证(具体语法因运行环境而异——请查看您加载的参考文档)。输入验证无法跳过。
skipOutputDataValidation结果精简 / 。若要精简大型结果至所需字段,请传入一个jq表达式对进行后处理(语法因运行环境而异)。jq仅针对运行,而非整体,因此表达式需以为根(运行脚本的或您环境中的等效命令查看输出schema)。转换后的值将替换,保留不变,且结果不会重新校验输出schema。
<!-- BEGIN:skill-references-table -->filterOutputDatadatadata{ data, meta }data--helpdatametaReferences
参考文档
Load the matching reference file before working in that area:
| Reference | Covers | Load it when |
|---|---|---|
| Alpaca API behavior the schemas don't capture: auth & paper/live hosts, the | Load before placing, replacing, or canceling orders; closing or exercising positions; or whenever a call returns an unexpected HTTP status or error code |
在对应场景工作前,请加载匹配的参考文档:
| 参考文档 | 涵盖内容 | 加载时机 |
|---|---|---|
| Alpaca API的特殊行为(未在schema中体现):认证与模拟/实盘环境、 | 在下单、修改或取消订单;平仓或行权持仓;或调用返回意外HTTP状态码或错误信息时加载 |