perp-cli 0.15.0 → 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 (154) hide show
  1. package/README.ja.md +243 -0
  2. package/README.ko.md +243 -0
  3. package/README.md +129 -535
  4. package/README.zh.md +243 -0
  5. package/dist/api/public/lighter.d.ts +5 -0
  6. package/dist/api/public/lighter.js +5 -0
  7. package/dist/api/public/pacifica.js +2 -2
  8. package/dist/arb/sizing.js +4 -2
  9. package/dist/arb/state.d.ts +6 -0
  10. package/dist/balance-by-address.d.ts +39 -0
  11. package/dist/balance-by-address.js +44 -0
  12. package/dist/bot/quote-rules.js +1 -1
  13. package/dist/bot/strategies/funding-arb-strategy.js +10 -3
  14. package/dist/bot/strategies/funding-arb-utils.d.ts +14 -2
  15. package/dist/bot/strategies/funding-arb-utils.js +48 -15
  16. package/dist/bot/strategies/spot-perp-arb-strategy.d.ts +1 -1
  17. package/dist/bot/strategies/spot-perp-arb-strategy.js +4 -2
  18. package/dist/bot/strategies/spot-perp-executor.js +2 -2
  19. package/dist/cli-program.js +1 -1
  20. package/dist/commands/account.js +168 -24
  21. package/dist/commands/arb/index.js +19 -77
  22. package/dist/commands/arb-auto.d.ts +24 -0
  23. package/dist/commands/arb-auto.js +155 -81
  24. package/dist/commands/arb.d.ts +8 -0
  25. package/dist/commands/arb.js +49 -23
  26. package/dist/commands/backtest.js +23 -21
  27. package/dist/commands/market.d.ts +48 -0
  28. package/dist/commands/market.js +241 -78
  29. package/dist/commands/options.d.ts +5 -0
  30. package/dist/commands/options.js +20 -3
  31. package/dist/commands/pacifica-earn.js +8 -21
  32. package/dist/commands/portfolio.d.ts +16 -0
  33. package/dist/commands/portfolio.js +51 -8
  34. package/dist/commands/trade.js +4 -4
  35. package/dist/cross-chain-margin.d.ts +3 -1
  36. package/dist/cross-chain-margin.js +4 -2
  37. package/dist/dashboard/server.js +2 -2
  38. package/dist/dashboard/ui.js +9 -6
  39. package/dist/errors.d.ts +5 -0
  40. package/dist/errors.js +10 -0
  41. package/dist/exchanges/address.d.ts +8 -0
  42. package/dist/exchanges/address.js +47 -0
  43. package/dist/exchanges/arcus/adapter.d.ts +10 -6
  44. package/dist/exchanges/arcus/adapter.js +33 -6
  45. package/dist/exchanges/arcus/public.js +3 -2
  46. package/dist/exchanges/aster.d.ts +27 -7
  47. package/dist/exchanges/aster.js +124 -42
  48. package/dist/exchanges/canonical-symbols.d.ts +7 -0
  49. package/dist/exchanges/canonical-symbols.js +20 -0
  50. package/dist/exchanges/capabilities.d.ts +2 -0
  51. package/dist/exchanges/capabilities.js +2 -1
  52. package/dist/exchanges/derive/options.d.ts +5 -0
  53. package/dist/exchanges/derive/options.js +20 -1
  54. package/dist/exchanges/extended/adapter.d.ts +16 -2
  55. package/dist/exchanges/extended/adapter.js +96 -34
  56. package/dist/exchanges/extended/public.d.ts +3 -0
  57. package/dist/exchanges/extended/public.js +9 -2
  58. package/dist/exchanges/grvt/adapter.d.ts +16 -2
  59. package/dist/exchanges/grvt/adapter.js +98 -21
  60. package/dist/exchanges/hyperliquid-outcome.d.ts +2 -0
  61. package/dist/exchanges/hyperliquid-outcome.js +29 -1
  62. package/dist/exchanges/hyperliquid-spot.d.ts +8 -0
  63. package/dist/exchanges/hyperliquid-spot.js +20 -12
  64. package/dist/exchanges/hyperliquid.d.ts +180 -13
  65. package/dist/exchanges/hyperliquid.js +487 -185
  66. package/dist/exchanges/interface.d.ts +64 -8
  67. package/dist/exchanges/interface.js +31 -0
  68. package/dist/exchanges/lighter-public.d.ts +66 -11
  69. package/dist/exchanges/lighter-public.js +249 -81
  70. package/dist/exchanges/lighter-spot.d.ts +7 -1
  71. package/dist/exchanges/lighter-spot.js +99 -90
  72. package/dist/exchanges/lighter.d.ts +70 -11
  73. package/dist/exchanges/lighter.js +285 -92
  74. package/dist/exchanges/ondo/adapter.d.ts +34 -8
  75. package/dist/exchanges/ondo/adapter.js +73 -16
  76. package/dist/exchanges/ondo/public.d.ts +27 -2
  77. package/dist/exchanges/ondo/public.js +63 -31
  78. package/dist/exchanges/outcome-interface.d.ts +4 -0
  79. package/dist/exchanges/pacifica-spot.d.ts +6 -0
  80. package/dist/exchanges/pacifica-spot.js +23 -15
  81. package/dist/exchanges/pacifica-vaults.d.ts +9 -0
  82. package/dist/exchanges/pacifica-vaults.js +14 -1
  83. package/dist/exchanges/pacifica.d.ts +77 -6
  84. package/dist/exchanges/pacifica.js +321 -130
  85. package/dist/exchanges/public-balances.d.ts +25 -0
  86. package/dist/exchanges/public-balances.js +158 -0
  87. package/dist/exchanges/public-positions.d.ts +43 -0
  88. package/dist/exchanges/public-positions.js +154 -0
  89. package/dist/exchanges/qfex/adapter.d.ts +52 -9
  90. package/dist/exchanges/qfex/adapter.js +74 -9
  91. package/dist/exchanges/qfex/public.d.ts +62 -9
  92. package/dist/exchanges/qfex/public.js +128 -22
  93. package/dist/exchanges/qfex/ws-transport.d.ts +1 -1
  94. package/dist/exchanges/risex/adapter.d.ts +19 -7
  95. package/dist/exchanges/risex/adapter.js +58 -12
  96. package/dist/exchanges/spot-factory.js +1 -1
  97. package/dist/exchanges/txflow/adapter.d.ts +14 -7
  98. package/dist/exchanges/txflow/adapter.js +51 -19
  99. package/dist/exchanges/txflow/client.js +3 -1
  100. package/dist/exchanges/txflow/public.d.ts +12 -1
  101. package/dist/exchanges/txflow/public.js +82 -11
  102. package/dist/exchanges/unknown-symbol.d.ts +6 -1
  103. package/dist/exchanges/unknown-symbol.js +7 -2
  104. package/dist/exchanges/variational/adapter.d.ts +2 -6
  105. package/dist/exchanges/venue-types.d.ts +46 -3
  106. package/dist/exchanges/venue-types.js +80 -9
  107. package/dist/exchanges/venue.d.ts +99 -3
  108. package/dist/exchanges/venue.js +72 -0
  109. package/dist/exchanges/venues/hyperliquid.js +9 -0
  110. package/dist/exchanges/venues/lighter-rh.js +13 -3
  111. package/dist/exchanges/venues/lighter.js +13 -3
  112. package/dist/exchanges/venues/pacifica.js +9 -0
  113. package/dist/exchanges/venues/risex.js +15 -0
  114. package/dist/funding/legacy-public.d.ts +5 -3
  115. package/dist/funding/legacy-public.js +33 -37
  116. package/dist/funding/rates.d.ts +54 -5
  117. package/dist/funding/rates.js +49 -13
  118. package/dist/liquidity.d.ts +3 -1
  119. package/dist/liquidity.js +8 -4
  120. package/dist/mcp-pacifica-earn.js +11 -5
  121. package/dist/mcp-server.js +104 -15
  122. package/dist/pacifica/client.d.ts +2 -1
  123. package/dist/pacifica/client.js +11 -0
  124. package/dist/positions-by-address.d.ts +34 -0
  125. package/dist/positions-by-address.js +46 -0
  126. package/dist/strategies/funding-arb.js +35 -62
  127. package/dist/utils.d.ts +11 -1
  128. package/dist/venue-health.js +1 -1
  129. package/dist/ws/arcus-market.d.ts +9 -0
  130. package/dist/ws/arcus-market.js +9 -0
  131. package/dist/ws/aster-market.d.ts +33 -0
  132. package/dist/ws/aster-market.js +30 -0
  133. package/dist/ws/index.d.ts +30 -9
  134. package/dist/ws/index.js +180 -15
  135. package/dist/ws/lighter-market.d.ts +14 -0
  136. package/dist/ws/lighter-market.js +13 -0
  137. package/dist/ws/node.d.ts +30 -9
  138. package/dist/ws/node.js +204 -16
  139. package/dist/ws/unclassified.d.ts +16 -0
  140. package/dist/ws/unclassified.js +43 -0
  141. package/package.json +15 -2
  142. package/skills/perp-cli/SKILL.md +97 -33
  143. package/skills/perp-cli/package.json +15 -2
  144. package/skills/perp-cli/references/agent-operations.md +15 -12
  145. package/skills/perp-cli/references/commands.md +67 -12
  146. package/skills/perp-cli/references/strategies.md +38 -3
  147. package/skills/perp-cli/references/ws-library.md +55 -24
  148. package/skills/perp-cli/scripts/arb-monitor.sh +13 -10
  149. package/skills/perp-cli/scripts/funding-analysis.sh +57 -29
  150. package/skills/perp-cli/scripts/preflight.sh +27 -19
  151. package/skills/perp-cli/scripts/spot-perp-scan.sh +58 -38
  152. package/skills/perp-cli/scripts/validate-arb.sh +56 -39
  153. package/dist/cli-spec.d.ts +0 -46
  154. package/dist/cli-spec.js +0 -81
@@ -1,9 +1,13 @@
1
+ import { type FundingHistoryRow } from "./interface.js";
1
2
  import { Keypair } from "@solana/web3.js";
2
3
  import { PacificaClient, type Network } from "../pacifica/index.js";
3
4
  import type { ExchangeAdapter, ExchangeMarketInfo, ExchangePosition, ExchangeOrder, ExchangeBalance, ExchangeTrade, ExchangePublicTrade, ExchangeFundingPayment, ExchangeKline } from "./interface.js";
4
5
  import type { ResolvedSlippage } from "./slippage.js";
5
6
  import type { SolanaSigner } from "../signer/index.js";
6
7
  import type { AgentMeta } from "../settings.js";
8
+ import type { PriceInfo } from "../pacifica/types/market.js";
9
+ import type { Position } from "../pacifica/types/position.js";
10
+ import type { AccountInfo } from "../pacifica/types/account.js";
7
11
  import type { TimeInForce as PacificaTif } from "../pacifica/types/order.js";
8
12
  import type { IocOutcome } from "./ioc-outcome.js";
9
13
  import { type BuilderApproval, type BuilderDecision, type BuilderFeeGate, type BuilderTarget } from "./builder-fee.js";
@@ -155,6 +159,20 @@ export interface PacificaAmendResult {
155
159
  notes: string[];
156
160
  venueRaw: unknown;
157
161
  }
162
+ /** GET /trades answers the last 20 fills (40 taker + maker rows); no limit or cursor. */
163
+ export declare const PACIFICA_TRADES_CAP = 20;
164
+ /** GET /funding_rate/history `limit` maximum per request (docs; live 4001 → 4000). */
165
+ export declare const PACIFICA_FUNDING_PAGE = 4000;
166
+ /** GET /kline: "Max range: 4000 candles" per request (HTTP 400 beyond, live 2026-10-19). */
167
+ export declare const PACIFICA_KLINE_MAX_BARS = 4000;
168
+ /** Requests one funding / kline read may send (the venue meters reads by credits). */
169
+ export declare const PACIFICA_MAX_PAGES = 10;
170
+ /**
171
+ * GET /kline intervals (venue error text, live 2026-10-19: "Must be one of 1m, 3m, 5m, 15m, 30m,
172
+ * 1h, 2h, 4h, 8h, 12h, 1d, 1w, 1M"; each answered 200 with rows labelled `i` = the interval).
173
+ * The ms length sizes the 4000-bar request windows (1M: 31 days, the longest month).
174
+ */
175
+ export declare const PACIFICA_KLINE_INTERVALS: Readonly<Record<string, number>>;
158
176
  /** Pacifica order_type of a stop / TP / SL order (stop_market, stop_limit, take_profit_*, stop_loss_*). */
159
177
  export declare function isPacificaStopType(type: string): boolean;
160
178
  /**
@@ -163,6 +181,27 @@ export declare function isPacificaStopType(type: string): boolean;
163
181
  * EXCHANGE_ERROR (never a guessed direction). Used by the public tape and the account fills.
164
182
  */
165
183
  export declare function pacificaFillSide(side: string, endpoint: string): "buy" | "sell";
184
+ /** Pacifica balance with its extras (USDC balance / loan, pending interest, withdrawable). */
185
+ export type PacificaBalance = ExchangeBalance & {
186
+ usdcBalance: string;
187
+ borrowedUsdc: string;
188
+ pendingInterest: string | null;
189
+ availableToWithdraw: string;
190
+ };
191
+ /**
192
+ * Balance of a Pacifica account from GET /account, its positions and /info/prices — the one
193
+ * implementation behind PacificaAdapter.getBalance() and the keyless `account balance --address`.
194
+ */
195
+ export declare function pacificaBalanceOf(info: AccountInfo, positions: Position[], prices: PriceInfo[]): PacificaBalance;
196
+ /**
197
+ * Open positions of one Pacifica account (`GET /positions?account=`), marked with `/info/prices`.
198
+ * The ONE mapper of the keyed `getPositions` and the public-address read: unresolved leverage is
199
+ * read from the account's `/account/settings` (public, by address), then the market max.
200
+ */
201
+ export declare function pacificaPositionRows(positions: Position[], prices: PriceInfo[], deps: {
202
+ accountSettings: () => Promise<unknown>;
203
+ maxLeverage: () => Promise<Map<string, number | null>>;
204
+ }): Promise<ExchangePosition[]>;
166
205
  export declare class PacificaAdapter implements ExchangeAdapter {
167
206
  readonly name = "pacifica";
168
207
  readonly chain = "solana";
@@ -186,6 +225,7 @@ export declare class PacificaAdapter implements ExchangeAdapter {
186
225
  private signMessage;
187
226
  private _marketsCache;
188
227
  private _marketsCacheTime;
228
+ private _infoCache;
189
229
  private static readonly CACHE_TTL;
190
230
  /** Venue network — part of every account cache key (the same key exists on mainnet and testnet). */
191
231
  private _network;
@@ -248,8 +288,37 @@ export declare class PacificaAdapter implements ExchangeAdapter {
248
288
  */
249
289
  builderApprovalOf(target: BuilderTarget): Promise<BuilderApproval>;
250
290
  get sdk(): PacificaClient;
291
+ /**
292
+ * The configured account for an account read (settings, TWAP orders, …): no Pacifica key
293
+ * configured → NO_SIGNER_AVAILABLE. A keyless adapter holds a generated throwaway keypair, whose
294
+ * empty account would otherwise read as "no settings / no orders".
295
+ */
296
+ accountForReads(): string;
251
297
  get signer(): (msg: Uint8Array) => Promise<Uint8Array>;
298
+ /** GET /info rows (every instrument type), one CACHE_TTL cache for symbol resolution and getMarkets. */
299
+ private infoRows;
252
300
  getMarkets(): Promise<ExchangeMarketInfo[]>;
301
+ /**
302
+ * The venue's own spelling of a perp market typed by the user. Pacifica's API is
303
+ * case-sensitive (kBONK / kPEPE / kSHIB: `KPEPE` answers `200 []` on /trades, /kline and
304
+ * /funding_rate/history and 400 "Book not found" on /book — live 2026-10-19), and the CLI
305
+ * upper-cases the argument. Matched against /info exactly first, then case-insensitively
306
+ * (a "-PERP" display suffix ignored), as `market info` does. A listed non-perp (spot SOL-USDC)
307
+ * is refused before any request: this adapter serves perps only (isPacificaPerpetual).
308
+ */
309
+ wireSymbol(symbol: string): Promise<string>;
310
+ /**
311
+ * wireSymbol for an order entry point (market / limit / stop / edit): a resolution failure is
312
+ * a definite "not sent" (orderNotSent re-types a read error), never a retryable code.
313
+ */
314
+ private orderSymbol;
315
+ /**
316
+ * The venue's spelling for a cancel / TP-SL on an existing order or position: resolved as in
317
+ * wireSymbol when /info lists it (any instrument type, case-insensitive); otherwise — not listed
318
+ * (a delisted market) or /info unreadable — sent as typed: a cancel must still reach the venue,
319
+ * whose own answer is final.
320
+ */
321
+ private listedSymbol;
253
322
  getOrderbook(symbol: string): Promise<{
254
323
  bids: [string, string][];
255
324
  asks: [string, string][];
@@ -395,12 +464,14 @@ export declare class PacificaAdapter implements ExchangeAdapter {
395
464
  * of both parties mapped through `side === "bid"` → all "sell". No de-duplication: two taker
396
465
  * rows with equal time / price / amount are two fills (one order filling two makers).
397
466
  */
398
- getRecentTrades(symbol: string, _limit?: number): Promise<ExchangePublicTrade[]>;
399
- getFundingHistory(symbol: string, limit?: number): Promise<{
400
- time: number;
401
- rate: string;
402
- price: string | null;
403
- }[]>;
467
+ getRecentTrades(symbol: string, limit?: number): Promise<ExchangePublicTrade[]>;
468
+ getFundingHistory(symbol: string, limit?: number): Promise<FundingHistoryRow[]>;
469
+ /**
470
+ * GET /kline over [startTime, endTime]. The venue refuses a range over 4000 candles (HTTP 400
471
+ * "Time range too large … Max range: 4000 candles"), so a longer window is read in consecutive
472
+ * 4000-bar windows (at most PACIFICA_MAX_PAGES), merged by open time. Intervals outside
473
+ * PACIFICA_KLINE_INTERVALS are refused locally with INVALID_PARAMS (the venue: HTTP 400).
474
+ */
404
475
  getKlines(symbol: string, interval: string, startTime: number, endTime: number): Promise<ExchangeKline[]>;
405
476
  /**
406
477
  * Recent orders, newest first (GET /orders/history; PacificaClient.get already unwraps the