pear-protocol
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese🍐 Pear Protocol — Headless (agent wallet)
🍐 Pear Protocol — 无头(Agent钱包)
Pair/basket trading on top of Hyperliquid: open a long and a short leg as one
synthetic position. This skill uses HEADLESS auth only — the agent's own
Privy wallet signs a SIWE login against the V3 gateway; no browser, no OAuth,
no user interaction. Works out of the box for any Starchild agent.
在Hyperliquid之上进行配对/篮子交易:将做多和做空两个仓位作为一个合成仓位开立。本技能仅使用无头认证——Agent自有Privy钱包针对V3网关签署SIWE登录信息;无需浏览器、无需OAuth、无需用户交互。适用于任何Starchild Agent,开箱即用。
Endpoints
端点
- V3 gateway (REST):
https://pro-gateway.pearprotocol.io - Orchard MCP: (streamable HTTP, stateless — accepts
https://mcp.pearprotocol.io/mcpdirectly; docs: https://docs.pear.garden)x-api-key
- V3网关(REST):
https://pro-gateway.pearprotocol.io - Orchard MCP: (可流式传输的HTTP,无状态——直接接受
https://mcp.pearprotocol.io/mcp;文档:https://docs.pear.garden)x-api-key
Auth — scripts/gateway.py
(use this, don't hand-roll curl)
scripts/gateway.py认证 — scripts/gateway.py
(请使用此脚本,不要手动编写curl命令)
scripts/gateway.pybash
python3 skills/pear-protocol/scripts/gateway.py login # SIWE login w/ agent wallet, caches tokens
python3 skills/pear-protocol/scripts/gateway.py status # identity + token validity
python3 skills/pear-protocol/scripts/gateway.py ensure-key # mint PEAR_API_KEY into .env (once)
python3 skills/pear-protocol/scripts/gateway.py markets --limit 15
python3 skills/pear-protocol/scripts/gateway.py get /trade-accounts
python3 skills/pear-protocol/scripts/gateway.py post <path> '<json>' # writes; auto BearerFlow: → (EIP-191;
gateway accepts the smart-wallet address even though personal_sign recovers to
the underlying EOA — no EIP-1271 issue) → → (JWT ~15 min,
auto-refresh/re-login). Tokens cached in
(0600). Single-flight nonce→login: concurrent nonce requests rotate the nonce
and 401 the earlier signature.
POST /auth/nonce {address}wallet.wallet_sign(message)POST /auth/login {method:"wallet",address,signature}accessTokenworkspace/.pear/gateway_tokens.jsonbash
python3 skills/pear-protocol/scripts/gateway.py login # 使用Agent钱包进行SIWE登录,缓存令牌
python3 skills/pear-protocol/scripts/gateway.py status # 身份信息 + 令牌有效性
python3 skills/pear-protocol/scripts/gateway.py ensure-key # 将PEAR_API_KEY写入.env文件(仅需执行一次)
python3 skills/pear-protocol/scripts/gateway.py markets --limit 15
python3 skills/pear-protocol/scripts/gateway.py get /trade-accounts
python3 skills/pear-protocol/scripts/gateway.py post <path> '<json>' # 写入操作;自动添加Bearer令牌流程: → (EIP-191;网关接受智能钱包地址,即使personal_sign恢复到底层EOA——无EIP-1271问题)→ → (JWT,有效期约15分钟,自动刷新/重新登录)。令牌缓存于(权限0600)。单次流程:nonce请求→登录:并发nonce请求会轮换nonce并使较早的签名返回401。
POST /auth/nonce {address}wallet.wallet_sign(message)POST /auth/login {method:"wallet",address,signature}accessTokenworkspace/.pear/gateway_tokens.jsonWhich credential for which call
不同调用对应的凭证
| Call type | Auth | Notes |
|---|---|---|
| Gateway reads (markets, funding) | | persistent, read scope |
| Gateway writes (orders, trade-accounts) | | api_key → 403; gateway.py auto-refreshes |
| Account-scoped calls | + | mandatory once >1 account |
| MCP server | | gateway wallet Bearer is REJECTED on MCP (different token type) |
- REQUIRES
GET /markets(291 markets: price, funding, OI, 24h vol/change).?connector=hyperliquid
| 调用类型 | 认证方式 | 说明 |
|---|---|---|
| 网关读取操作(市场、资金费率) | | 持久有效,仅读取权限 |
| 网关写入操作(订单、交易账户) | | 使用api_key会返回403;gateway.py会自动刷新令牌 |
| 账户范围调用 | + | 当存在多个账户时为必填项 |
| MCP服务器 | 直接使用 | 网关钱包的Bearer令牌在MCP上会被拒绝(令牌类型不同) |
- 必须携带
GET /markets参数(共291个市场:价格、资金费率、持仓量、24小时成交量/涨跌幅)。?connector=hyperliquid
API-key scopes gate the MCP tool surface
API密钥权限管控MCP工具范围
POST /api-keys{"label": "...", "scope": "read"|"read_write"}labelnameread_writeConvention: store the read key as and (if trading) a
read_write key as in workspace/.env. For MCP trading,
export before calling .
PEAR_API_KEYPEAR_API_KEY_RWPEAR_API_KEY=$PEAR_API_KEY_RWpear_mcp.pyPOST /api-keys{"label": "...", "scope": "read"|"read_write"}labelnameread_write约定:将只读密钥存储为中的,若需交易则将读写密钥存储为。对于MCP交易,在调用前导出。
.envPEAR_API_KEYPEAR_API_KEY_RWpear_mcp.pyPEAR_API_KEY=$PEAR_API_KEY_RWMCP client — scripts/pear_mcp.py
scripts/pear_mcp.pyMCP客户端 — scripts/pear_mcp.py
scripts/pear_mcp.pybash
python3 skills/pear-protocol/scripts/pear_mcp.py status
python3 skills/pear-protocol/scripts/pear_mcp.py list
python3 skills/pear-protocol/scripts/pear_mcp.py call <tool> '<json-args>'Auto-uses from env/.env (x-api-key header). Read tools:
get_position(+history), discover_assets, list_baskets,
search_prediction_markets, get_leaderboard, list_trade_accounts,
get_account_summary, get_fee_quote, get_tca, list_pending_orders, etc.
PEAR_API_KEYbash
python3 skills/pear-protocol/scripts/pear_mcp.py status
python3 skills/pear-protocol/scripts/pear_mcp.py list
python3 skills/pear-protocol/scripts/pear_mcp.py call <tool> '<json-args>'自动使用环境变量/.env中的(x-api-key请求头)。只读工具包括:get_position(+历史记录)、discover_assets、list_baskets、search_prediction_markets、get_leaderboard、list_trade_accounts、get_account_summary、get_fee_quote、get_tca、list_pending_orders等。
PEAR_API_KEYTrade account (Hyperliquid) — REQUIRED before any execute_*
交易账户(Hyperliquid)—— 执行任何execute_*操作前必须设置
One-time setup per agent (the connected account id is returned at step 3;
keep it in ):
.pear/trade_account.json- Generate keypair () → save to
eth_account.Account.create()(0600)..pear/hl_signer.json - Approve as HL agent wallet — user-signed action, EIP-712 domain
approveAgent(chainId 421614), typesHyperliquidSignTransaction[hyperliquidChain, agentAddress, agentName, nonce] — signed by the Privy master via wallet serviceHyperliquidTransaction:ApproveAgent(same pattern as hyperliquid skill's/agent/sign-typed-data). Submit tosign_user_actionwithPOST api.hyperliquid.xyz/exchange(used even on Mainnet — thesignatureChainId: "0x66eee"field selects the network; use that). 42161 /hyperliquidChainis also accepted and was verified working — the real requirement is that0xa4b1exactly matches the domain chainId used when signing. Verify with infosignatureChainId.{"type":"extraAgents","user":<master>} - (Bearer) — EXACT payload (validation errors only show details when
POST /trade-accountsis present):connector→ 201 with{"alias": "...", "connector": "hyperliquid", "exchangeIdentifier": <master addr>, "credentials": {"signer_key": <signer priv, snake_case!>}, "metadata": {"agentWalletAddress": <signer addr>, "isSubaccount": false, "mainAccountAddress": <master addr>}}.account.id
Funds stay under the master HL account; signer trades, can't withdraw.
- Approve Pear's builder fee (REQUIRED — executions fail without it).
Pear does NOT do this for you. Get the builder address via MCP
(currently
get_fee_recipient {"connector":"hyperliquid"}, fee 6 bps). Sign a user-signed0xa47d4d99191db54a4829cdf3de2417e527c3b042action with the MASTER wallet (not the signer): EIP-712 typeapproveBuilderFee[hyperliquidChain, maxFeeRate, builder, nonce], same domain/chain-id rules as approveAgent. UseHyperliquidTransaction:ApproveBuilderFee(HL perps cap). Submit tomaxFeeRate: "0.1%"with matchingPOST api.hyperliquid.xyz/exchange. Verify: infosignatureChainIdmust return > 0 (100 = 0.1%).{"type":"maxBuilderFee","user":<master>,"builder":<builder>}
每个Agent只需执行一次设置(连接的账户ID会在步骤3返回;请保存到):
.pear/trade_account.json- 生成密钥对()→ 保存到
eth_account.Account.create()(权限0600)。.pear/hl_signer.json - 批准为HL Agent钱包——由用户签署操作,EIP-712域为
approveAgent(链ID 421614),类型为HyperliquidSignTransaction[hyperliquidChain, agentAddress, agentName, nonce] —— 通过钱包服务HyperliquidTransaction:ApproveAgent由Privy主钱包签署(与hyperliquid技能的/agent/sign-typed-data模式相同)。提交至sign_user_action,并携带POST api.hyperliquid.xyz/exchange(即使在主网也使用该值——signatureChainId: "0x66eee"字段选择网络;请使用该值)。42161 /hyperliquidChain也可接受并已验证可用——实际要求是0xa4b1必须与签名时使用的域链ID完全匹配。通过信息signatureChainId验证。{"type":"extraAgents","user":<master>} - (Bearer令牌)—— 精确请求体(仅当存在
POST /trade-accounts时才会显示验证错误详情):connector→ 返回201状态码及{"alias": "...", "connector": "hyperliquid", "exchangeIdentifier": <master addr>, "credentials": {"signer_key": <signer priv, snake_case!>}, "metadata": {"agentWalletAddress": <signer addr>, "isSubaccount": false, "mainAccountAddress": <master addr>}}。account.id
资金仍存于主HL账户;签名者可进行交易,但无法提取资金。
- 批准Pear的构建者费用(必须设置——未批准则执行操作会失败)。
Pear不会自动完成此操作。通过MCP 获取构建者地址(当前为
get_fee_recipient {"connector":"hyperliquid"},费率为6个基点)。使用主钱包(而非签名者)签署用户操作0xa47d4d99191db54a4829cdf3de2417e527c3b042:EIP-712类型为approveBuilderFee[hyperliquidChain, maxFeeRate, builder, nonce],域/链ID规则与approveAgent相同。使用HyperliquidTransaction:ApproveBuilderFee(HL永续合约上限)。提交至maxFeeRate: "0.1%"并携带匹配的POST api.hyperliquid.xyz/exchange。验证:信息signatureChainId必须返回大于0的值(100 = 0.1%)。{"type":"maxBuilderFee","user":<master>,"builder":<builder>}
Trading via MCP — plan → execute pattern
通过MCP交易——规划→执行模式
Arg shape: — is a
discriminated union on (market|twap|trigger|ladder).
Legs: + top-level
, , . = dry-run with priced
legs/margin (ALWAYS show the user before executing); = live.
HL $10 min notional per leg (auto-bumped with warning).
{"tradeAccountId": <id>, "params": {...}}paramsexecutionStyle{"source":"symbol","symbol":"BTC","side":"BUY"|"SELL"}totalUsdleveragemarginModeplan_*execute_*Preflight (run before every execute_*):
python3 scripts/preflight.py check --notional <usd> [--leverage N]Verifies: API key, trade account, on-chain builder-fee approval, balance
breakdown (perp equity vs spot — catches funds stuck in spot / account-mode
issues that zero out margin on xyz:* builder-DEX markets), and available
margin vs the planned notional. Exit 0 = safe to execute; nonzero = blocked
with the specific reason. Do NOT execute on a failing preflight.
Post-trade receipt (run after every execute_*):
python3 scripts/preflight.py verify <execution_id> --trade-account <id>Checks execution status + venue errors + filledQuantity + that the position
actually exists. Only "FILLED ✅" means a trade happened.
⚠️ ≠ filled. The execute_* response only means Pear
submitted the order. ALWAYS verify the outcome: check the execution record
for venue errors and , then confirm the position exists
(get_position / HL clearinghouseState). A common definitive rejection is
→ run step 4 of the trade-account
recipe, then retry.
status: executedfilledQuantity > 0"Builder fee has not been approved"get_account_summary{"tradeAccountId": <id>, "params": {"scope": "balance"}}参数格式: —— 是基于(market|twap|trigger|ladder)的区分联合类型。仓位腿: + 顶层字段、、。 = 带定价仓位腿/保证金的试运行(执行前必须展示给用户); = 实盘交易。HL每条仓位腿最低名义价值为10美元(若不足会自动调整并给出警告)。
{"tradeAccountId": <id>, "params": {...}}paramsexecutionStyle{"source":"symbol","symbol":"BTC","side":"BUY"|"SELL"}totalUsdleveragemarginModeplan_*execute_*预检查(每次执行execute_*前运行):
python3 scripts/preflight.py check --notional <usd> [--leverage N]验证:API密钥、交易账户、链上构建者费用批准、余额明细(永续合约权益 vs 现货——捕获资金被困在现货/账户模式问题,这些问题会导致xyz:*构建者DEX市场的保证金归零),以及可用保证金与计划名义价值的对比。退出码0 = 可安全执行;非零 = 因特定原因被阻止。预检查失败时不要执行交易。
交易后确认(每次执行execute_*后运行):
python3 scripts/preflight.py verify <execution_id> --trade-account <id>检查执行状态 + 场所错误 + 成交数量 + 仓位是否实际存在。只有“FILLED ✅”表示交易已完成。
⚠️ ≠ 成交。 execute_*的响应仅表示Pear已提交订单。必须始终验证结果:检查执行记录中的场所错误和,然后确认仓位存在(get_position / HL clearinghouseState)。常见的明确拒绝是 → 完成交易账户设置的步骤4,然后重试。
status: executedfilledQuantity > 0"Builder fee has not been approved"get_account_summary{"tradeAccountId": <id>, "params": {"scope": "balance"}}Notes
注意事项
- Read-only pair data (funding, ratios) can also come from the skill; use Pear when acting on a Pear account or using Pear analytics.
hyperliquid - Optional: a Pear-issued attributes routed volume (contact Pear).
clientId - Docs: https://docs.pear.garden/api-integration/access-management/authentication-process
- 只读配对数据(资金费率、比率)也可来自技能;当操作Pear账户或使用Pear分析工具时,请使用Pear。
hyperliquid - 可选:Pear颁发的可统计路由成交量(联系Pear获取)。
clientId - 文档:https://docs.pear.garden/api-integration/access-management/authentication-process
Troubleshooting
故障排除
-
Builder-fee approval has cache propagation delay. After on-chainverifies > 0, Pear's venue check may still reject briefly ("Builder fee has not been approved") — wait ~1–2 min and retry before debugging further.
maxBuilderFee -
xyz: (HIP-3 builder-DEX) markets show $0 margin until unified account abstraction is enabled* on the Hyperliquid account. If a plan prices fine but available margin reads zero on an xyz pair, enable unified/abstracted account mode first, then re-plan.
-
Account-scoped gateway/MCP calls (positions, account summary, execute_*) fail until a trade account is connected — expected; follow the trade-account recipe first. Market data and analytics tools work without one.
-
Importing the wallet module may print harmless warnings about unavailable optional analytics integrations (e.g. CoinGecko/Coinglass) — ignore them; they don't affect Pear.
-
Scripts auto-route HTTP through Starchild's authenticated proxy when available and fall back to direct connections otherwise; no configuration needed.
-
构建者费用批准存在缓存传播延迟。 当链上验证大于0后,Pear的场所检查可能仍会短暂拒绝(“Builder fee has not been approved”)——等待约1-2分钟后重试,再进行进一步调试。
maxBuilderFee -
xyz:*(HIP-3构建者DEX)市场在Hyperliquid账户启用统一账户抽象前显示0美元保证金。若某个计划定价正常但xyz配对的可用保证金显示为0,请先启用统一/抽象账户模式,然后重新规划。
-
账户范围的网关/MCP调用(仓位、账户摘要、execute_*)在连接交易账户前会失败——此为预期行为;请先完成交易账户设置流程。市场数据和分析工具无需交易账户即可使用。
-
导入钱包模块可能会打印关于可选分析集成(如CoinGecko/Coinglass)不可用的无害警告——忽略即可;这些不影响Pear的使用。
-
脚本会自动通过Starchild的认证代理路由HTTP请求(若可用),否则回退到直接连接;无需额外配置。