perp-cli 0.14.3 → 0.16.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 (363) hide show
  1. package/README.ja.md +243 -0
  2. package/README.ko.md +243 -0
  3. package/README.md +138 -405
  4. package/README.zh.md +243 -0
  5. package/dist/agent-wallet/store.d.ts +3 -2
  6. package/dist/agent-wallet/store.js +2 -2
  7. package/dist/api/public/hyperliquid.js +4 -0
  8. package/dist/api/public/lighter.d.ts +5 -0
  9. package/dist/api/public/lighter.js +5 -0
  10. package/dist/api/public/pacifica.js +85 -15
  11. package/dist/api/public/urls.d.ts +2 -0
  12. package/dist/api/public/urls.js +3 -0
  13. package/dist/arb/sizing.js +4 -2
  14. package/dist/arb/state.d.ts +6 -0
  15. package/dist/arb/utils.d.ts +1 -2
  16. package/dist/arb/utils.js +1 -2
  17. package/dist/balance-by-address.d.ts +39 -0
  18. package/dist/balance-by-address.js +44 -0
  19. package/dist/bot/apex/pulse.js +3 -0
  20. package/dist/bot/apex/radar.js +2 -1
  21. package/dist/bot/engine.d.ts +10 -1
  22. package/dist/bot/engine.js +14 -6
  23. package/dist/bot/indicators.d.ts +7 -0
  24. package/dist/bot/indicators.js +16 -0
  25. package/dist/bot/perp-order.d.ts +4 -4
  26. package/dist/bot/perp-order.js +5 -5
  27. package/dist/bot/quarantine.d.ts +1 -1
  28. package/dist/bot/quarantine.js +1 -1
  29. package/dist/bot/quote-rules.js +1 -1
  30. package/dist/bot/strategies/apex-strategy.js +3 -2
  31. package/dist/bot/strategies/engine-mm.js +6 -5
  32. package/dist/bot/strategies/funding-arb-strategy.js +12 -5
  33. package/dist/bot/strategies/funding-arb-utils.d.ts +15 -3
  34. package/dist/bot/strategies/funding-arb-utils.js +53 -20
  35. package/dist/bot/strategies/funding-auto.js +2 -2
  36. package/dist/bot/strategies/liquidation-mm.d.ts +1 -0
  37. package/dist/bot/strategies/liquidation-mm.js +8 -2
  38. package/dist/bot/strategies/momentum-breakout.d.ts +1 -0
  39. package/dist/bot/strategies/momentum-breakout.js +11 -3
  40. package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +1 -1
  41. package/dist/bot/strategies/spot-perp-arb-strategy.js +6 -4
  42. package/dist/bot/strategies/spot-perp-executor.d.ts +1 -1
  43. package/dist/bot/strategies/spot-perp-executor.js +3 -3
  44. package/dist/bot/strategy-types.d.ts +2 -1
  45. package/dist/bot/tui/BotDashboard.d.ts +1 -1
  46. package/dist/bot/tui/BotDashboard.js +1 -1
  47. package/dist/cache.js +12 -6
  48. package/dist/cli-program.d.ts +15 -0
  49. package/dist/cli-program.js +126 -6
  50. package/dist/commands/account.js +168 -24
  51. package/dist/commands/agent-import.d.ts +7 -0
  52. package/dist/commands/agent-import.js +30 -1
  53. package/dist/commands/agent.d.ts +6 -3
  54. package/dist/commands/agent.js +160 -12
  55. package/dist/commands/arb/index.js +23 -81
  56. package/dist/commands/arb-auto.d.ts +24 -0
  57. package/dist/commands/arb-auto.js +175 -97
  58. package/dist/commands/arb.d.ts +20 -0
  59. package/dist/commands/arb.js +107 -163
  60. package/dist/commands/backtest.js +23 -21
  61. package/dist/commands/bot.js +1 -1
  62. package/dist/commands/builder.js +1 -1
  63. package/dist/commands/funds.js +113 -3
  64. package/dist/commands/init.d.ts +1 -1
  65. package/dist/commands/init.js +27 -7
  66. package/dist/commands/manage.js +23 -21
  67. package/dist/commands/market.d.ts +48 -0
  68. package/dist/commands/market.js +395 -100
  69. package/dist/commands/options.d.ts +14 -0
  70. package/dist/commands/options.js +151 -0
  71. package/dist/commands/pacifica-earn.d.ts +5 -0
  72. package/dist/commands/pacifica-earn.js +455 -0
  73. package/dist/commands/pacifica-orders.d.ts +14 -0
  74. package/dist/commands/pacifica-orders.js +142 -0
  75. package/dist/commands/portfolio.d.ts +16 -0
  76. package/dist/commands/portfolio.js +83 -55
  77. package/dist/commands/rebalance.d.ts +1 -0
  78. package/dist/commands/rebalance.js +15 -0
  79. package/dist/commands/risk.d.ts +11 -2
  80. package/dist/commands/risk.js +39 -44
  81. package/dist/commands/trade.d.ts +1 -0
  82. package/dist/commands/trade.js +67 -62
  83. package/dist/commands/wallet.js +1 -1
  84. package/dist/config.d.ts +2 -2
  85. package/dist/config.js +15 -4
  86. package/dist/constants.js +6 -0
  87. package/dist/cross-chain-margin.d.ts +3 -1
  88. package/dist/cross-chain-margin.js +4 -2
  89. package/dist/dashboard/server.js +3 -3
  90. package/dist/dashboard/ui.js +9 -6
  91. package/dist/errors.d.ts +29 -1
  92. package/dist/errors.js +35 -3
  93. package/dist/exchanges/address.d.ts +8 -0
  94. package/dist/exchanges/address.js +47 -0
  95. package/dist/exchanges/arcus/adapter.d.ts +16 -12
  96. package/dist/exchanges/arcus/adapter.js +45 -18
  97. package/dist/exchanges/arcus/agent.d.ts +1 -1
  98. package/dist/exchanges/arcus/agent.js +1 -1
  99. package/dist/exchanges/arcus/client.js +1 -1
  100. package/dist/exchanges/arcus/public.js +3 -2
  101. package/dist/exchanges/arcus/signing.d.ts +2 -3
  102. package/dist/exchanges/arcus/signing.js +1 -1
  103. package/dist/exchanges/arcus/spot-chain.d.ts +1 -1
  104. package/dist/exchanges/arcus/spot-chain.js +1 -1
  105. package/dist/exchanges/arcus/spot-router.d.ts +1 -1
  106. package/dist/exchanges/arcus/spot-router.js +2 -2
  107. package/dist/exchanges/arcus/spot.d.ts +2 -3
  108. package/dist/exchanges/arcus/spot.js +2 -3
  109. package/dist/exchanges/aster-spot.d.ts +3 -3
  110. package/dist/exchanges/aster-spot.js +6 -9
  111. package/dist/exchanges/aster-typed-data.d.ts +1 -1
  112. package/dist/exchanges/aster-typed-data.js +1 -1
  113. package/dist/exchanges/aster.d.ts +30 -10
  114. package/dist/exchanges/aster.js +153 -53
  115. package/dist/exchanges/builder-fee.d.ts +1 -1
  116. package/dist/exchanges/builder-fee.js +13 -2
  117. package/dist/exchanges/canonical-symbols.d.ts +8 -2
  118. package/dist/exchanges/canonical-symbols.js +46 -2
  119. package/dist/exchanges/capabilities.d.ts +2 -0
  120. package/dist/exchanges/capabilities.js +2 -1
  121. package/dist/exchanges/derive/client.d.ts +37 -0
  122. package/dist/exchanges/derive/client.js +135 -0
  123. package/dist/exchanges/derive/options.d.ts +73 -0
  124. package/dist/exchanges/derive/options.js +379 -0
  125. package/dist/exchanges/extended/adapter.d.ts +96 -0
  126. package/dist/exchanges/extended/adapter.js +241 -0
  127. package/dist/exchanges/extended/client.d.ts +38 -0
  128. package/dist/exchanges/extended/client.js +88 -0
  129. package/dist/exchanges/extended/public.d.ts +133 -0
  130. package/dist/exchanges/extended/public.js +436 -0
  131. package/dist/exchanges/grvt/adapter.d.ts +100 -0
  132. package/dist/exchanges/grvt/adapter.js +283 -0
  133. package/dist/exchanges/grvt/client.d.ts +25 -0
  134. package/dist/exchanges/grvt/client.js +86 -0
  135. package/dist/exchanges/grvt/public.d.ts +151 -0
  136. package/dist/exchanges/grvt/public.js +438 -0
  137. package/dist/exchanges/hyperliquid-outcome.d.ts +2 -0
  138. package/dist/exchanges/hyperliquid-outcome.js +29 -1
  139. package/dist/exchanges/hyperliquid-spot.d.ts +9 -1
  140. package/dist/exchanges/hyperliquid-spot.js +24 -16
  141. package/dist/exchanges/hyperliquid.d.ts +199 -22
  142. package/dist/exchanges/hyperliquid.js +550 -202
  143. package/dist/exchanges/index.d.ts +1 -1
  144. package/dist/exchanges/index.js +1 -1
  145. package/dist/exchanges/interface.d.ts +157 -13
  146. package/dist/exchanges/interface.js +47 -0
  147. package/dist/exchanges/ioc-outcome.d.ts +1 -1
  148. package/dist/exchanges/ioc-outcome.js +1 -1
  149. package/dist/exchanges/legacy-trading-v2.d.ts +2 -2
  150. package/dist/exchanges/legacy-trading-v2.js +7 -2
  151. package/dist/exchanges/lighter-public.d.ts +67 -12
  152. package/dist/exchanges/lighter-public.js +250 -82
  153. package/dist/exchanges/lighter-signer.d.ts +1 -1
  154. package/dist/exchanges/lighter-signer.js +1 -1
  155. package/dist/exchanges/lighter-spot.d.ts +10 -5
  156. package/dist/exchanges/lighter-spot.js +105 -97
  157. package/dist/exchanges/lighter.d.ts +80 -21
  158. package/dist/exchanges/lighter.js +312 -105
  159. package/dist/exchanges/ondo/adapter.d.ts +38 -13
  160. package/dist/exchanges/ondo/adapter.js +86 -27
  161. package/dist/exchanges/ondo/agent.d.ts +1 -1
  162. package/dist/exchanges/ondo/agent.js +1 -1
  163. package/dist/exchanges/ondo/client.d.ts +1 -1
  164. package/dist/exchanges/ondo/client.js +2 -2
  165. package/dist/exchanges/ondo/public.d.ts +35 -3
  166. package/dist/exchanges/ondo/public.js +75 -32
  167. package/dist/exchanges/ondo/spot.d.ts +2 -2
  168. package/dist/exchanges/ondo/spot.js +3 -3
  169. package/dist/exchanges/options-interface.d.ts +158 -0
  170. package/dist/exchanges/options-interface.js +17 -0
  171. package/dist/exchanges/options-venues.d.ts +12 -0
  172. package/dist/exchanges/options-venues.js +35 -0
  173. package/dist/exchanges/outcome-interface.d.ts +4 -0
  174. package/dist/exchanges/pacifica-atomic.d.ts +211 -0
  175. package/dist/exchanges/pacifica-atomic.js +440 -0
  176. package/dist/exchanges/pacifica-decimal.d.ts +10 -0
  177. package/dist/exchanges/pacifica-decimal.js +51 -0
  178. package/dist/exchanges/pacifica-presigned.d.ts +53 -0
  179. package/dist/exchanges/pacifica-presigned.js +141 -0
  180. package/dist/exchanges/pacifica-print.d.ts +200 -0
  181. package/dist/exchanges/pacifica-print.js +417 -0
  182. package/dist/exchanges/pacifica-spot.d.ts +8 -2
  183. package/dist/exchanges/pacifica-spot.js +26 -18
  184. package/dist/exchanges/pacifica-typed-data.d.ts +1 -1
  185. package/dist/exchanges/pacifica-typed-data.js +1 -1
  186. package/dist/exchanges/pacifica-vaults.d.ts +130 -0
  187. package/dist/exchanges/pacifica-vaults.js +277 -0
  188. package/dist/exchanges/pacifica.d.ts +108 -10
  189. package/dist/exchanges/pacifica.js +428 -171
  190. package/dist/exchanges/precision.d.ts +3 -1
  191. package/dist/exchanges/precision.js +9 -2
  192. package/dist/exchanges/public-balances.d.ts +25 -0
  193. package/dist/exchanges/public-balances.js +158 -0
  194. package/dist/exchanges/public-positions.d.ts +43 -0
  195. package/dist/exchanges/public-positions.js +154 -0
  196. package/dist/exchanges/qfex/adapter.d.ts +69 -13
  197. package/dist/exchanges/qfex/adapter.js +102 -17
  198. package/dist/exchanges/qfex/agent.d.ts +1 -1
  199. package/dist/exchanges/qfex/agent.js +1 -1
  200. package/dist/exchanges/qfex/client.d.ts +1 -1
  201. package/dist/exchanges/qfex/client.js +1 -1
  202. package/dist/exchanges/qfex/errors.d.ts +1 -1
  203. package/dist/exchanges/qfex/errors.js +2 -2
  204. package/dist/exchanges/qfex/public.d.ts +65 -12
  205. package/dist/exchanges/qfex/public.js +131 -25
  206. package/dist/exchanges/qfex/signing.d.ts +2 -2
  207. package/dist/exchanges/qfex/signing.js +4 -5
  208. package/dist/exchanges/qfex/ws-transport.d.ts +3 -3
  209. package/dist/exchanges/qfex/ws-transport.js +3 -3
  210. package/dist/exchanges/rate-limiter.d.ts +1 -1
  211. package/dist/exchanges/rate-limiter.js +5 -2
  212. package/dist/exchanges/registry.d.ts +1 -1
  213. package/dist/exchanges/registry.js +1 -1
  214. package/dist/exchanges/risex/adapter.d.ts +160 -0
  215. package/dist/exchanges/risex/adapter.js +842 -0
  216. package/dist/exchanges/risex/agent.d.ts +154 -0
  217. package/dist/exchanges/risex/agent.js +384 -0
  218. package/dist/exchanges/risex/client.d.ts +47 -0
  219. package/dist/exchanges/risex/client.js +174 -0
  220. package/dist/exchanges/risex/nonce.d.ts +43 -0
  221. package/dist/exchanges/risex/nonce.js +212 -0
  222. package/dist/exchanges/risex/public.d.ts +64 -0
  223. package/dist/exchanges/risex/public.js +150 -0
  224. package/dist/exchanges/risex/session.d.ts +71 -0
  225. package/dist/exchanges/risex/session.js +171 -0
  226. package/dist/exchanges/risex/typed-data.d.ts +173 -0
  227. package/dist/exchanges/risex/typed-data.js +240 -0
  228. package/dist/exchanges/risex/units.d.ts +29 -0
  229. package/dist/exchanges/risex/units.js +104 -0
  230. package/dist/exchanges/slippage.d.ts +1 -1
  231. package/dist/exchanges/slippage.js +1 -1
  232. package/dist/exchanges/spot-factory.d.ts +3 -3
  233. package/dist/exchanges/spot-factory.js +8 -8
  234. package/dist/exchanges/spot-interface.d.ts +5 -5
  235. package/dist/exchanges/spot-interface.js +2 -2
  236. package/dist/exchanges/spot-result.d.ts +3 -3
  237. package/dist/exchanges/spot-result.js +3 -3
  238. package/dist/exchanges/trading-v2.d.ts +3 -3
  239. package/dist/exchanges/trading-v2.js +9 -6
  240. package/dist/exchanges/txflow/adapter.d.ts +61 -0
  241. package/dist/exchanges/txflow/adapter.js +150 -0
  242. package/dist/exchanges/txflow/client.d.ts +47 -0
  243. package/dist/exchanges/txflow/client.js +155 -0
  244. package/dist/exchanges/txflow/public.d.ts +87 -0
  245. package/dist/exchanges/txflow/public.js +355 -0
  246. package/dist/exchanges/unknown-symbol.d.ts +34 -0
  247. package/dist/exchanges/unknown-symbol.js +56 -0
  248. package/dist/exchanges/variational/adapter.d.ts +67 -0
  249. package/dist/exchanges/variational/adapter.js +137 -0
  250. package/dist/exchanges/variational/client.d.ts +21 -0
  251. package/dist/exchanges/variational/client.js +66 -0
  252. package/dist/exchanges/variational/public.d.ts +126 -0
  253. package/dist/exchanges/variational/public.js +430 -0
  254. package/dist/exchanges/venue-types.d.ts +52 -10
  255. package/dist/exchanges/venue-types.js +82 -11
  256. package/dist/exchanges/venue.d.ts +150 -11
  257. package/dist/exchanges/venue.js +126 -4
  258. package/dist/exchanges/venues/arcus.d.ts +1 -2
  259. package/dist/exchanges/venues/arcus.js +5 -4
  260. package/dist/exchanges/venues/aster.d.ts +2 -2
  261. package/dist/exchanges/venues/aster.js +6 -4
  262. package/dist/exchanges/venues/create-helpers.d.ts +1 -1
  263. package/dist/exchanges/venues/create-helpers.js +3 -3
  264. package/dist/exchanges/venues/extended.d.ts +21 -0
  265. package/dist/exchanges/venues/extended.js +96 -0
  266. package/dist/exchanges/venues/grvt.d.ts +30 -0
  267. package/dist/exchanges/venues/grvt.js +98 -0
  268. package/dist/exchanges/venues/hyperliquid.d.ts +2 -2
  269. package/dist/exchanges/venues/hyperliquid.js +19 -8
  270. package/dist/exchanges/venues/index.d.ts +7 -2
  271. package/dist/exchanges/venues/index.js +8 -2
  272. package/dist/exchanges/venues/lighter-family.d.ts +7 -9
  273. package/dist/exchanges/venues/lighter-family.js +9 -11
  274. package/dist/exchanges/venues/lighter-rh.d.ts +2 -2
  275. package/dist/exchanges/venues/lighter-rh.js +20 -8
  276. package/dist/exchanges/venues/lighter.d.ts +1 -1
  277. package/dist/exchanges/venues/lighter.js +18 -6
  278. package/dist/exchanges/venues/ondo.d.ts +1 -1
  279. package/dist/exchanges/venues/ondo.js +5 -3
  280. package/dist/exchanges/venues/pacifica.d.ts +2 -2
  281. package/dist/exchanges/venues/pacifica.js +15 -4
  282. package/dist/exchanges/venues/qfex.d.ts +1 -1
  283. package/dist/exchanges/venues/qfex.js +4 -2
  284. package/dist/exchanges/venues/risex-release.d.ts +14 -0
  285. package/dist/exchanges/venues/risex-release.js +14 -0
  286. package/dist/exchanges/venues/risex.d.ts +31 -0
  287. package/dist/exchanges/venues/risex.js +131 -0
  288. package/dist/exchanges/venues/txflow.d.ts +18 -0
  289. package/dist/exchanges/venues/txflow.js +77 -0
  290. package/dist/exchanges/venues/variational.d.ts +21 -0
  291. package/dist/exchanges/venues/variational.js +85 -0
  292. package/dist/execution-log.d.ts +1 -1
  293. package/dist/funding/legacy-public.d.ts +6 -4
  294. package/dist/funding/legacy-public.js +42 -41
  295. package/dist/funding/normalize.d.ts +1 -1
  296. package/dist/funding/normalize.js +1 -1
  297. package/dist/funding/rates.d.ts +95 -6
  298. package/dist/funding/rates.js +99 -19
  299. package/dist/index.js +7 -6
  300. package/dist/jobs.d.ts +1 -0
  301. package/dist/jobs.js +25 -1
  302. package/dist/landing.d.ts +2 -0
  303. package/dist/landing.js +1 -1
  304. package/dist/liquidity.d.ts +3 -1
  305. package/dist/liquidity.js +8 -4
  306. package/dist/mcp-pacifica-earn.d.ts +9 -0
  307. package/dist/mcp-pacifica-earn.js +64 -0
  308. package/dist/mcp-server.js +211 -68
  309. package/dist/pacifica/client.d.ts +69 -5
  310. package/dist/pacifica/client.js +181 -8
  311. package/dist/pacifica/rate-limit.d.ts +144 -0
  312. package/dist/pacifica/rate-limit.js +267 -0
  313. package/dist/pacifica/types/order.d.ts +2 -1
  314. package/dist/plan-executor.js +7 -2
  315. package/dist/positions-by-address.d.ts +34 -0
  316. package/dist/positions-by-address.js +46 -0
  317. package/dist/rebalance.js +1 -1
  318. package/dist/risk.d.ts +2 -1
  319. package/dist/risk.js +2 -4
  320. package/dist/settings.d.ts +32 -3
  321. package/dist/signer/ows-evm.d.ts +1 -1
  322. package/dist/signer/ows-evm.js +1 -1
  323. package/dist/smart-order.d.ts +1 -1
  324. package/dist/smart-order.js +1 -1
  325. package/dist/strategies/funding-arb.d.ts +1 -1
  326. package/dist/strategies/funding-arb.js +36 -63
  327. package/dist/trade-validator.js +2 -2
  328. package/dist/utils.d.ts +22 -3
  329. package/dist/utils.js +11 -3
  330. package/dist/venue-health.d.ts +40 -0
  331. package/dist/venue-health.js +75 -0
  332. package/dist/withdraw-gate.d.ts +1 -1
  333. package/dist/withdraw-gate.js +1 -1
  334. package/dist/ws/arcus-market.d.ts +9 -0
  335. package/dist/ws/arcus-market.js +9 -0
  336. package/dist/ws/aster-market.d.ts +33 -0
  337. package/dist/ws/aster-market.js +30 -0
  338. package/dist/ws/index.d.ts +980 -0
  339. package/dist/ws/index.js +4460 -0
  340. package/dist/ws/lighter-market.d.ts +14 -0
  341. package/dist/ws/lighter-market.js +13 -0
  342. package/dist/ws/node.d.ts +996 -0
  343. package/dist/ws/node.js +4554 -0
  344. package/dist/ws/pacifica-instrument.d.ts +8 -0
  345. package/dist/ws/pacifica-instrument.js +8 -0
  346. package/dist/ws/unclassified.d.ts +16 -0
  347. package/dist/ws/unclassified.js +43 -0
  348. package/dist/ws-cli/credentials.d.ts +62 -0
  349. package/dist/ws-cli/credentials.js +126 -0
  350. package/package.json +71 -10
  351. package/skills/perp-cli/SKILL.md +153 -36
  352. package/skills/perp-cli/package.json +15 -2
  353. package/skills/perp-cli/references/agent-operations.md +22 -12
  354. package/skills/perp-cli/references/commands.md +143 -17
  355. package/skills/perp-cli/references/strategies.md +38 -3
  356. package/skills/perp-cli/references/ws-library.md +523 -0
  357. package/skills/perp-cli/scripts/arb-monitor.sh +13 -10
  358. package/skills/perp-cli/scripts/funding-analysis.sh +57 -29
  359. package/skills/perp-cli/scripts/preflight.sh +27 -19
  360. package/skills/perp-cli/scripts/spot-perp-scan.sh +58 -38
  361. package/skills/perp-cli/scripts/validate-arb.sh +56 -39
  362. package/dist/cli-spec.d.ts +0 -46
  363. package/dist/cli-spec.js +0 -81
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Options market data — venue-agnostic model (READ-ONLY).
3
+ *
4
+ * An options venue implements `OptionsVenue`; the CLI (`perp options`) and the MCP tools
5
+ * (`get_option_*`) only see these types. The first implementation is Derive
6
+ * (`src/exchanges/derive/options.ts`).
7
+ *
8
+ * Contract (same rules as the perp JSON):
9
+ * - decimals are strings, passed through as the venue printed them (never re-rounded);
10
+ * - unknown is `null`, never `0` — an empty book side is `bid: null` / `ask: null`, an IV the venue
11
+ * could not compute is `null`, greeks are `null` when the venue publishes none;
12
+ * - every top-level object carries `schema: 1` (bumped on any breaking change of these types).
13
+ *
14
+ * Nothing here places orders or needs a key.
15
+ */
16
+ /** Version of the options JSON shapes below. */
17
+ export declare const OPTIONS_SCHEMA: 1;
18
+ export type OptionKind = "call" | "put";
19
+ /** One side of the top of book. */
20
+ export interface OptionBookSide {
21
+ /** Premium per contract, in `quoteCurrency`. */
22
+ price: string;
23
+ /** Contracts available at `price`. */
24
+ size: string;
25
+ }
26
+ export interface OptionGreeks {
27
+ delta: string;
28
+ gamma: string;
29
+ /** Units as published by the venue (Derive documents none; magnitudes match theta per day, vega per 1 vol point). */
30
+ theta: string;
31
+ vega: string;
32
+ rho: string;
33
+ }
34
+ export interface OptionIv {
35
+ /** Implied volatility of the mark price (fraction: "0.55" = 55%). */
36
+ mark: string | null;
37
+ /** IV of the best bid; null when there is no bid or the venue could not compute it. */
38
+ bid: string | null;
39
+ /** IV of the best ask; null when there is no ask or the venue could not compute it. */
40
+ ask: string | null;
41
+ }
42
+ export interface OptionStats24h {
43
+ /** Contracts traded in the last 24 h. */
44
+ contracts: string;
45
+ /** Notional (underlying) volume in `quoteCurrency`. */
46
+ notional: string;
47
+ /** Premium volume in `quoteCurrency`. */
48
+ premium: string;
49
+ trades: number;
50
+ /** null when there were no trades (the venue sends a "0" placeholder). */
51
+ high: string | null;
52
+ low: string | null;
53
+ }
54
+ /** A single option's quote: instrument facts + live market data. */
55
+ export interface OptionQuote {
56
+ schema: typeof OPTIONS_SCHEMA;
57
+ venue: string;
58
+ /** Venue instrument name, e.g. "ETH-20261225-3500-P". */
59
+ instrument: string;
60
+ underlying: string;
61
+ quoteCurrency: string;
62
+ kind: OptionKind;
63
+ strike: string;
64
+ /** Expiry date (UTC, YYYY-MM-DD). */
65
+ expiry: string;
66
+ expiryMs: number;
67
+ bid: OptionBookSide | null;
68
+ ask: OptionBookSide | null;
69
+ mark: string;
70
+ /** Underlying index price. */
71
+ index: string;
72
+ /** Forward price used by the venue's pricer; null when the venue publishes no pricing. */
73
+ forward: string | null;
74
+ discountFactor: string | null;
75
+ iv: OptionIv;
76
+ greeks: OptionGreeks | null;
77
+ /** Open interest in contracts. */
78
+ openInterest: string;
79
+ stats24h: OptionStats24h;
80
+ /** Venue snapshot time (ms epoch). */
81
+ timestampMs: number;
82
+ }
83
+ export interface OptionExpiry {
84
+ /** UTC date, YYYY-MM-DD (the key for `chain --expiry`). */
85
+ expiry: string;
86
+ expiryMs: number;
87
+ /** Distinct strikes listed for this expiry. */
88
+ strikes: number;
89
+ /** Listed instruments (calls + puts). */
90
+ instruments: number;
91
+ }
92
+ export interface OptionExpiries {
93
+ schema: typeof OPTIONS_SCHEMA;
94
+ venue: string;
95
+ underlying: string;
96
+ /** Active (tradable) expiries, soonest first. */
97
+ expiries: OptionExpiry[];
98
+ }
99
+ export interface OptionChainRow {
100
+ strike: string;
101
+ call: OptionQuote | null;
102
+ put: OptionQuote | null;
103
+ }
104
+ export interface OptionChain {
105
+ schema: typeof OPTIONS_SCHEMA;
106
+ venue: string;
107
+ underlying: string;
108
+ expiry: string;
109
+ expiryMs: number;
110
+ /** "requested" = --expiry; "nearest" = the soonest active expiry (no --expiry given). */
111
+ expirySelection: "requested" | "nearest";
112
+ /** Underlying index of the newest ticker of the expiry (largest timestampMs); null when no ticker was returned. */
113
+ index: string | null;
114
+ /** Forward of the newest ticker of the expiry (one ticker's value, not an average); null when it carried no pricing. */
115
+ forward: string | null;
116
+ /**
117
+ * At-the-money strike: the listed strike closest to `price` — the expiry's forward when the venue
118
+ * publishes one (`reference: "forward"`), the index otherwise. null when neither is known.
119
+ * `--strikes N` keeps the N strikes closest to `price`.
120
+ */
121
+ atm: {
122
+ strike: string;
123
+ reference: "forward" | "index";
124
+ price: string;
125
+ } | null;
126
+ /** Total strikes listed for the expiry (before --strikes). */
127
+ strikesListed: number;
128
+ /** Rows sorted by strike ascending. */
129
+ rows: OptionChainRow[];
130
+ /** Listed instruments for which the venue returned no ticker (their side is null). */
131
+ missingTickers: string[];
132
+ }
133
+ export interface OptionUnderlying {
134
+ underlying: string;
135
+ /** Venue spot price of the underlying; null when the venue publishes none. */
136
+ spotPrice: string | null;
137
+ }
138
+ export interface OptionUnderlyings {
139
+ schema: typeof OPTIONS_SCHEMA;
140
+ venue: string;
141
+ underlyings: OptionUnderlying[];
142
+ }
143
+ export interface OptionChainQuery {
144
+ underlying: string;
145
+ /** YYYY-MM-DD; null = the nearest active expiry. */
146
+ expiry: string | null;
147
+ /** Keep only the N strikes closest to the ATM reference; null = every strike. */
148
+ strikesAroundAtm: number | null;
149
+ }
150
+ /** A read-only options venue. Every method throws a PerpError on failure. */
151
+ export interface OptionsVenue {
152
+ readonly id: string;
153
+ readonly displayName: string;
154
+ listUnderlyings(): Promise<OptionUnderlyings>;
155
+ listExpiries(underlying: string): Promise<OptionExpiries>;
156
+ getChain(q: OptionChainQuery): Promise<OptionChain>;
157
+ getQuote(instrument: string): Promise<OptionQuote>;
158
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Options market data — venue-agnostic model (READ-ONLY).
3
+ *
4
+ * An options venue implements `OptionsVenue`; the CLI (`perp options`) and the MCP tools
5
+ * (`get_option_*`) only see these types. The first implementation is Derive
6
+ * (`src/exchanges/derive/options.ts`).
7
+ *
8
+ * Contract (same rules as the perp JSON):
9
+ * - decimals are strings, passed through as the venue printed them (never re-rounded);
10
+ * - unknown is `null`, never `0` — an empty book side is `bid: null` / `ask: null`, an IV the venue
11
+ * could not compute is `null`, greeks are `null` when the venue publishes none;
12
+ * - every top-level object carries `schema: 1` (bumped on any breaking change of these types).
13
+ *
14
+ * Nothing here places orders or needs a key.
15
+ */
16
+ /** Version of the options JSON shapes below. */
17
+ export const OPTIONS_SCHEMA = 1;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Options venues (read-only market data). Separate from the perp venue registry (`venue.ts`):
3
+ * an options venue is not a perp venue, so it never appears in `perp health`, arb scans or the
4
+ * perp market commands. `perp options` and the MCP `get_option_*` tools resolve venues here only.
5
+ */
6
+ import type { OptionsVenue } from "./options-interface.js";
7
+ import type { Network } from "./venue-types.js";
8
+ /** Option venue ids and aliases (for argv classification). */
9
+ export declare function optionsVenueWords(): string[];
10
+ export declare function listOptionsVenueIds(): string[];
11
+ /** The options venue `input` names (id or alias, case-insensitive) — CAPABILITY_UNSUPPORTED otherwise. */
12
+ export declare function getOptionsVenue(input: string, network: Network): Promise<OptionsVenue>;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Options venues (read-only market data). Separate from the perp venue registry (`venue.ts`):
3
+ * an options venue is not a perp venue, so it never appears in `perp health`, arb scans or the
4
+ * perp market commands. `perp options` and the MCP `get_option_*` tools resolve venues here only.
5
+ */
6
+ import { PerpError } from "../errors.js";
7
+ const OPTIONS_VENUES = [
8
+ {
9
+ id: "derive",
10
+ aliases: ["drv"],
11
+ displayName: "Derive",
12
+ async create(network) {
13
+ const { DeriveOptionsVenue } = await import("./derive/options.js");
14
+ return DeriveOptionsVenue.forNetwork(network);
15
+ },
16
+ },
17
+ ];
18
+ /** Option venue ids and aliases (for argv classification). */
19
+ export function optionsVenueWords() {
20
+ return OPTIONS_VENUES.flatMap(v => [v.id, ...v.aliases]);
21
+ }
22
+ export function listOptionsVenueIds() {
23
+ return OPTIONS_VENUES.map(v => v.id);
24
+ }
25
+ /** The options venue `input` names (id or alias, case-insensitive) — CAPABILITY_UNSUPPORTED otherwise. */
26
+ export async function getOptionsVenue(input, network) {
27
+ const want = input.trim().toLowerCase();
28
+ const entry = OPTIONS_VENUES.find(v => v.id === want || v.aliases.includes(want));
29
+ if (entry === undefined) {
30
+ throw new PerpError("CAPABILITY_UNSUPPORTED", `"${input}" has no options market data in perp-cli; options venues: ${listOptionsVenueIds().join(", ")}`, {
31
+ remediation: `Use -e ${OPTIONS_VENUES[0].id} (e.g. perp -e ${OPTIONS_VENUES[0].id} options expiries ETH)`,
32
+ });
33
+ }
34
+ return entry.create(network);
35
+ }
@@ -80,6 +80,10 @@ export interface OutcomeViewSide extends OutcomeSideInfo {
80
80
  bestAsk?: string;
81
81
  /** Implied probability of THIS side winning, derived from mid */
82
82
  impliedProb?: number;
83
+ /** Side name without a "template:" prefix ("template:Yes" → "Yes"). */
84
+ label?: string;
85
+ /** true = bid–ask wider than OUTCOME_WIDE_SPREAD: the mid is a weak probability estimate; null = one side empty. */
86
+ wideSpread?: boolean | null;
83
87
  }
84
88
  export interface OutcomeViewUnderlying {
85
89
  /** Underlying symbol from description (e.g. "BTC") */
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Pacifica Atomic order: a weighted basket of market orders across several markets, sent in ONE
3
+ * POST /api/v1/orders/batch request.
4
+ *
5
+ * Docs (read 2026-10-19):
6
+ * - trading-on-pacifica/order-types/strategies/atomic: "Each leg is signed as a market order with
7
+ * your Max Slippage, and all legs are sent to the exchange in a single batch request. Each leg
8
+ * can fill or fail independently." Up to 5 legs per side, a market appears once in the basket,
9
+ * weights are relative, the total size is USD converted to a token amount at each leg's mark
10
+ * price, Reduce Only applies to every leg. "Atomic does not guarantee an all-or-nothing fill."
11
+ * - api-documentation/api/rest-api/orders/batch-order: action `type` "CreateMarket"; `data` = the
12
+ * signed request payload of create-market-order (signing type "create_market_order"); max 10
13
+ * actions; "If one action fails, subsequent actions are still attempted"; response
14
+ * `{ success, data: { results: [{ success, order_id, error }] } }`; Status 400 = bad request.
15
+ * - There is no Atomic endpoint, signing type or order type code: legs are ordinary market
16
+ * orders (`/orders` and `account_order_updates` show them as `order_type` / `ot` "market").
17
+ *
18
+ * Money safety: every leg is validated (lot, venue minimum, slippage bound, unique market) before
19
+ * anything is signed; the whole basket is signed before the single POST; an unreadable or
20
+ * ambiguous answer is ORDER_PENDING (never resubmitted); a per-leg fill is read back from
21
+ * history_by_id and never assumed.
22
+ */
23
+ import { PerpError } from "../errors.js";
24
+ import type { MarketInfo, PriceInfo } from "../pacifica/types/market.js";
25
+ import type { BatchAction } from "../pacifica/types/order.js";
26
+ import { type RiskAssessment } from "../risk.js";
27
+ import type { PacificaAdapter, PacificaOrderOutcome } from "./pacifica.js";
28
+ /** "Up to 5 markets per side" (atomic docs). */
29
+ export declare const ATOMIC_MAX_LEGS_PER_SIDE = 5;
30
+ /** "Maximum 10 actions per batch request" (batch-order docs). */
31
+ export declare const PACIFICA_BATCH_MAX_ACTIONS = 10;
32
+ /** Signing operation type of each leg (create-market-order docs). */
33
+ export declare const ATOMIC_LEG_SIGNING_TYPE = "create_market_order";
34
+ /** Batch action type of each leg (batch-order docs, case sensitive). */
35
+ export declare const ATOMIC_LEG_ACTION_TYPE = "CreateMarket";
36
+ /** Placeholder for the signature in a dry-run plan (nothing is signed in a dry run). */
37
+ export declare const DRY_RUN_SIGNATURE = "<not signed: dry-run>";
38
+ export interface AtomicLegSpec {
39
+ /** As given by the user (resolved against /info, case-insensitively). */
40
+ symbol: string;
41
+ side: "buy" | "sell";
42
+ /** Relative weight (> 0). */
43
+ weight: number;
44
+ }
45
+ export interface AtomicMarket {
46
+ symbol: string;
47
+ lotSize: string;
48
+ /** /info `min_order_size` — "Minimum order size (denominated in USD)". */
49
+ minOrderUsd: string;
50
+ /** /info/prices `mark`. */
51
+ mark: string;
52
+ }
53
+ export interface AtomicLeg {
54
+ symbol: string;
55
+ side: "buy" | "sell";
56
+ weight: number;
57
+ /** weight / sum of weights. */
58
+ share: number;
59
+ /** total × share, before lot flooring. */
60
+ targetUsd: number;
61
+ mark: string;
62
+ lotSize: string;
63
+ /** Token amount sent: floor(targetUsd / mark) to the lot. */
64
+ size: string;
65
+ /** size × mark. */
66
+ notionalUsd: number;
67
+ }
68
+ /** --long / --short leg lists → leg specs (≤ 5 per side, ≥ 1 leg, each market once). */
69
+ export declare function parseAtomicLegs(longs: readonly string[], shorts: readonly string[]): AtomicLegSpec[];
70
+ /**
71
+ * The basket's markets from GET /info + GET /info/prices (public reads). Perp rows only; every
72
+ * requested symbol must be listed, with a positive lot_size / min_order_size and a positive mark
73
+ * (PRICE_STALE otherwise — nothing sent). Resolved to the venue's own spelling (e.g. kBONK).
74
+ */
75
+ export declare function atomicMarketsOf(specs: readonly AtomicLegSpec[], info: readonly MarketInfo[], prices: readonly PriceInfo[]): Map<string, AtomicMarket>;
76
+ /**
77
+ * Size every leg: total × weight / Σweights in USD → token amount at the mark, floored to the
78
+ * lot. A leg under one lot → SIZE_TOO_SMALL (nothing sent). Its notional at the mark must be at
79
+ * least the market's USD minimum × (1 + slippage bound), so a sell leg still meets the minimum when
80
+ * it fills at the worst price the bound allows. Reduce-only legs are held to it too (no exemption is
81
+ * documented).
82
+ */
83
+ export declare function sizeAtomicLegs(specs: readonly AtomicLegSpec[], totalUsd: string, markets: ReadonlyMap<string, AtomicMarket>, slippageBps: number): AtomicLeg[];
84
+ /**
85
+ * Reduce-only basket check (read only): every leg must reduce an existing position — a buy needs
86
+ * a short, a sell a long — by no more than its size. Otherwise INVALID_PARAMS, nothing sent.
87
+ */
88
+ export declare function requireAtomicReduceOnly(legs: readonly AtomicLeg[], positions: ReadonlyArray<{
89
+ symbol: string;
90
+ side: "long" | "short";
91
+ size: string;
92
+ }>): void;
93
+ /** A client_order_id for one leg: a UUID v4 outside the reserved TIF-encoding prefix (5ac1f). */
94
+ export declare function atomicLegClientOrderId(): string;
95
+ /**
96
+ * Basis points → Pacifica `slippage_percent` as an exact decimal string (1.1 bps → "0.011", not
97
+ * the float "0.011000000000000001"; 50 → "0.5").
98
+ */
99
+ export declare function bpsToPercent(bps: number): string;
100
+ /**
101
+ * Basket-level risk gate (on top of the per-leg enforceOrderRisk, which checks each leg against
102
+ * the max position size): the WHOLE basket's notional against the total-exposure limit and the
103
+ * number of legs that open a new market against max positions — preTradeCheck's rules applied
104
+ * to the basket as one order. Violations → RISK_VIOLATION (nothing sent). --force skips it.
105
+ */
106
+ export declare function atomicBasketRiskCheck(assessment: RiskAssessment, legs: readonly AtomicLeg[], positions: ReadonlyArray<{
107
+ symbol: string;
108
+ size: string;
109
+ }>): void;
110
+ /**
111
+ * The create_market_order payload of one leg (create-market-order docs: symbol, amount, side,
112
+ * slippage_percent, reduce_only, client_order_id, optional builder_code). Signed as-is.
113
+ */
114
+ export declare function atomicLegPayload(leg: AtomicLeg, o: {
115
+ reduceOnly: boolean;
116
+ slippageBps: number;
117
+ clientOrderId: string;
118
+ builderCode: string | null;
119
+ }): Record<string, unknown>;
120
+ /**
121
+ * Dry-run plan: the exact POST /orders/batch body the live run would send, with the signature
122
+ * replaced by a placeholder, plus each leg's canonical message (recursively key-sorted compact JSON,
123
+ * `{data, expiry_window, timestamp, type}`) that the live run signs. Nothing is signed.
124
+ */
125
+ export declare function atomicDryRunPlan(payloads: ReadonlyArray<Record<string, unknown>>, o: {
126
+ account: string | null;
127
+ agentWallet: string | null;
128
+ timestamp: number;
129
+ expiryWindow?: number;
130
+ }): {
131
+ endpoint: string;
132
+ body: {
133
+ actions: BatchAction[];
134
+ };
135
+ signedMessages: string[];
136
+ };
137
+ /**
138
+ * Error thrown by POST /orders/batch → typed. Already-typed errors (ORDER_PENDING after a send,
139
+ * ORDER_REJECTED when nothing could be sent) are kept. HTTP 400 is the documented whole-request
140
+ * refusal (batch-order: "Status 400: Bad request"; "All signatures must be valid for the batch to
141
+ * process") → ORDER_REJECTED. HTTP 429 → RATE_LIMITED, nothing processed. Any other answer →
142
+ * ORDER_PENDING (undocumented for this endpoint: legs may have executed).
143
+ */
144
+ export declare function atomicBatchError(e: unknown): PerpError;
145
+ export type AtomicAck = {
146
+ kind: "accepted";
147
+ orderId: string | null;
148
+ } | {
149
+ kind: "rejected";
150
+ error: string;
151
+ } | {
152
+ kind: "unknown";
153
+ reason: string;
154
+ };
155
+ /**
156
+ * Per-leg acks of a 200 batch response, in leg order. The body must carry `data.results` with one
157
+ * row per action; otherwise the batch's effect is unknown → ORDER_PENDING. A row with
158
+ * `success: true` was accepted (its `order_id` may be null — the docs' own example has one); a row
159
+ * with `success: false` and an error string was refused; anything else is unknown.
160
+ */
161
+ export declare function parseAtomicBatchResponse(raw: unknown, legCount: number): AtomicAck[];
162
+ export interface AtomicLegOutcome {
163
+ symbol: string;
164
+ side: "buy" | "sell";
165
+ size: string;
166
+ clientOrderId: string;
167
+ orderId: string | null;
168
+ /** filled / partiallyFilled = venue-final; notFilled = cancelled with nothing filled; unknown = not proven. */
169
+ status: "filled" | "partiallyFilled" | "notFilled" | "rejected" | "unknown";
170
+ filledSize: string | null;
171
+ detail: string | null;
172
+ }
173
+ /**
174
+ * Leg outcome from its ack, the order id it was traced to (the ack's, or one resolved from the
175
+ * leg's client_order_id; null = never traced) and that order's history_by_id outcome (null = not
176
+ * resolved).
177
+ */
178
+ export declare function atomicLegOutcome(leg: AtomicLeg, clientOrderId: string, ack: AtomicAck, orderId: string | null, history: PacificaOrderOutcome | null): AtomicLegOutcome;
179
+ /**
180
+ * The failure an Atomic basket reports unless every leg filled completely: any unknown leg →
181
+ * ORDER_PENDING (do not resubmit); nothing filled at all → ORDER_REJECTED; otherwise
182
+ * ORDER_PARTIAL. details carry every leg.
183
+ */
184
+ export declare function atomicIncompleteError(legs: readonly AtomicLegOutcome[]): PerpError | null;
185
+ /** Safety margin under the signature expiry: the batch is not sent when less than this is left. */
186
+ export declare const ATOMIC_EXPIRY_MARGIN_MS = 1500;
187
+ /** client_order_id → order_id lookups for a leg accepted without an order_id. */
188
+ export declare const ATOMIC_CLOID_POLLS = 6;
189
+ export declare const ATOMIC_CLOID_POLL_MS = 500;
190
+ export interface AtomicDeps {
191
+ now: () => number;
192
+ sleep: (ms: number) => Promise<void>;
193
+ }
194
+ /**
195
+ * order_id of a leg accepted without one (the batch docs' CreateMarket result carries
196
+ * `order_id: null`), found by its client_order_id in open orders / order history
197
+ * (PacificaAdapter.orderByClientId). Bounded: ATOMIC_CLOID_POLLS reads ATOMIC_CLOID_POLL_MS apart;
198
+ * read errors poll again. null = never found (the leg stays unknown).
199
+ */
200
+ export declare function resolveAtomicLegOrderId(adapter: Pick<PacificaAdapter, "orderByClientId">, clientOrderId: string, deps?: AtomicDeps): Promise<string | null>;
201
+ /**
202
+ * Wait for rate-limit capacity, sign every leg (create_market_order) with ONE shared timestamp,
203
+ * send them in ONE batch (the post-sign throttle wait bounded by the signature deadline), then
204
+ * read each accepted leg's fill back (in parallel — reads only). Signing failures and a signature
205
+ * that would expire within ATOMIC_EXPIRY_MARGIN_MS (a slow signer) stop before anything is sent
206
+ * (ORDER_REJECTED). Returns the per-leg outcomes; the caller decides with atomicIncompleteError.
207
+ */
208
+ export declare function executeAtomic(adapter: PacificaAdapter, legs: readonly AtomicLeg[], payloads: ReadonlyArray<Record<string, unknown>>, deps?: AtomicDeps): Promise<{
209
+ outcomes: AtomicLegOutcome[];
210
+ venueRaw: unknown;
211
+ }>;