perp-cli 0.12.15 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/README.md +278 -31
  2. package/dist/_stderr-filter.js +0 -1
  3. package/dist/agent-wallet/lighter-keystore.d.ts +11 -0
  4. package/dist/agent-wallet/lighter-keystore.js +92 -10
  5. package/dist/agent-wallet/passphrase.d.ts +1 -1
  6. package/dist/agent-wallet/passphrase.js +16 -3
  7. package/dist/agent-wallet/store.d.ts +37 -4
  8. package/dist/agent-wallet/store.js +132 -0
  9. package/dist/agent-wallet/venue-keystore.d.ts +14 -0
  10. package/dist/agent-wallet/venue-keystore.js +121 -0
  11. package/dist/api/public/hyperliquid.js +4 -4
  12. package/dist/api/public/lighter.js +5 -5
  13. package/dist/api/public/pacifica.d.ts +0 -1
  14. package/dist/api/public/pacifica.js +4 -13
  15. package/dist/api/public/urls.d.ts +9 -1
  16. package/dist/api/public/urls.js +35 -13
  17. package/dist/arb/file-lock.d.ts +11 -0
  18. package/dist/arb/file-lock.js +74 -0
  19. package/dist/arb/index.d.ts +2 -2
  20. package/dist/arb/index.js +2 -2
  21. package/dist/arb/pending-entry.d.ts +32 -0
  22. package/dist/arb/pending-entry.js +77 -0
  23. package/dist/arb/sizing.d.ts +6 -13
  24. package/dist/arb/sizing.js +12 -51
  25. package/dist/arb/state.d.ts +45 -12
  26. package/dist/arb/state.js +214 -42
  27. package/dist/arb/utils.d.ts +20 -6
  28. package/dist/arb/utils.js +43 -39
  29. package/dist/bot/conditions.d.ts +4 -4
  30. package/dist/bot/conditions.js +11 -6
  31. package/dist/bot/config.d.ts +17 -1
  32. package/dist/bot/config.js +48 -12
  33. package/dist/bot/engine.d.ts +61 -2
  34. package/dist/bot/engine.js +610 -144
  35. package/dist/bot/fill-size.d.ts +7 -0
  36. package/dist/bot/fill-size.js +18 -0
  37. package/dist/bot/index.d.ts +1 -1
  38. package/dist/bot/index.js +1 -1
  39. package/dist/bot/perp-order.d.ts +99 -0
  40. package/dist/bot/perp-order.js +299 -0
  41. package/dist/bot/presets.d.ts +7 -0
  42. package/dist/bot/presets.js +17 -0
  43. package/dist/bot/quarantine.d.ts +75 -0
  44. package/dist/bot/quarantine.js +190 -0
  45. package/dist/bot/quote-rules.d.ts +23 -0
  46. package/dist/bot/quote-rules.js +69 -0
  47. package/dist/bot/strategies/avellaneda-mm.d.ts +32 -2
  48. package/dist/bot/strategies/avellaneda-mm.js +72 -70
  49. package/dist/bot/strategies/basis-arb.js +2 -0
  50. package/dist/bot/strategies/dca-strategy.d.ts +2 -0
  51. package/dist/bot/strategies/dca-strategy.js +5 -0
  52. package/dist/bot/strategies/funding-arb-strategy.d.ts +43 -3
  53. package/dist/bot/strategies/funding-arb-strategy.js +571 -380
  54. package/dist/bot/strategies/funding-arb-utils.d.ts +48 -23
  55. package/dist/bot/strategies/funding-arb-utils.js +159 -195
  56. package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
  57. package/dist/bot/strategies/funding-arb-v2.js +258 -47
  58. package/dist/bot/strategies/funding-auto.js +215 -194
  59. package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +14 -0
  60. package/dist/bot/strategies/spot-perp-arb-strategy.js +217 -50
  61. package/dist/bot/strategies/spot-perp-executor.d.ts +73 -19
  62. package/dist/bot/strategies/spot-perp-executor.js +319 -120
  63. package/dist/bot/strategies/spot-perp-state.d.ts +43 -0
  64. package/dist/bot/strategies/spot-perp-state.js +70 -0
  65. package/dist/bot/strategy-types.d.ts +6 -0
  66. package/dist/bot/tui/BotDashboard.d.ts +7 -2
  67. package/dist/bot/tui/BotDashboard.js +6 -3
  68. package/dist/bridge-engine.d.ts +120 -19
  69. package/dist/bridge-engine.js +710 -422
  70. package/dist/bridge-signers.d.ts +54 -0
  71. package/dist/bridge-signers.js +161 -0
  72. package/dist/cache.d.ts +4 -1
  73. package/dist/cache.js +11 -0
  74. package/dist/cli-flags.d.ts +50 -0
  75. package/dist/cli-flags.js +104 -0
  76. package/dist/cli-program.d.ts +35 -0
  77. package/dist/cli-program.js +286 -0
  78. package/dist/cli-spec.js +1 -1
  79. package/dist/client-id-tracker.js +11 -2
  80. package/dist/commands/account.d.ts +7 -1
  81. package/dist/commands/account.js +74 -84
  82. package/dist/commands/agent-import.d.ts +114 -0
  83. package/dist/commands/agent-import.js +794 -0
  84. package/dist/commands/agent.d.ts +232 -2
  85. package/dist/commands/agent.js +1858 -955
  86. package/dist/commands/alerts.d.ts +1 -0
  87. package/dist/commands/alerts.js +31 -28
  88. package/dist/commands/arb/index.d.ts +60 -1
  89. package/dist/commands/arb/index.js +381 -384
  90. package/dist/commands/arb-auto.d.ts +132 -4
  91. package/dist/commands/arb-auto.js +1474 -967
  92. package/dist/commands/arb.d.ts +3 -1
  93. package/dist/commands/arb.js +62 -30
  94. package/dist/commands/bot.js +127 -47
  95. package/dist/commands/bridge.d.ts +2 -1
  96. package/dist/commands/bridge.js +339 -192
  97. package/dist/commands/builder.d.ts +55 -0
  98. package/dist/commands/builder.js +387 -0
  99. package/dist/commands/funds-onchain.d.ts +32 -0
  100. package/dist/commands/funds-onchain.js +286 -0
  101. package/dist/commands/funds.d.ts +25 -0
  102. package/dist/commands/funds.js +939 -245
  103. package/dist/commands/history.js +72 -45
  104. package/dist/commands/init.d.ts +107 -15
  105. package/dist/commands/init.js +1116 -249
  106. package/dist/commands/jobs.d.ts +2 -1
  107. package/dist/commands/jobs.js +77 -15
  108. package/dist/commands/manage.js +136 -91
  109. package/dist/commands/market.d.ts +4 -1
  110. package/dist/commands/market.js +35 -32
  111. package/dist/commands/outcome.d.ts +10 -0
  112. package/dist/commands/outcome.js +396 -0
  113. package/dist/commands/plan.js +52 -12
  114. package/dist/commands/portfolio.d.ts +1 -0
  115. package/dist/commands/portfolio.js +60 -72
  116. package/dist/commands/rebalance.d.ts +2 -1
  117. package/dist/commands/rebalance.js +33 -43
  118. package/dist/commands/risk.js +46 -19
  119. package/dist/commands/settings.d.ts +1 -0
  120. package/dist/commands/settings.js +246 -51
  121. package/dist/commands/trade.d.ts +50 -0
  122. package/dist/commands/trade.js +1943 -695
  123. package/dist/commands/wallet.d.ts +30 -1
  124. package/dist/commands/wallet.js +316 -337
  125. package/dist/config.d.ts +60 -9
  126. package/dist/config.js +252 -82
  127. package/dist/constants.d.ts +29 -4
  128. package/dist/constants.js +62 -20
  129. package/dist/dashboard/server.d.ts +2 -0
  130. package/dist/dashboard/server.js +9 -6
  131. package/dist/dashboard/ui.js +6 -4
  132. package/dist/dashboard/ws-feeds.js +20 -8
  133. package/dist/dex-asset-map.js +5 -3
  134. package/dist/errors.d.ts +122 -0
  135. package/dist/errors.js +194 -0
  136. package/dist/event-stream.js +75 -19
  137. package/dist/evm-master-tx.d.ts +59 -0
  138. package/dist/evm-master-tx.js +154 -0
  139. package/dist/exchanges/adapter-network.d.ts +10 -0
  140. package/dist/exchanges/adapter-network.js +10 -0
  141. package/dist/exchanges/arcus/adapter.d.ts +196 -0
  142. package/dist/exchanges/arcus/adapter.js +1092 -0
  143. package/dist/exchanges/arcus/agent.d.ts +55 -0
  144. package/dist/exchanges/arcus/agent.js +188 -0
  145. package/dist/exchanges/arcus/client.d.ts +63 -0
  146. package/dist/exchanges/arcus/client.js +285 -0
  147. package/dist/exchanges/arcus/public.d.ts +65 -0
  148. package/dist/exchanges/arcus/public.js +138 -0
  149. package/dist/exchanges/arcus/signing.d.ts +176 -0
  150. package/dist/exchanges/arcus/signing.js +288 -0
  151. package/dist/exchanges/arcus/spot-chain.d.ts +60 -0
  152. package/dist/exchanges/arcus/spot-chain.js +241 -0
  153. package/dist/exchanges/arcus/spot-router.d.ts +177 -0
  154. package/dist/exchanges/arcus/spot-router.js +183 -0
  155. package/dist/exchanges/arcus/spot.d.ts +109 -0
  156. package/dist/exchanges/arcus/spot.js +645 -0
  157. package/dist/exchanges/aster-funds.d.ts +127 -0
  158. package/dist/exchanges/aster-funds.js +252 -0
  159. package/dist/exchanges/aster-nonce.d.ts +2 -0
  160. package/dist/exchanges/aster-nonce.js +107 -0
  161. package/dist/exchanges/aster-spot.d.ts +117 -0
  162. package/dist/exchanges/aster-spot.js +686 -0
  163. package/dist/exchanges/aster-typed-data.d.ts +133 -7
  164. package/dist/exchanges/aster-typed-data.js +121 -7
  165. package/dist/exchanges/aster.d.ts +219 -6
  166. package/dist/exchanges/aster.js +1023 -153
  167. package/dist/exchanges/builder-fee.d.ts +254 -0
  168. package/dist/exchanges/builder-fee.js +421 -0
  169. package/dist/exchanges/canonical-symbols.d.ts +32 -0
  170. package/dist/exchanges/canonical-symbols.js +96 -0
  171. package/dist/exchanges/capabilities.d.ts +7 -1
  172. package/dist/exchanges/capabilities.js +7 -0
  173. package/dist/exchanges/hl-signing.d.ts +165 -0
  174. package/dist/exchanges/hl-signing.js +158 -0
  175. package/dist/exchanges/hyperliquid-outcome.d.ts +211 -0
  176. package/dist/exchanges/hyperliquid-outcome.js +646 -0
  177. package/dist/exchanges/hyperliquid-spot.d.ts +44 -5
  178. package/dist/exchanges/hyperliquid-spot.js +308 -117
  179. package/dist/exchanges/hyperliquid.d.ts +462 -57
  180. package/dist/exchanges/hyperliquid.js +1575 -449
  181. package/dist/exchanges/index.d.ts +6 -0
  182. package/dist/exchanges/index.js +4 -0
  183. package/dist/exchanges/interface.d.ts +63 -10
  184. package/dist/exchanges/interface.js +18 -3
  185. package/dist/exchanges/ioc-outcome.d.ts +44 -0
  186. package/dist/exchanges/ioc-outcome.js +57 -0
  187. package/dist/exchanges/legacy-trading-v2.d.ts +39 -0
  188. package/dist/exchanges/legacy-trading-v2.js +940 -0
  189. package/dist/exchanges/lighter-public.d.ts +43 -0
  190. package/dist/exchanges/lighter-public.js +276 -0
  191. package/dist/exchanges/lighter-rh-deposit.d.ts +62 -0
  192. package/dist/exchanges/lighter-rh-deposit.js +185 -0
  193. package/dist/exchanges/lighter-signer.d.ts +123 -0
  194. package/dist/exchanges/lighter-signer.js +215 -0
  195. package/dist/exchanges/lighter-spot.d.ts +91 -13
  196. package/dist/exchanges/lighter-spot.js +595 -233
  197. package/dist/exchanges/lighter.d.ts +611 -39
  198. package/dist/exchanges/lighter.js +1890 -649
  199. package/dist/exchanges/ondo/adapter.d.ts +166 -0
  200. package/dist/exchanges/ondo/adapter.js +835 -0
  201. package/dist/exchanges/ondo/agent.d.ts +31 -0
  202. package/dist/exchanges/ondo/agent.js +101 -0
  203. package/dist/exchanges/ondo/client.d.ts +60 -0
  204. package/dist/exchanges/ondo/client.js +297 -0
  205. package/dist/exchanges/ondo/funds.d.ts +122 -0
  206. package/dist/exchanges/ondo/funds.js +290 -0
  207. package/dist/exchanges/ondo/public.d.ts +95 -0
  208. package/dist/exchanges/ondo/public.js +214 -0
  209. package/dist/exchanges/ondo/spot.d.ts +127 -0
  210. package/dist/exchanges/ondo/spot.js +392 -0
  211. package/dist/exchanges/outcome-interface.d.ts +140 -0
  212. package/dist/exchanges/outcome-interface.js +16 -0
  213. package/dist/exchanges/pacifica-spot.d.ts +83 -0
  214. package/dist/exchanges/pacifica-spot.js +324 -0
  215. package/dist/exchanges/pacifica-typed-data.d.ts +30 -13
  216. package/dist/exchanges/pacifica-typed-data.js +57 -9
  217. package/dist/exchanges/pacifica.d.ts +288 -4
  218. package/dist/exchanges/pacifica.js +1013 -76
  219. package/dist/exchanges/precision.d.ts +47 -0
  220. package/dist/exchanges/precision.js +209 -0
  221. package/dist/exchanges/qfex/adapter.d.ts +341 -0
  222. package/dist/exchanges/qfex/adapter.js +1383 -0
  223. package/dist/exchanges/qfex/agent.d.ts +58 -0
  224. package/dist/exchanges/qfex/agent.js +188 -0
  225. package/dist/exchanges/qfex/client.d.ts +54 -0
  226. package/dist/exchanges/qfex/client.js +138 -0
  227. package/dist/exchanges/qfex/errors.d.ts +70 -0
  228. package/dist/exchanges/qfex/errors.js +236 -0
  229. package/dist/exchanges/qfex/public.d.ts +122 -0
  230. package/dist/exchanges/qfex/public.js +268 -0
  231. package/dist/exchanges/qfex/signing.d.ts +160 -0
  232. package/dist/exchanges/qfex/signing.js +283 -0
  233. package/dist/exchanges/qfex/ws-transport.d.ts +294 -0
  234. package/dist/exchanges/qfex/ws-transport.js +798 -0
  235. package/dist/exchanges/rate-limiter.d.ts +12 -0
  236. package/dist/exchanges/rate-limiter.js +64 -0
  237. package/dist/exchanges/registry.d.ts +14 -2
  238. package/dist/exchanges/registry.js +20 -32
  239. package/dist/exchanges/slippage.d.ts +37 -0
  240. package/dist/exchanges/slippage.js +70 -0
  241. package/dist/exchanges/spot-factory.d.ts +166 -0
  242. package/dist/exchanges/spot-factory.js +431 -0
  243. package/dist/exchanges/spot-interface.d.ts +98 -4
  244. package/dist/exchanges/spot-interface.js +27 -1
  245. package/dist/exchanges/spot-result.d.ts +79 -0
  246. package/dist/exchanges/spot-result.js +273 -0
  247. package/dist/exchanges/trading-v2.d.ts +117 -0
  248. package/dist/exchanges/trading-v2.js +301 -0
  249. package/dist/exchanges/venue-types.d.ts +231 -0
  250. package/dist/exchanges/venue-types.js +87 -0
  251. package/dist/exchanges/venue.d.ts +211 -0
  252. package/dist/exchanges/venue.js +132 -0
  253. package/dist/exchanges/venues/arcus.d.ts +8 -0
  254. package/dist/exchanges/venues/arcus.js +109 -0
  255. package/dist/exchanges/venues/aster.d.ts +49 -0
  256. package/dist/exchanges/venues/aster.js +176 -0
  257. package/dist/exchanges/venues/create-helpers.d.ts +18 -0
  258. package/dist/exchanges/venues/create-helpers.js +199 -0
  259. package/dist/exchanges/venues/hyperliquid.d.ts +23 -0
  260. package/dist/exchanges/venues/hyperliquid.js +126 -0
  261. package/dist/exchanges/venues/index.d.ts +16 -0
  262. package/dist/exchanges/venues/index.js +26 -0
  263. package/dist/exchanges/venues/lighter-family.d.ts +92 -0
  264. package/dist/exchanges/venues/lighter-family.js +166 -0
  265. package/dist/exchanges/venues/lighter-rh.d.ts +7 -0
  266. package/dist/exchanges/venues/lighter-rh.js +58 -0
  267. package/dist/exchanges/venues/lighter.d.ts +6 -0
  268. package/dist/exchanges/venues/lighter.js +55 -0
  269. package/dist/exchanges/venues/ondo.d.ts +34 -0
  270. package/dist/exchanges/venues/ondo.js +140 -0
  271. package/dist/exchanges/venues/pacifica.d.ts +8 -0
  272. package/dist/exchanges/venues/pacifica.js +95 -0
  273. package/dist/exchanges/venues/qfex.d.ts +28 -0
  274. package/dist/exchanges/venues/qfex.js +132 -0
  275. package/dist/execution-log.js +10 -2
  276. package/dist/funding/legacy-public.d.ts +31 -0
  277. package/dist/funding/legacy-public.js +369 -0
  278. package/dist/funding/normalize.d.ts +28 -16
  279. package/dist/funding/normalize.js +61 -29
  280. package/dist/funding/rates.d.ts +46 -11
  281. package/dist/funding/rates.js +228 -277
  282. package/dist/guardrail/perp-guardrail.js +0 -0
  283. package/dist/index.js +157 -682
  284. package/dist/jobs.d.ts +84 -6
  285. package/dist/jobs.js +239 -41
  286. package/dist/landing.d.ts +14 -0
  287. package/dist/landing.js +36 -0
  288. package/dist/mcp-server.d.ts +14 -4
  289. package/dist/mcp-server.js +820 -402
  290. package/dist/mcp-trade-guard.d.ts +16 -0
  291. package/dist/mcp-trade-guard.js +59 -0
  292. package/dist/pacifica/client.d.ts +41 -10
  293. package/dist/pacifica/client.js +167 -63
  294. package/dist/pacifica/constants.d.ts +0 -1
  295. package/dist/pacifica/constants.js +0 -5
  296. package/dist/pacifica/deposit.d.ts +30 -3
  297. package/dist/pacifica/deposit.js +119 -2
  298. package/dist/pacifica/faucet.d.ts +29 -0
  299. package/dist/pacifica/faucet.js +100 -0
  300. package/dist/pacifica/sign-tx.d.ts +15 -0
  301. package/dist/pacifica/sign-tx.js +41 -0
  302. package/dist/pacifica/types/account.d.ts +28 -4
  303. package/dist/pacifica/types/lake.d.ts +20 -5
  304. package/dist/pacifica/types/lake.js +4 -0
  305. package/dist/pacifica/types/market.d.ts +5 -0
  306. package/dist/pacifica/types/order.d.ts +4 -1
  307. package/dist/pacifica/types/position.d.ts +9 -1
  308. package/dist/plan-executor.d.ts +10 -5
  309. package/dist/plan-executor.js +165 -54
  310. package/dist/position-history.js +13 -0
  311. package/dist/rebalance.d.ts +26 -2
  312. package/dist/rebalance.js +86 -7
  313. package/dist/relay-swap.d.ts +232 -0
  314. package/dist/relay-swap.js +630 -0
  315. package/dist/risk.js +5 -1
  316. package/dist/secret-env.d.ts +15 -0
  317. package/dist/secret-env.js +36 -0
  318. package/dist/settings.d.ts +169 -6
  319. package/dist/settings.js +219 -38
  320. package/dist/signer/ows-evm.d.ts +13 -0
  321. package/dist/signer/ows-evm.js +22 -0
  322. package/dist/smart-order.d.ts +9 -0
  323. package/dist/smart-order.js +53 -8
  324. package/dist/strategies/dca.d.ts +6 -2
  325. package/dist/strategies/dca.js +66 -26
  326. package/dist/strategies/funding-arb.d.ts +11 -1
  327. package/dist/strategies/funding-arb.js +202 -89
  328. package/dist/strategies/grid.d.ts +31 -0
  329. package/dist/strategies/grid.js +89 -11
  330. package/dist/strategies/pending-stop.d.ts +8 -0
  331. package/dist/strategies/pending-stop.js +12 -0
  332. package/dist/strategies/split-order.d.ts +45 -17
  333. package/dist/strategies/split-order.js +157 -91
  334. package/dist/strategies/trailing-stop.d.ts +2 -1
  335. package/dist/strategies/trailing-stop.js +52 -6
  336. package/dist/strategies/twap.d.ts +6 -1
  337. package/dist/strategies/twap.js +39 -11
  338. package/dist/trade-validator.d.ts +22 -0
  339. package/dist/trade-validator.js +119 -15
  340. package/dist/utils/numeric.d.ts +46 -0
  341. package/dist/utils/numeric.js +79 -0
  342. package/dist/utils.d.ts +19 -0
  343. package/dist/utils.js +96 -19
  344. package/dist/withdraw-gate.d.ts +49 -0
  345. package/dist/withdraw-gate.js +131 -0
  346. package/package.json +15 -6
  347. package/skills/perp-cli/SKILL.md +338 -134
  348. package/skills/perp-cli/references/agent-operations.md +181 -92
  349. package/skills/perp-cli/references/commands.md +475 -132
  350. package/skills/perp-cli/references/strategies.md +44 -38
  351. package/skills/perp-cli/scripts/arb-monitor.sh +22 -17
  352. package/skills/perp-cli/scripts/funding-analysis.sh +20 -10
  353. package/skills/perp-cli/scripts/preflight.sh +21 -14
  354. package/skills/perp-cli/scripts/spot-perp-scan.sh +12 -7
  355. package/skills/perp-cli/scripts/validate-arb.sh +33 -16
  356. package/vendor/lighter-signer/SHA256SUMS +2 -0
  357. package/vendor/lighter-signer/VERSION +8 -0
  358. package/vendor/lighter-signer/lighter-signer.wasm +0 -0
  359. package/vendor/lighter-signer/wasm_exec.js +575 -0
  360. package/dist/bot/strategies/funding-arb-v2-strategy.d.ts +0 -42
  361. package/dist/bot/strategies/funding-arb-v2-strategy.js +0 -864
@@ -1,219 +1,423 @@
1
1
  ---
2
2
  name: perp-cli
3
- description: "Multi-DEX perpetual futures trading CLI for Pacifica (Solana), Hyperliquid (EVM), Lighter (Ethereum), and Aster (BNB Chain). Use when user asks to: trade perps, check funding rates, scan arbitrage (perp-perp or spot-perp), delta-neutral strategies, bridge USDC, manage positions/orders, deposit/withdraw, spot+perp hedge, HIP-3 DEX trading, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, Aster, HyperEVM, funding arb, U-token (UBTC/UETH/USOL)."
4
- allowed-tools: "Bash(perp:*), Bash(npx perp-cli:*), Bash(npx -y perp-cli:*)"
3
+ description: "Multi-DEX perpetual futures trading via the perp-cli command-line tool. Use when user asks to: trade perps, check funding rates, scan/execute arbitrage (perp-perp or spot-perp), run delta-neutral strategies, bridge USDC across chains, manage positions/orders/leverage, deposit/withdraw, hedge spot+perp, trade HIP-3 DEXes, or mentions perp-cli, hypurrquant, Pacifica, Hyperliquid, Lighter, Aster, Lighter RH, Ondo Perps, Arcus, HyperEVM, funding arb, or U-tokens (UBTC/UETH/USOL). Covers Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum), Aster (BNB Chain), Lighter RH and Arcus (Robinhood chain) and Ondo Perps (off-chain)."
5
4
  license: MIT
5
+ allowed-tools: "Bash(perp:*), Bash(npx -y perp-cli:*), Bash(bash scripts/preflight.sh:*), Bash(bash scripts/arb-monitor.sh:*), Bash(bash scripts/funding-analysis.sh:*), Bash(bash scripts/spot-perp-scan.sh:*), Bash(bash scripts/validate-arb.sh:*)"
6
+ compatibility: "Requires Node.js 20 or newer and the perp-cli npm package (global install or npx). Network access required for exchange APIs and bridge providers. Mutating commands need a wallet key imported into the OWS vault via 'perp wallet set EXCHANGE' (key on stdin or hidden prompt — never argv). Skill is portable across Claude Code, Claude.ai, Cursor, Codex, and Gemini CLI — no platform-specific features."
6
7
  metadata:
7
8
  author: hypurrquant
8
- version: "0.12.15"
9
+ version: "0.14.0"
9
10
  ---
10
11
 
11
- # perp-cli Agent Guide
12
+ # perp-cli
12
13
 
13
- Multi-DEX perpetual futures CLI + MCP server — Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum), Aster (BNB Chain).
14
+ Multi-DEX perpetual futures CLI + MCP server for Pacifica (Solana), Hyperliquid (HyperEVM), Lighter (Ethereum), Aster (BNB Chain), Lighter RH (`lighter-rh`, Robinhood chain, USDG), Ondo Perps (`ondo`), QFEX (`qfex`, custodial TradFi perps — import-only API key; resting reduce-only limits and automation are refused for now, see "QFEX" below), Arcus (`arcus`, Robinhood chain, USDG). v0.13.0+ also supports Hyperliquid Outcome markets (HIP-4) — fully-collateralized binary/range contracts; each outcome's quote token comes from `outcomeMeta.quoteToken` (USDC on every listed outcome as of 2026-10-12), minimum order value 10 quote tokens.
14
15
 
15
- [![Glama MCP server](https://glama.ai/mcp/servers/hypurrquant/perp-cli/badges/score.svg)](https://glama.ai/mcp/servers/hypurrquant/perp-cli)
16
+ ## Instructions
16
17
 
17
- ## MCP Server
18
+ ### When to use this skill
18
19
 
19
- 18 tools, 3 resources, 2 prompts. No API keys required for market data — explore prices, orderbooks, funding rates, and arb opportunities without setup.
20
+ Activate whenever the user wants to do anything against perp-cli, including: scanning funding-rate arbitrage, executing perp-perp or spot+perp legs, running long-running strategy bots, moving USDC between chains/exchanges, checking account/portfolio state, configuring wallets, or troubleshooting any of the above.
20
21
 
21
- ```json
22
- {
23
- "mcpServers": {
24
- "perp-cli": {
25
- "command": "npx",
26
- "args": ["-y", "-p", "perp-cli", "perp-mcp"]
27
- }
28
- }
29
- }
30
- ```
22
+ **Do NOT** answer trading questions from memory — always run the actual CLI command and parse its JSON output.
23
+
24
+ ### Reference files (load only when needed)
25
+
26
+ This skill uses progressive disclosure. Read these on demand:
27
+
28
+ - `references/commands.md` — full command tree for every group (market, account, trade, outcome, arb, funds, wallet, risk, history, strategy, background, alerts, settings, backtest)
29
+ - `references/agent-operations.md` — non-interactive setup flows, idempotency rules, error codes, common mistakes
30
+ - `references/strategies.md` — funding-arb decision framework + risk-management playbook (read before designing arb strategy)
31
+
32
+ Also bundled under `scripts/`: `preflight.sh`, `arb-monitor.sh`, `funding-analysis.sh`, `spot-perp-scan.sh`, `validate-arb.sh`. Use these for repeatable multi-step diagnostics.
31
33
 
32
- ## Rules
34
+ ### Critical rules
35
+
36
+ 1. **Always pass `--json`.** Without it, output is human-formatted and hard to parse. `ok:false` also exits 1.
37
+ 2. **Always pass `-e <venue>`** on venue-scoped commands. The default is `settings.defaultExchange`, else `pacifica` — never rely on it.
38
+ 3. **Always run `--dry-run` first** for any mutating command that supports it (`--help` says "supports --dry-run"). Show the result, get user confirmation, then execute without `--dry-run`. Commands without dry-run support refuse `--dry-run` with `INVALID_PARAMS` (see "Safety rules").
39
+ 4. **Always use `--fields`** when you only need specific data — saves tokens.
40
+ 5. **Avoid bare `perp setup` / `perp init` / `perp wallet setup`** — they prompt and will hang an agent. Use `printf '%s' "$KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set <exchange>` for key registration (key on stdin; a key on argv or `-k` is rejected), or `perp --json setup --non-interactive --wallet <ows-wallet> --venues <list> [--default-venue <v>] [--slippage-bps <n>] [--slippage <venue>=<bps>]` (new wallet: `--wallet-name <name>` with the passphrase in `OWS_PASSPHRASE`; agent registration only with `--approve-agents --yes`, after user confirmation) (and `OWS_PASSPHRASE=<pp> perp wallet setup --name <n> --max-tx-usd <usd> --max-daily-usd <usd>`) when the wizard is required. The passphrase goes in `OWS_PASSPHRASE` or stdin — the root `--passphrase` flag is deprecated (visible in `ps`).
41
+ 6. **NEVER trade without explicit user confirmation.** A dry-run is not consent.
42
+ 7. **NEVER read `~/.perp/.env` or other key files.** The CLI reads them — you should not.
43
+ 8. **NEVER manually add `-PERP` suffix** to symbols. Use bare names (`BTC`, `SOL`, `ICP`); the CLI resolves exchange-specific naming.
44
+ 9. **NEVER resubmit after `ORDER_PENDING`** (or any unknown outcome). See "Safety rules".
45
+
46
+ ### Step 1: Verify install + version
47
+
48
+ ```bash
49
+ perp --version 2>/dev/null || npx -y perp-cli@latest --version # must be >= 0.14.0
50
+ ```
33
51
 
34
- 1. **Always use `--json`** on every command.
35
- 2. **Always use `--dry-run`** before any mutating trade (then execute without it after user confirms).
36
- 3. **Always use `--fields`** to reduce output when you only need specific data (saves tokens).
37
- 4. **NEVER use `perp setup`** (alias: `perp init`) — interactive, will hang.
38
- 5. **NEVER trade without user confirmation.**
39
- 6. **NEVER read ~/.perp/.env or key files.**
52
+ If it is missing or older, ask the user before installing/upgrading (`npm install -g perp-cli@latest`) — never install on your own. If `perp` is not on PATH, prefix every command with `npx -y perp-cli@latest`.
40
53
 
41
- ## Install
54
+ ### Step 2: Verify wallet + balance
42
55
 
43
56
  ```bash
44
- perp --version 2>/dev/null # check if exists (must be >= 0.12.15)
45
- npm install -g perp-cli@latest 2>/dev/null || npx -y perp-cli@latest --json --version
57
+ perp --json wallet show # confirms configured exchanges
58
+ perp --json portfolio -e <venue-id> # per-exchange USDC available; full id (hyperliquid, not hl) — portfolio rejects aliases
46
59
  ```
47
60
 
48
- Use `perp` if global install works, otherwise `npx -y perp-cli@latest` as prefix.
61
+ If any required exchange is missing, register it (user supplies the key):
49
62
 
50
- ## Global Flags
63
+ ```bash
64
+ printf '%s' "$EVM_HEX_KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set hl # Hyperliquid / Lighter / Aster (EVM)
65
+ printf '%s' "$SOLANA_BASE58_KEY" | OWS_PASSPHRASE=<pp> perp --json wallet set pac # Pacifica (Solana)
66
+ ```
51
67
 
52
- `--json` (required) | `-e hl/pac/lt/aster` (exchange) | `--dex <name>` (HIP-3) | `-w <wallet>` | `--dry-run` | `--fields <f1,f2>` | `--ndjson`
68
+ The key is read from stdin (never argv — an argv key is rejected) and imported into the OWS vault; the imported wallet becomes `owsActiveWallet`, which serves every venue. The same EVM key works for Hyperliquid, Lighter and Aster. Lighter trading additionally needs `perp wallet agent approve lighter`.
53
69
 
54
- ## Wallet Setup
70
+ Lighter RH / Ondo Perps / Arcus have no `wallet set` path — register an agent / API key (user runs it; Ondo reads key id + secret from stdin):
55
71
 
56
72
  ```bash
57
- perp --json wallet set pac <SOLANA_KEY> # Pacifica
58
- perp --json wallet set hl <EVM_KEY> # Hyperliquid
59
- perp --json wallet set lt <EVM_KEY> # Lighter (API key auto-generated)
60
- perp --json wallet set aster <API_KEY> # Aster (BNB Chain)
61
- perp --json wallet show # verify
73
+ perp --json wallet agent approve lighter-rh
74
+ printf '%s\n%s\n' "$KEY_ID" "$SECRET" | perp --json wallet agent approve ondo
75
+ perp --json wallet agent approve arcus --master <ows-wallet> # address must be on the Arcus access whitelist
62
76
  ```
63
77
 
64
- ## Core Workflow: Arb
78
+ **No master wallet on this computer?** The user can create the agent / API key on the exchange website and import it — key on stdin only, verified against the venue before it is stored (`verification.status` is `"unverified"` only for Pacifica, which lists bindings master-signed only):
65
79
 
80
+ ```bash
81
+ printf '%s' "$AGENT_KEY" | perp --json wallet agent import hyperliquid # master read from HL
82
+ printf '%s' "$AGENT_KEY" | perp --json wallet agent import aster --master-address 0x… # also Aster testnet
83
+ printf '%s' "$AGENT_KEY" | perp --json wallet agent import pacifica --master-address <SOL>
84
+ printf '%s' "$API_KEY" | perp --json wallet agent import lighter --account-index <n> --api-key-index <slot>
85
+ printf '%s' "$ED25519_KEY" | perp --json wallet agent import arcus --master-address 0x…
66
86
  ```
67
- 1. perp --json arb scan # scan opportunities (perp-perp + spot-perp + HIP-3)
68
- 2. perp --json account balance # check balances across all exchanges
69
- 3. perp --json --dry-run arb exec <SYM> <longEx> <shortEx> <$> # dry-run (auto-sizes)
70
- 4. [show result to user, get confirmation]
71
- 5. perp --json arb exec <SYM> <longEx> <shortEx> <$> # execute
72
- 6. perp --json arb status # monitor PnL + funding income
73
- 7. perp --json arb close <SYM> # close both legs
87
+
88
+ Imported keys trade; `funds deposit|withdraw|transfer|bridge`, `wallet manage referral set` and `wallet agent approve` need the master → `NO_SIGNER_AVAILABLE` (tell the user to do it on the website or `perp wallet import` the master). `wallet agent revoke` of an imported key needs `--local-only` and does NOT revoke it on the exchange; `rotate` is refused (new key on the website → `import --replace`).
89
+
90
+ **QFEX** (`-e qfex`, testnet = QFEX UAT): keys are created on the QFEX website and imported by the USER (`perp wallet agent import qfex [--account-id <uuid>]` — the resolved account UUID must be confirmed). Rules an agent must follow:
91
+ - Works: market / IOC reduce-only closes (`trade close/close-all/flatten/reduce`), reduce-only stop-market orders (`trade stop`, `trade tpsl` TP/SL legs, `--tp/--sl` as separate stops after the verified fill; cancel with `trade cancel <S> <id>` or `trade cancel-stop`), `trade edit` of a plain LIMIT / ALO (the venue assigns a new order id; the client id is kept).
92
+ - Refused with `CAPABILITY_UNSUPPORTED` (do not work around): resting reduce-only limits (GTC / ALO / FOK, `scale-tp`), stop-limit and opening stops, amend of a reduce-only order, `--client-id`, non-USD-quoted markets, unattended automation (bots / plans / TWAP / DCA / grid / background jobs), QFEX as a funding-arb / funding-bot leg.
93
+ - After a close, reduce-only / stop orders left on a now-flat symbol are listed as a WARNING (the venue does not cancel them) — cancel them, or use `trade flatten`, which cancels them.
94
+ - Limit GTC / ALO returns `status: accepted, finality: pending` after the ACK; `open` only via `perp --json trade status c:<id> --symbol <S> -e qfex`.
95
+ - `ORDER_PENDING` = outcome unknown: NEVER resubmit; check with the `c:<id>` in the remediation.
96
+ - Funding rates on QFEX are unverified: excluded everywhere unless `perp --json arb scan --rates --include-unverified` (display only).
97
+ - Withdrawals need `settings.withdraw.qfex` (allowlist + limits), which only the user can set in an interactive terminal — an agent cannot set or change it. `perp --json --dry-run funds withdraw qfex <amt> --to <addr>` shows the gate verdict.
98
+
99
+ Venue rules for these: `trade limit` defaults to `--tif GTC` on every venue (arcus maps it to GTT; ondo offers GTC|IOC|ALO; FOK is never emulated → `CAPABILITY_UNSUPPORTED` where not offered); market orders on every venue are bounded by `--slippage-bps <n>` → `settings.slippageBps.<venue>` → `settings.defaultSlippageBps` (shipped default 50). Ondo (US, PA) and Arcus (US, CA, GB) print a one-time restricted-region notice on stderr when used with credentials (warn only, never blocks).
100
+
101
+ ### Step 3: Discover (read-only)
102
+
103
+ ```bash
104
+ perp --json arb scan # all modes (perp-perp + spot-perp), default --min 10 (% annual)
105
+ perp --json arb scan --mode perp-perp --top 10
106
+ perp --json arb scan --mode spot-perp --top 10
107
+ perp --json arb scan --rates # raw funding rates
108
+ perp --json arb scan --basis [<symbol>] # cross-exchange basis
109
+ perp --json arb scan --gaps # cross-exchange price gaps
110
+ perp --json arb scan --hip3 # HIP-3 cross-dex spreads
111
+ perp --json arb scan --history <symbol> # historical funding
112
+ perp --json arb scan --compare <symbol> # one symbol across all exchanges
113
+ perp --json arb scan --positions # funding impact on open positions
114
+ perp --json arb scan --live --interval 60 # continuous monitoring
74
115
  ```
75
116
 
76
- ### Scan Modes
117
+ Common knobs: `--min <pct>`, `--top <n>`, `--hold-days <n>`, `--bridge-cost <usd>`, `--size <usd>`.
77
118
 
78
- | Flag | Description |
79
- |------|-------------|
80
- | _(default)_ | All modes combined (perp-perp + spot-perp) |
81
- | `--rates` | Funding rates across exchanges |
82
- | `--basis [symbol]` | Cross-exchange basis/price diff |
83
- | `--gaps` | Price gaps |
84
- | `--hip3` | HIP-3 on-chain dex opportunities |
85
- | `--history [symbol]` | Historical funding data |
86
- | `--compare <symbol>` | Compare symbol across exchanges |
87
- | `--positions` | Existing position exit signals |
88
- | `--live` | Continuous monitoring |
119
+ ### Step 4: Validate before mutating
89
120
 
90
- ### Spot+Perp Arb
121
+ For arb:
91
122
 
92
- Spot has 0 funding cost. Use `spot:<exch>` prefix for the long leg:
123
+ ```bash
124
+ perp --json portfolio -e <longEx> # check available USDC (long leg)
125
+ perp --json portfolio -e <shortEx> # check available USDC (short leg)
126
+ perp --json --dry-run arb exec <SYM> <longEx> <shortEx> <USD>
127
+ ```
128
+
129
+ For a single trade:
93
130
 
94
131
  ```bash
95
- perp --json arb exec ETH spot:hl hl 100 # spot buy(HL) + perp short(HL)
96
- perp --json arb exec BTC spot:lt pac 50 # spot buy(LT) + perp short(PAC)
97
- perp --json arb close ETH # sells spot + buys back perp
132
+ perp --json -e <ex> trade check <SYM> <SIDE> <SIZE> --leverage <N>
133
+ perp --json --dry-run -e <ex> trade buy <SYM> <SIZE> --smart
98
134
  ```
99
135
 
100
- Spot exchanges: HL, LT. Pacifica and Aster are perp-only.
136
+ > `trade check` does NOT read exchange-set leverage. Always pass `--leverage` explicitly.
137
+ >
138
+ > `--smart` (IOC at best bid/ask ± 1 tick) exists only on pacifica / hyperliquid / lighter / aster, and is refused (`CAPABILITY_UNSUPPORTED`) together with `--tp`/`--sl` or `--client-id`/`--auto-id`.
139
+
140
+ Show the dry-run output to the user. Wait for confirmation.
141
+
142
+ ### Step 5: Execute
101
143
 
102
- ## Strategy Engine (19 bot algorithms + nested scripted plans)
144
+ After explicit user confirmation:
103
145
 
104
146
  ```bash
105
- perp strategy list-strategies # list all 19 strategies
106
- perp strategy run <strategy> [symbol] # run any registered strategy
107
- perp strategy run funding-auto # multi-exchange funding arb
108
- perp strategy apex [symbol] # APEX orchestrator (Radar+Pulse+Guard)
109
- perp strategy reflect # performance analysis (win rate, fees, PnL)
110
- perp strategy preset-list # list strategy presets
111
- perp strategy preset <name> [symbol] # run from preset
112
- perp strategy start <config.yaml> # start from YAML/JSON config
113
- perp strategy quick-grid <symbol> # quick grid bot
114
- perp strategy quick-dca <symbol> <side> <amount> <interval>
115
- perp strategy quick-arb # quick funding arb
147
+ # Perp-perp arb: legs are SEQUENTIAL — long first, then the short sized to the verified long fill;
148
+ # reconcile is always on (the long is trimmed reduce-only to the short's verified fill).
149
+ # An unconfirmed leg quarantines the symbol (see "Safety rules").
150
+ perp --json arb exec <SYM> <longEx> <shortEx> <USD> --smart
151
+
152
+ # Spot+perp arb (spot has 0 funding cost; spot:<venue> = hl, lt, lrh, aster, ondo)
153
+ perp --json arb exec <SYM> spot:hl hl <USD>
154
+ perp --json arb exec <SYM> spot:lt pac <USD>
155
+
156
+ # Single trade
157
+ perp --json -e <ex> trade buy <SYM> <SIZE> --smart
158
+ perp --json -e <ex> trade sell <SYM> <SIZE> --smart
159
+ perp --json -e <ex> trade split <SYM> buy <USD> --max-slippage 0.5
160
+ ```
161
+
162
+ HL spot uses U-tokens (`BTC→UBTC`, `ETH→UETH`, `SOL→USOL`) — auto-resolved.
116
163
 
117
- # Scripted plans (one-shot multi-step execution)
118
- perp strategy plan example # show plan format
119
- perp --json strategy plan validate <file> # validate before run
120
- perp --json strategy plan execute <file> --dry-run # dry-run plan
164
+ ### Step 6: Monitor
121
165
 
122
- # Background process supervisor (tmux)
123
- perp background list # list running jobs
124
- perp background stop <id> # stop a job
125
- perp background logs <id> -f # follow logs
166
+ ```bash
167
+ perp --json arb status # open arb positions, PnL, funding earned
168
+ perp --json portfolio # cross-exchange equity + risk
169
+ perp --json risk status # canTrade, level, violations
170
+ perp --json risk liquidation-distance # % from liq for ALL positions
126
171
  ```
127
172
 
128
- **Strategies:** grid, dca, funding-arb, funding-arb-v2, funding-auto, basis-arb, simple-mm, engine-mm, avellaneda-mm, regime-mm, grid-mm, liquidation-mm, momentum-breakout, mean-reversion, aggressive-taker, hedge-agent, rfq-agent, claude-agent, apex
173
+ If `risk status.canTrade === false`, do NOT open new positions. If liquidation distance falls below the user's `--min-liq-distance`, recommend reducing position size.
129
174
 
130
- **Flags:** `--dry-run` (simulate without executing), `--headless` (no TUI, log only)
175
+ For continuous monitoring, run `bash scripts/arb-monitor.sh --json`.
131
176
 
132
- ## Core Workflow: Single Trade
177
+ ### Step 7: Close
133
178
 
134
179
  ```bash
135
- perp --json -e <EX> trade buy <SYM> <SIZE> # market buy (SIZE = token units)
136
- perp --json -e <EX> trade sell <SYM> <SIZE> # market sell
137
- perp --json -e <EX> trade buy <SYM> <SIZE> --smart # IOC limit at best ask
138
- perp --json -e <EX> trade split <SYM> buy <USD> # orderbook-aware split
139
- perp --json -e <EX> trade limit <SYM> buy <PRICE> <SIZE>
140
- perp --json -e <EX> trade tpsl <SYM> buy --tp <P> --sl <P>
141
- perp --json -e <EX> trade close <SYM>
142
- perp --json -e <EX> trade flatten # close ALL + cancel ALL
143
- perp --json -e <EX> trade cancel <SYM> # cancel all orders for symbol
180
+ perp --json arb close <SYM> # perp-perp arb
181
+ perp --json arb close <SYM> --pair <longEx>:<shortEx> # disambiguate
182
+ perp --json arb close <SYM> --spot-exch hl --perp-exch hl # spot+perp
183
+ perp --json arb close <SYM> --smart # IOC limits
184
+ perp --json arb close <SYM> --force # quarantined symbol — only after the user checked positions
185
+ perp --json arb close <SYM> --state-only --yes # drop a stale state entry (arb status staleStateEntries); sends no order
186
+
187
+ # Single trade
188
+ perp --json -e <ex> trade close <SYM> # close one symbol
189
+ perp --json -e <ex> trade close-all # close all positions on this exchange
190
+ perp --json -e <ex> trade flatten # close ALL + cancel ALL orders
144
191
  ```
145
192
 
146
- ## Agent Tools
193
+ ### Funds workflow (deposit / withdraw / transfer / bridge / rebalance)
194
+
195
+ All money movement lives under `perp funds`:
147
196
 
148
197
  ```bash
149
- perp --json -e <EX> trade check <SYM> <SIDE> <SIZE> # pre-validate trade
150
- perp --json portfolio # balances + positions + risk level
151
- perp --json --fields totalEquity,positions portfolio # filtered output
198
+ # Exchange in/out
199
+ perp --json funds deposit hyperliquid 100
200
+ perp --json funds deposit pacifica 100
201
+ perp --json funds deposit lighter ethereum 100 # L1 direct
202
+ perp --json funds deposit lighter cctp arbitrum 100 # via CCTP
203
+ perp --json funds withdraw hyperliquid 100 [--chain arbitrum|ethereum|base] # CCTP to your own wallet
204
+ perp --json funds transfer 100 <ADDRESS> # HL internal (instant) — allowlisted destinations only
205
+
206
+ # Cross-chain bridge (auto-cheapest cctp/relay/debridge)
207
+ perp --json funds bridge quote --from solana --to arbitrum --amount 100
208
+ perp --json funds bridge send --from solana --to arbitrum --amount 100
209
+ perp --json funds bridge status <orderId> # poll until success
210
+
211
+ # Inter-exchange rebalance
212
+ perp --json funds rebalance check
213
+ perp --json funds rebalance plan
214
+ perp --json --dry-run funds rebalance execute --auto-bridge # status "simulated" (moves[].status "dry_run"), or "balanced" (nothing to move)
215
+ perp --json funds rebalance execute --auto-bridge # withdraw → bridge ONLY; no deposit
152
216
  ```
153
217
 
154
- ## Position Sizing & Safety
218
+ Always run `funds bridge quote` before `funds bridge send` so the user sees fees + ETA.
219
+
220
+ - `funds rebalance execute` returns `ok:true` even when a move failed: check EVERY `moves[].status` (`withdrawn`, `bridged`, `same_chain`, `needs_bridge`, `withdraw_failed`, `bridge_failed`). It never deposits — after the bridge arrives, deposit manually (`funds deposit <venue> <amt>`).
221
+ - `funds transfer <amt> <addr>` (HL) and `funds withdraw hyperliquid --to <other address>` require the destination on the `settings withdraw.hyperliquid` allowlist (`POLICY_DENIED` otherwise). Only the user can set it, in an interactive terminal (`--json` / piped → `POLICY_DENIED`). NEVER try to set or change `withdraw.<venue>` yourself.
222
+ - HL withdraw goes over CCTP (native USDC); on Arbitrum a 0.2 USDC forwarding fee is deducted (an amount ≤ the fee → `SIZE_TOO_SMALL`).
223
+ - Bridges: exactly `--amount` leaves the wallet (fees come out of it); a deBridge `nativeFee` is shown separately and is paid in the source chain's native token. Solana-origin deBridge is refused (`NO_BRIDGE_ROUTE`) → `--provider cctp`. `--fast` = fast CCTP finality (higher fee).
224
+ - `funds bridge exchange --from <ex> --to <ex>` bridges the master wallet's OWN USDC between the venues' chains (pacifica → solana, lighter → arbitrum); it does NOT withdraw from / deposit into Pacifica or Lighter. Exception hyperliquid: `--from hyperliquid` spends HyperCore spot USDC, `--to hyperliquid` credits HyperCore perps. HyperCore → Solana is refused (`NO_BRIDGE_ROUTE`).
225
+
226
+ Relay swaps between assets (`--from-asset` / `--to-asset`, chains `robinhood`, `arbitrum`, `bsc`, `base`, destination `solana`): run `perp --json --dry-run funds bridge send ...` first — it prints the locally verified quote (amount in, expected out, protocol-guaranteed minimum, fees, ETA) and the min-out verdict without loading a key. Stable → native (e.g. USDG → SOL / ETH) needs `--min-out`. The recipient is always the master wallet's own address; an `ORDER_PENDING` result carries the Relay request id — never bridge again before checking it.
227
+
228
+ ### Strategy engine (20 algorithms + scripted plans)
155
229
 
156
- - Single position < **80%** of that exchange's available balance
157
- - Leverage 1-3x for arb, max 5x
158
- - `arb exec` auto-matches both legs to the same size
159
- - ALWAYS follow `longExch`/`shortExch` from scan — NEVER reverse direction
160
- - NEVER enter if `netSpread <= 0` or `netSpread < estimated round-trip slippage`
161
- - Check `portfolio.risk.canTrade` — if `false`, do NOT trade
230
+ ```bash
231
+ perp strategy list-strategies # 20 registered
232
+ perp strategy run <strategy> [symbol] # run any strategy (multi-venue: --exchanges must include the -e venue)
233
+ perp --json --dry-run strategy run <strategy> [symbol] # simulate: actions logged, never sent
234
+ perp strategy apex [symbol] # APEX orchestrator
235
+ perp strategy reflect # performance analysis
236
+ perp --json strategy plan validate <FILE> # validate scripted plan
237
+ perp --json strategy plan execute <FILE> --dry-run # dry-run scripted plan
238
+ ```
239
+
240
+ **Strategies:** `grid`, `dca`, `simple-mm`, `engine-mm`, `avellaneda-mm`, `regime-mm`, `grid-mm`, `liquidation-mm`, `momentum-breakout`, `mean-reversion`, `aggressive-taker`, `funding-arb`, `funding-arb-v2`, `funding-auto`, `basis-arb`, `spot-perp-arb`, `hedge-agent`, `rfq-agent`, `claude-agent`, `apex`.
162
241
 
163
- ## HIP-3 Support
242
+ Background daemon (tmux):
164
243
 
165
244
  ```bash
166
- perp --json -e hl --dex km market list # dex-specific markets
167
- perp --json market list --hip3 # all HIP-3 markets
168
- perp --json account positions --hip3 # HIP-3 positions
169
- perp --json arb scan --hip3 # HIP-3 arb opportunities
245
+ perp --json --dry-run arb auto --min-spread 30 --size 100 # simulate first (--background inherits --dry-run)
246
+ perp --json arb auto --min-spread 30 --size 100 --background
247
+ perp --json background list
248
+ perp --json background logs <id> -f
249
+ perp --json background stop <id> [--timeout 90] # graceful: SIGINT, job cancels its orders, waits, reports what is left on the venue
170
250
  ```
171
251
 
172
- ## Error Handling
252
+ `strategy funding-arb` is monitor-only unless `--auto-execute`. Bots: `equity` is `null` when a balance read fails — arb strategies then skip new entries and the bot stops after 10 consecutive unknown ticks; `ordersPlaced` counts orders sent, `fills` only venue-reported fills — a resting order is placed, not filled.
173
253
 
174
- Response format: `{ "ok": true, "data": {...} }` or `{ "ok": false, "error": { "code": "...", "retryable": true/false } }`
254
+ Background jobs inherit the parent's `-n`, `--dry-run`, `-e`, `--ows`, `-w`, `--no-agent`, `--dex`, and never receive key material (argv/env): they resolve credentials from the OWS vault / agent keystores / `~/.perp/.env` themselves. `--background` with `-k`, `--passphrase`, `--ows-key` or a shell-exported key / `OWS_PASSPHRASE` → `INVALID_PARAMS` — register an agent (`perp wallet agent approve <venue>`), which signs without the master passphrase.
175
255
 
176
- | Error | Action |
177
- |-------|--------|
178
- | `RATE_LIMITED` | wait 5s, retry (max 3). Lighter: space 3s+ apart |
179
- | `EXCHANGE_UNREACHABLE` | wait 10s, retry. 3x fail → skip exchange |
180
- | `INSUFFICIENT_BALANCE` | reduce size or bridge funds |
181
- | `SYMBOL_NOT_FOUND` | `market list` to verify symbol |
182
- | `SIZE_TOO_SMALL` | `market info <SYM>` for min size |
183
- | `DUPLICATE_ORDER` | already submitted — check positions |
184
- | Lighter `invalid signature` | `perp wallet agent approve lighter` to regenerate |
256
+ ### Position sizing & safety
257
+
258
+ - Single position notional < **80%** of that exchange's available balance.
259
+ - Leverage 1–3x for arb; never above 5x for arb positions.
260
+ - `arb exec` sizes the short to the verified long fill and always reconciles; still check `arb status` (`unconfirmedPairs`, `staleStateEntries`) afterwards.
261
+ - ALWAYS follow `longExch`/`shortExch` from `arb scan` — NEVER reverse direction.
262
+ - NEVER enter if `netSpread <= 0` or `netSpread < estimated round-trip slippage`.
263
+ - Capital that's mid-bridge is "at risk" and unhedged — factor it in.
264
+
265
+ For deeper risk-management framework, read `references/strategies.md`.
185
266
 
186
267
  ## Examples
187
268
 
188
- **"Find arb opportunities"**
269
+ ### Example 1: "Find funding-rate arb opportunities"
270
+
189
271
  ```bash
272
+ # 1. Discover
190
273
  perp --json arb scan --min 10 --top 10
191
- perp --json account balance
192
- # → show results, recommend best, ask confirmation
274
+ # 2. Show top 3 to user; ask which to evaluate
275
+ # 3. Check balances on the two exchanges
276
+ perp --json portfolio -e <longEx>
277
+ perp --json portfolio -e <shortEx>
278
+ # 4. Recommend size + dry-run
279
+ perp --json --dry-run arb exec BTC <longEx> <shortEx> 100
280
+ # 5. After user confirmation:
281
+ perp --json arb exec BTC <longEx> <shortEx> 100 --smart
282
+ perp --json arb status
193
283
  ```
194
284
 
195
- **"ETH spot-perp arb, $100"**
285
+ ### Example 2: "ETH spot+perp arb, $100"
286
+
196
287
  ```bash
197
288
  perp --json --dry-run arb exec ETH spot:hl hl 100
198
289
  # → show dry-run, ask confirmation
199
290
  perp --json arb exec ETH spot:hl hl 100
200
291
  perp --json arb status
292
+ # Later, to close both legs:
293
+ perp --json arb close ETH --spot-exch hl --perp-exch hl
201
294
  ```
202
295
 
203
- **"Long SOL 0.5 on HL"**
296
+ ### Example 3: "Long SOL 0.5 on Hyperliquid with 2x leverage"
297
+
204
298
  ```bash
205
- perp --json -e hl trade check SOL buy 0.5
299
+ perp --json -e hl wallet manage margin SOL isolated # use isolated margin for new trade
300
+ perp --json -e hl trade leverage SOL 2 --isolated
301
+ perp --json -e hl trade check SOL buy 0.5 --leverage 2
206
302
  perp --json --dry-run -e hl trade buy SOL 0.5 --smart
207
- # → ask confirmation
303
+ # → show dry-run, ask confirmation
208
304
  perp --json -e hl trade buy SOL 0.5 --smart
305
+ perp --json -e hl account positions
306
+ ```
307
+
308
+ ### Example 4: "Move 500 USDC from Pacifica to Hyperliquid"
309
+
310
+ ```bash
311
+ perp --json funds withdraw pacifica 500
312
+ perp --json funds bridge quote --from solana --to arbitrum --amount 500
313
+ # → show fee, ETA, ask confirmation
314
+ perp --json funds bridge send --from solana --to arbitrum --amount 500
315
+ perp --json funds bridge status <orderId> # poll until completed
316
+ perp --json funds deposit hyperliquid 500
317
+ ```
318
+
319
+ `funds rebalance execute --auto-bridge` only withdraws and bridges — check every `moves[].status`, then deposit by hand (`funds deposit hyperliquid <amt>`) after the bridge arrives.
320
+
321
+ ### Example 5: "Run a delta-neutral funding bot in background"
322
+
323
+ ```bash
324
+ perp --json --dry-run arb auto --min-spread 30 --close-spread 5 --size 100 --max-positions 5
325
+ # → show the simulation, ask confirmation
326
+ perp --json arb auto --min-spread 30 --close-spread 5 --size 100 --max-positions 5 --background
327
+ perp --json background list
328
+ perp --json background logs <id> -f
329
+ # To stop:
330
+ perp --json background stop <id>
331
+ ```
332
+
333
+ ## Troubleshooting
334
+
335
+ Every response is `{ "ok": true, "data": ... }` or `{ "ok": false, "error": { "code": "...", "retryable": true|false, "remediation"?: "..." } }`; `ok:false` exits 1. Always check `ok` first and follow `error.remediation`. `retryable: true` → wait and retry ONCE, and only for read-only commands — a write is never blindly retried.
336
+
337
+ | Error code | Meaning | Action |
338
+ |---|---|---|
339
+ | `ORDER_PENDING` | A write was sent, outcome unknown | NEVER resubmit. See "Safety rules". |
340
+ | `ORDER_PARTIAL` | Part of a multi-leg / close succeeded | Don't retry; check positions per venue, close residuals by hand (may be quarantined). |
341
+ | `ORDER_REJECTED` / `ACTION_REJECTED` | Definitely not placed / not executed | Fix the cause from `error.message`; a new attempt is a new decision (ask the user). |
342
+ | `RISK_VIOLATION` | Local risk limit breached, or symbol quarantined | Report to the user. `--force` only with explicit user consent, and never bypasses quarantine. |
343
+ | `CAPABILITY_UNSUPPORTED` | Venue/feature combination not offered | Do NOT work around it (no emulation via other orders/venues); tell the user. |
344
+ | `INVALID_TICK` | Limit/trigger price off the venue grid (HL: ≤ 5 significant figures) | Refused, never rounded — re-price on the grid and confirm with the user. |
345
+ | `INVALID_PARAMS` | Bad argument (incl. strict sizes: `1,000` / `1e3` / `10abc` refused; `--dry-run` on a command without dry-run) | Fix the argument. |
346
+ | `CLI_ERROR` | Command parse error (unknown command / missing option) | Check `<cmd> --help`. |
347
+ | `NO_SIGNER_AVAILABLE` | No key that may sign this (e.g. imported agent key for a master-only action) | User does it on the website, or `perp wallet import`s the master. |
348
+ | `AGENT_NOT_REGISTERED` / `AGENT_EXPIRED` | Agent key missing, on the other network, or expired | Follow `remediation`: master on this computer → `perp wallet agent approve <venue> [--rotate]` (master-signed: user consent); imported key → new key on the website, `wallet agent import <venue> --replace`. |
349
+ | `POLICY_DENIED` | Local withdraw gate / OWS policy refused | Never change `withdraw.<venue>` — only the user can, in a terminal. |
350
+ | `PASSPHRASE_REQUIRED` | Vault passphrase needed | Ask the user to provide `OWS_PASSPHRASE` (or stdin); never put it on argv. |
351
+ | `LOCK_HELD` | Another perp process holds a state lock | Wait ~5s and retry once; check `background list`. |
352
+ | `NO_BRIDGE_ROUTE` | No supported bridge route (e.g. deBridge from Solana, HyperCore → Solana) | Use the route in `remediation` (e.g. `--provider cctp`). |
353
+ | `RATE_LIMITED` / `EXCHANGE_UNREACHABLE` | Throttled / API down (reads) | Wait 5–10s, retry once; then skip that venue. |
354
+ | `INSUFFICIENT_BALANCE` | Not enough collateral on that venue | Reduce size or move funds first (user-confirmed). |
355
+ | `SYMBOL_NOT_FOUND` | Not listed on this venue | `market list`. Don't add `-PERP`. |
356
+ | `SIZE_TOO_SMALL` | Below venue minimum (HL TWAP: $100 total) | Compute `size × price`; raise size. |
357
+
358
+ `--client-id` (`trade market/buy/sell/limit`): an id already recorded in `~/.perp/client-ids.jsonl` (and not marked failed) returns `ok:true` with `data.duplicate: true` and sends nothing — local tracking only, not a venue check (it is NOT a `DUPLICATE_ORDER` error). Formats: Pacifica a full UUID, Hyperliquid `0x` + 32 hex; QFEX refuses `--client-id` (use `--auto-id`); `--smart` + client id → `CAPABILITY_UNSUPPORTED`.
359
+
360
+ ## Safety rules
361
+
362
+ - **Unknown outcome (`ORDER_PENDING`) on ANY write** — orders, cancels, edits, leverage, withdraw / deposit / bridge / transfer: do NOT resubmit. Check `perp --json -e <ex> trade status c:<id> --symbol <S>` (the id in `remediation`), `account orders` / `account positions` / `portfolio`, and the tx hash / request id in `error.details` (`funds bridge status <id>` for bridges). Report to the user.
363
+ - **Quarantine**: an unknown or unhedged outcome (arb, bots, `trade close`, `trade multi`) quarantines the symbol — global per symbol, scoped by network. It blocks opening orders, `arb exec`, `arb auto` and bots (`RISK_VIOLATION`); reduce-only orders pass. List: `perp --json strategy quarantine`. Clear only after the USER has verified the positions on the venues: `perp --json strategy quarantine-clear <SYM>`. `arb close` on a quarantined symbol needs `--force`.
364
+ - **Risk gate**: `trade market / buy / sell / limit / split / market --split / scale-in / twap / multi / stop --no-reduce-only` check `~/.perp/risk.json` (`perp risk limits ...`); reduce-only is exempt. `--force` bypasses the limits (never quarantine) — only with explicit user consent.
365
+ - **Stops** (`trade stop`, `tpsl`) are reduce-only by default; `--no-reduce-only` is refused on ondo and qfex. `trade tpsl <SYM> long|short` = the OPEN position's side; legs are sized to the live position.
366
+ - **Dry-run is default-deny**: commands that cannot simulate refuse `--dry-run` with `INVALID_PARAMS` (e.g. `trade twap`, `trade multi`, `trade cancel-stop`, `trade cancel-twap`, `strategy start / preset / grid / dca / quick-* / funding-arb`, `wallet agent approve`, `wallet rotate`). Simulate bots with `perp --json --dry-run strategy run <strategy>` / `perp --json --dry-run arb auto`.
367
+ - **A dry-run is not a full venue check**: it validates arguments, the risk gate and quarantine, but some venue rules are enforced only on the live send — e.g. an off-grid limit price (`INVALID_TICK`) or `--no-reduce-only` on ondo / qfex (`CAPABILITY_UNSUPPORTED`). Those refusals happen before anything is sent.
368
+ - **`wallet rotate`** creates a new wallet and transfers assets, with no dry-run — only on the user's explicit request.
369
+
370
+ ### Common mistakes
371
+
372
+ - **Forgetting `--json`** → output becomes unparseable human text. The very first thing to check when parsing fails.
373
+ - **Using legacy command names** — `arb rates`/`arb prices`/`arb dex`/`arb spot-exec`/`arb spot-close` are removed. Use `arb scan --rates|--gaps|--hip3` and `arb exec spot:<exch>` / `arb close <SYM> --spot-exch <ex>`.
374
+ - **Calling `trade check` without `--leverage`** → cost estimate doesn't match what the exchange applies.
375
+ - **Retrying a non-idempotent trade** without checking `account positions` → opens a duplicate position.
376
+ - **Bridging without quoting first** → user sees no fee/ETA and can't approve cleanly.
377
+ - **Treating `bridge send` as instant** → always `funds bridge status <orderId>` before depositing on the destination.
378
+ - **Manually adding `-PERP` suffix** → CLI auto-resolves; let it.
379
+
380
+ For a full troubleshooting + non-interactive flow guide, read `references/agent-operations.md`.
381
+
382
+ ## Referrals (optional, ask once per setup)
383
+
384
+ ```bash
385
+ perp --json --dry-run -e hyperliquid wallet manage referral set # preview (nothing signed)
386
+ perp --json -e hyperliquid wallet manage referral set [code] # signs + sends ONE referral action
387
+ perp --json -e lighter wallet manage referral set [code] # Lighter (needs an agent key)
209
388
  ```
210
389
 
211
- ## Referrals (Optional)
390
+ Referral codes are never applied implicitly (adapter creation signs nothing). When the user first sets up a wallet, ask:
391
+ > "perp-cli development is supported by optional referrals. Apply the referral code? It signs one referral action on the venue; no extra fees — only exchange rebates are used."
392
+
393
+ ## Builder fees (OFF by default — never enable on your own)
394
+
395
+ Builder fees are extra fees on the USER's perp orders, paid to a third-party builder. perp-cli attaches none unless the user explicitly set `settings builder.<venue>` AND the venue approval is confirmed. Do not configure or approve a builder unless the user asks for it.
212
396
 
213
397
  ```bash
214
- perp --json settings referrals on # enable (opt-in, no extra fees)
215
- perp --json settings referrals off # disable anytime
398
+ perp --json wallet builder status [venue] # support, config, approval, attaches?
399
+ perp --json --dry-run wallet builder approve <venue> # plan only — show it to the user
400
+ perp --json wallet builder approve <venue> --yes # only after explicit user consent (master-signed)
401
+ perp --json --no-builder -e <ex> trade market BTC buy 0.1 # one run without the fee
216
402
  ```
217
403
 
218
- When setting up wallets for the first time, ask:
219
- > "perp-cli development is supported by optional referrals. Enable? No extra fees — only exchange rebates are used."
404
+ qfex: `builder.qfex <uuid>` is a fee share (no extra fee, no approval; mainnet only). Unsupported: lighter, lighter-rh, arcus (`CAPABILITY_UNSUPPORTED`). An order whose approval is missing or unknown is sent without the fee (`execution.notes`); `execution.builderFee` records what was attached.
405
+
406
+ ## MCP Server
407
+
408
+ The package also ships a 22-tool MCP server (no API keys required for read-only market data — `get_markets`, `get_orderbook`, `get_funding_rates`, `get_prices`, `get_outcome_markets`, `get_outcome_view`, `get_outcome_book`, plus 15 account/advisor tools):
409
+
410
+ MCP network: `PERP_NETWORK=mainnet|testnet` (validated; unset = mainnet); every result's `meta.network` says which. The only write tools, `trade_execute` / `trade_close`, run the same local risk gate as `perp trade` (no override over MCP), refuse non-reduce-only orders on quarantined symbols, and log every order.
411
+
412
+ ```json
413
+ {
414
+ "mcpServers": {
415
+ "perp-cli": {
416
+ "command": "npx",
417
+ "args": ["-y", "-p", "perp-cli", "perp-mcp"]
418
+ }
419
+ }
420
+ }
421
+ ```
422
+
423
+ [![Glama MCP server](https://glama.ai/mcp/servers/hypurrquant/perp-cli/badges/score.svg)](https://glama.ai/mcp/servers/hypurrquant/perp-cli)