perp-cli 0.6.4 → 0.7.2

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 (181) hide show
  1. package/README.md +7 -2
  2. package/dist/api/public/hyperliquid.d.ts +2 -2
  3. package/dist/api/public/hyperliquid.js +0 -10
  4. package/dist/api/public/lighter.d.ts +2 -1
  5. package/dist/api/public/pacifica.d.ts +2 -1
  6. package/dist/arb/index.d.ts +7 -4
  7. package/dist/arb/index.js +5 -4
  8. package/dist/arb/sizing.d.ts +1 -1
  9. package/dist/arb/state.d.ts +1 -1
  10. package/dist/arb/state.js +4 -3
  11. package/dist/arb/utils.d.ts +0 -10
  12. package/dist/arb/utils.js +0 -42
  13. package/dist/bot/apex/guard.d.ts +26 -0
  14. package/dist/bot/apex/guard.js +86 -0
  15. package/dist/bot/apex/index.d.ts +6 -0
  16. package/dist/bot/apex/index.js +4 -0
  17. package/dist/bot/apex/pulse.d.ts +22 -0
  18. package/dist/bot/apex/pulse.js +107 -0
  19. package/dist/bot/apex/radar.d.ts +17 -0
  20. package/dist/bot/apex/radar.js +150 -0
  21. package/dist/bot/conditions.d.ts +1 -1
  22. package/dist/bot/config.d.ts +6 -1
  23. package/dist/bot/config.js +2 -2
  24. package/dist/bot/engine.d.ts +23 -2
  25. package/dist/bot/engine.js +331 -351
  26. package/dist/bot/index.d.ts +16 -0
  27. package/dist/bot/index.js +10 -0
  28. package/dist/bot/indicators.d.ts +29 -0
  29. package/dist/bot/indicators.js +144 -0
  30. package/dist/bot/reflect.d.ts +34 -0
  31. package/dist/bot/reflect.js +155 -0
  32. package/dist/bot/strategies/aggressive-taker.d.ts +36 -0
  33. package/dist/bot/strategies/aggressive-taker.js +125 -0
  34. package/dist/bot/strategies/apex-strategy.d.ts +36 -0
  35. package/dist/bot/strategies/apex-strategy.js +185 -0
  36. package/dist/bot/strategies/avellaneda-mm.d.ts +27 -0
  37. package/dist/bot/strategies/avellaneda-mm.js +111 -0
  38. package/dist/bot/strategies/basis-arb.d.ts +27 -0
  39. package/dist/bot/strategies/basis-arb.js +97 -0
  40. package/dist/bot/strategies/claude-agent.d.ts +31 -0
  41. package/dist/bot/strategies/claude-agent.js +155 -0
  42. package/dist/bot/strategies/dca-strategy.d.ts +25 -0
  43. package/dist/bot/strategies/dca-strategy.js +59 -0
  44. package/dist/bot/strategies/engine-mm.d.ts +29 -0
  45. package/dist/bot/strategies/engine-mm.js +141 -0
  46. package/dist/bot/strategies/funding-arb-strategy.d.ts +32 -0
  47. package/dist/bot/strategies/funding-arb-strategy.js +168 -0
  48. package/dist/bot/strategies/funding-arb-v2.d.ts +32 -0
  49. package/dist/bot/strategies/funding-arb-v2.js +222 -0
  50. package/dist/bot/strategies/funding-auto.d.ts +1 -0
  51. package/dist/bot/strategies/funding-auto.js +572 -0
  52. package/dist/bot/strategies/grid-mm.d.ts +25 -0
  53. package/dist/bot/strategies/grid-mm.js +99 -0
  54. package/dist/bot/strategies/grid-strategy.d.ts +39 -0
  55. package/dist/bot/strategies/grid-strategy.js +176 -0
  56. package/dist/bot/strategies/hedge-agent.d.ts +25 -0
  57. package/dist/bot/strategies/hedge-agent.js +79 -0
  58. package/dist/bot/strategies/liquidation-mm.d.ts +25 -0
  59. package/dist/bot/strategies/liquidation-mm.js +108 -0
  60. package/dist/bot/strategies/mean-reversion.d.ts +35 -0
  61. package/dist/bot/strategies/mean-reversion.js +118 -0
  62. package/dist/bot/strategies/momentum-breakout.d.ts +36 -0
  63. package/dist/bot/strategies/momentum-breakout.js +159 -0
  64. package/dist/bot/strategies/regime-mm.d.ts +25 -0
  65. package/dist/bot/strategies/regime-mm.js +111 -0
  66. package/dist/bot/strategies/rfq-agent.d.ts +25 -0
  67. package/dist/bot/strategies/rfq-agent.js +71 -0
  68. package/dist/bot/strategies/simple-mm.d.ts +25 -0
  69. package/dist/bot/strategies/simple-mm.js +76 -0
  70. package/dist/bot/strategy-registry.d.ts +9 -0
  71. package/dist/bot/strategy-registry.js +14 -0
  72. package/dist/bot/strategy-types.d.ts +64 -0
  73. package/dist/bot/strategy-types.js +5 -0
  74. package/dist/bot/trade-journal.d.ts +27 -0
  75. package/dist/bot/trade-journal.js +53 -0
  76. package/dist/bot/tui/BotDashboard.d.ts +56 -0
  77. package/dist/bot/tui/BotDashboard.js +94 -0
  78. package/dist/bot/tui/index.d.ts +6 -0
  79. package/dist/bot/tui/index.js +8 -0
  80. package/dist/bridge-engine.d.ts +0 -1
  81. package/dist/bridge-engine.js +0 -1
  82. package/dist/cache.d.ts +0 -1
  83. package/dist/cache.js +0 -1
  84. package/dist/commands/account.d.ts +1 -1
  85. package/dist/commands/account.js +94 -91
  86. package/dist/commands/agent.d.ts +1 -1
  87. package/dist/commands/arb/index.d.ts +1 -1
  88. package/dist/commands/arb/index.js +1 -1
  89. package/dist/commands/arb-auto.d.ts +1 -1
  90. package/dist/commands/arb-auto.js +5 -3
  91. package/dist/commands/arb.d.ts +2 -1
  92. package/dist/commands/arb.js +2 -0
  93. package/dist/commands/bot.d.ts +1 -1
  94. package/dist/commands/bot.js +236 -15
  95. package/dist/commands/bridge.js +1 -1
  96. package/dist/commands/dashboard.d.ts +1 -1
  97. package/dist/commands/dashboard.js +1 -1
  98. package/dist/commands/funds.d.ts +1 -1
  99. package/dist/commands/funds.js +34 -21
  100. package/dist/commands/history.d.ts +1 -1
  101. package/dist/commands/history.js +10 -5
  102. package/dist/commands/manage.d.ts +2 -3
  103. package/dist/commands/manage.js +11 -18
  104. package/dist/commands/market.d.ts +1 -1
  105. package/dist/commands/market.js +26 -17
  106. package/dist/commands/plan.d.ts +1 -1
  107. package/dist/commands/rebalance.d.ts +1 -1
  108. package/dist/commands/rebalance.js +8 -9
  109. package/dist/commands/risk.d.ts +1 -1
  110. package/dist/commands/settings.d.ts +1 -1
  111. package/dist/commands/settings.js +3 -1
  112. package/dist/commands/trade.d.ts +1 -1
  113. package/dist/commands/trade.js +42 -55
  114. package/dist/commands/wallet.d.ts +0 -2
  115. package/dist/commands/wallet.js +0 -5
  116. package/dist/constants.d.ts +0 -3
  117. package/dist/constants.js +0 -4
  118. package/dist/cross-chain-margin.d.ts +1 -1
  119. package/dist/dashboard/index.d.ts +4 -0
  120. package/dist/dashboard/index.js +3 -0
  121. package/dist/dashboard/server.d.ts +1 -1
  122. package/dist/dashboard/server.js +1 -1
  123. package/dist/dashboard/ws-feeds.d.ts +1 -1
  124. package/dist/event-stream.d.ts +1 -1
  125. package/dist/exchanges/aster.d.ts +62 -0
  126. package/dist/exchanges/aster.js +420 -0
  127. package/dist/exchanges/capabilities.d.ts +74 -0
  128. package/dist/exchanges/capabilities.js +44 -0
  129. package/dist/exchanges/edgex.d.ts +62 -0
  130. package/dist/exchanges/edgex.js +552 -0
  131. package/dist/exchanges/hyperliquid-spot.d.ts +1 -1
  132. package/dist/exchanges/hyperliquid-spot.js +20 -12
  133. package/dist/exchanges/hyperliquid.d.ts +8 -2
  134. package/dist/exchanges/hyperliquid.js +21 -6
  135. package/dist/exchanges/index.d.ts +11 -0
  136. package/dist/exchanges/index.js +10 -0
  137. package/dist/exchanges/interface.d.ts +3 -0
  138. package/dist/exchanges/lighter-spot.d.ts +13 -0
  139. package/dist/exchanges/lighter-spot.js +98 -26
  140. package/dist/exchanges/lighter.d.ts +9 -3
  141. package/dist/exchanges/lighter.js +18 -8
  142. package/dist/exchanges/nado.d.ts +52 -0
  143. package/dist/exchanges/nado.js +223 -0
  144. package/dist/exchanges/pacifica.d.ts +7 -1
  145. package/dist/exchanges/pacifica.js +17 -2
  146. package/dist/exchanges/registry.d.ts +13 -0
  147. package/dist/exchanges/registry.js +37 -0
  148. package/dist/exchanges/spot-interface.d.ts +9 -0
  149. package/dist/funding/rates.js +1 -1
  150. package/dist/index.js +2 -6
  151. package/dist/jobs.js +1 -1
  152. package/dist/liquidity.d.ts +1 -2
  153. package/dist/liquidity.js +12 -5
  154. package/dist/mcp-server.js +4 -2
  155. package/dist/pacifica/constants.d.ts +0 -3
  156. package/dist/pacifica/constants.js +0 -4
  157. package/dist/pacifica/types/account.d.ts +0 -8
  158. package/dist/pacifica/types/lake.d.ts +0 -6
  159. package/dist/pacifica/types/position.d.ts +0 -12
  160. package/dist/pacifica/types/ws.d.ts +0 -24
  161. package/dist/pacifica/types/ws.js +1 -41
  162. package/dist/plan-executor.d.ts +1 -1
  163. package/dist/rebalance.d.ts +1 -7
  164. package/dist/rebalance.js +0 -6
  165. package/dist/risk.d.ts +1 -1
  166. package/dist/risk.js +3 -1
  167. package/dist/smart-order.d.ts +1 -1
  168. package/dist/strategies/dca.d.ts +1 -1
  169. package/dist/strategies/funding-arb.d.ts +1 -1
  170. package/dist/strategies/funding-arb.js +193 -181
  171. package/dist/strategies/grid.d.ts +1 -1
  172. package/dist/strategies/grid.js +1 -1
  173. package/dist/strategies/index.d.ts +12 -0
  174. package/dist/strategies/index.js +7 -0
  175. package/dist/strategies/split-order.d.ts +1 -1
  176. package/dist/strategies/trailing-stop.d.ts +1 -1
  177. package/dist/strategies/twap.d.ts +1 -1
  178. package/dist/trade-validator.d.ts +1 -1
  179. package/package.json +7 -1
  180. package/skills/perp-cli/SKILL.md +20 -0
  181. package/skills/perp-cli/references/commands.md +22 -8
@@ -1,8 +1,7 @@
1
- import { PacificaAdapter } from "../exchanges/pacifica.js";
2
- import { HyperliquidAdapter } from "../exchanges/hyperliquid.js";
3
1
  import { makeTable, formatUsd, formatPnl, printJson, jsonOk, jsonError, symbolMatch, withJsonErrors } from "../utils.js";
4
2
  import chalk from "chalk";
5
3
  import { assessRisk } from "../risk.js";
4
+ import { hasPacificaSdk, isDexCapable } from "../exchanges/capabilities.js";
6
5
  const EXCHANGES = ["pacifica", "hyperliquid", "lighter"];
7
6
  async function fetchExchangeSnapshot(name, getAdapter) {
8
7
  try {
@@ -96,7 +95,7 @@ function buildSummary(snapshots) {
96
95
  };
97
96
  }
98
97
  function pac(adapter) {
99
- if (!(adapter instanceof PacificaAdapter))
98
+ if (!hasPacificaSdk(adapter))
100
99
  throw new Error("Market settings are only available on Pacifica.");
101
100
  return adapter;
102
101
  }
@@ -112,6 +111,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
112
111
  try {
113
112
  if (name === "hyperliquid") {
114
113
  const { HyperliquidSpotAdapter } = await import("../exchanges/hyperliquid-spot.js");
114
+ const { HyperliquidAdapter } = await import("../exchanges/hyperliquid.js");
115
115
  const hlSpot = new HyperliquidSpotAdapter(adapter);
116
116
  await hlSpot.init();
117
117
  const raw = await hlSpot.getSpotBalances();
@@ -149,7 +149,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
149
149
  catch { /* spot not available */ }
150
150
  // HL unified account: perp equity already includes spot USDC balance.
151
151
  // Detect by checking if adapter is HL without a dex override.
152
- const isUnified = name === "hyperliquid" && !adapter.dex;
152
+ const isUnified = name === "hyperliquid" && (!isDexCapable(adapter) || !adapter.dex);
153
153
  const cutoff24h = Date.now() - 24 * 60 * 60 * 1000;
154
154
  const recent = fundingPayments.filter(f => f.time >= cutoff24h);
155
155
  const funding24h = recent.reduce((sum, f) => sum + Number(f.payment), 0);
@@ -368,7 +368,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
368
368
  ]);
369
369
  }
370
370
  // --hip3: fetch HIP-3 dex positions for HL
371
- if (opts.hip3 && ex === "hyperliquid" && adapter instanceof HyperliquidAdapter) {
371
+ if (opts.hip3 && ex === "hyperliquid" && isDexCapable(adapter)) {
372
372
  const hip3 = await fetchHip3Data(adapter, a => a.getPositions());
373
373
  for (const { dex, items } of hip3) {
374
374
  for (const p of items) {
@@ -397,7 +397,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
397
397
  try {
398
398
  const adapter = await getAdapterForExchange(ex);
399
399
  grouped[ex] = await adapter.getPositions();
400
- if (opts.hip3 && ex === "hyperliquid" && adapter instanceof HyperliquidAdapter) {
400
+ if (opts.hip3 && ex === "hyperliquid" && isDexCapable(adapter)) {
401
401
  const hip3 = await fetchHip3Data(adapter, a => a.getPositions());
402
402
  for (const { dex, items } of hip3)
403
403
  grouped[`hip3:${dex}`] = items;
@@ -423,7 +423,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
423
423
  const positions = await adapter.getPositions();
424
424
  // --hip3: append HIP-3 dex positions
425
425
  const hip3Positions = [];
426
- if (opts.hip3 && adapter instanceof HyperliquidAdapter) {
426
+ if (opts.hip3 && isDexCapable(adapter)) {
427
427
  hip3Positions.push(...await fetchHip3Data(adapter, a => a.getPositions()));
428
428
  }
429
429
  if (isJson()) {
@@ -494,7 +494,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
494
494
  ]);
495
495
  }
496
496
  // --hip3: fetch HIP-3 dex orders for HL
497
- if (opts.hip3 && ex === "hyperliquid" && adapter instanceof HyperliquidAdapter) {
497
+ if (opts.hip3 && ex === "hyperliquid" && isDexCapable(adapter)) {
498
498
  const hip3 = await fetchHip3Data(adapter, a => a.getOpenOrders());
499
499
  for (const { dex, items } of hip3) {
500
500
  for (const o of items) {
@@ -523,7 +523,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
523
523
  try {
524
524
  const adapter = await getAdapterForExchange(ex);
525
525
  grouped[ex] = await adapter.getOpenOrders();
526
- if (opts.hip3 && ex === "hyperliquid" && adapter instanceof HyperliquidAdapter) {
526
+ if (opts.hip3 && ex === "hyperliquid" && isDexCapable(adapter)) {
527
527
  const hip3 = await fetchHip3Data(adapter, a => a.getOpenOrders());
528
528
  for (const { dex, items } of hip3)
529
529
  grouped[`hip3:${dex}`] = items;
@@ -549,7 +549,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
549
549
  const orders = await adapter.getOpenOrders();
550
550
  // --hip3: append HIP-3 dex orders
551
551
  const hip3Orders = [];
552
- if (opts.hip3 && adapter instanceof HyperliquidAdapter) {
552
+ if (opts.hip3 && isDexCapable(adapter)) {
553
553
  hip3Orders.push(...await fetchHip3Data(adapter, a => a.getOpenOrders()));
554
554
  }
555
555
  if (isJson()) {
@@ -623,8 +623,9 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
623
623
  .action(async () => {
624
624
  const adapter = await getAdapter();
625
625
  // Pacifica: use dedicated SDK endpoint
626
- if (adapter instanceof PacificaAdapter) {
627
- const settings = await adapter.sdk.getAccountSettings(adapter.publicKey);
626
+ if (hasPacificaSdk(adapter)) {
627
+ const sdk = adapter.sdk;
628
+ const settings = await sdk.getAccountSettings(adapter.publicKey);
628
629
  if (isJson())
629
630
  return printJson(jsonOk(settings));
630
631
  if (!Array.isArray(settings) || settings.length === 0) {
@@ -902,9 +903,19 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
902
903
  .command("twap-orders")
903
904
  .description("Active TWAP orders")
904
905
  .action(async () => {
905
- const adapter = await getAdapter();
906
- const p = pac(adapter);
907
- const orders = await p.sdk.getTWAPOrders(p.publicKey);
906
+ let p;
907
+ try {
908
+ const adapter = await getAdapter();
909
+ p = pac(adapter);
910
+ }
911
+ catch (err) {
912
+ if (isJson())
913
+ return printJson(jsonError("EXCHANGE_ERROR", err instanceof Error ? err.message : String(err)));
914
+ console.error(chalk.red(`\n ${err instanceof Error ? err.message : String(err)}\n`));
915
+ return;
916
+ }
917
+ const sdk = p.sdk;
918
+ const orders = await sdk.getTWAPOrders(p.publicKey);
908
919
  if (isJson())
909
920
  return printJson(jsonOk(orders));
910
921
  if (!orders || orders.length === 0) {
@@ -932,7 +943,73 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
932
943
  const exchanges = opts.exchange
933
944
  ? opts.exchange.split(",").map(e => e.trim())
934
945
  : [...EXCHANGES];
935
- const snapshots = await Promise.all(exchanges.map(ex => fetchExchangeSnapshot(ex, getAdapterForExchange)));
946
+ // Fetch snapshots + funding + spot ALL in parallel
947
+ const fundingByExSym = new Map();
948
+ const spotRows = [];
949
+ let totalSpotValue = 0;
950
+ const [snapshots] = await Promise.all([
951
+ // Phase 1: balance + positions + orders
952
+ Promise.all(exchanges.map(ex => fetchExchangeSnapshot(ex, getAdapterForExchange))),
953
+ // Phase 2: funding payments (parallel with Phase 1)
954
+ Promise.allSettled(exchanges.map(async (exName) => {
955
+ try {
956
+ const adapter = await getAdapterForExchange(exName);
957
+ const payments = await adapter.getFundingPayments(200);
958
+ for (const p of payments) {
959
+ const sym = p.symbol.replace("-PERP", "").toUpperCase();
960
+ const key = `${exName}:${sym}`;
961
+ fundingByExSym.set(key, (fundingByExSym.get(key) ?? 0) + Number(p.payment));
962
+ }
963
+ }
964
+ catch { /* skip */ }
965
+ })),
966
+ // Phase 3: spot balances (parallel with Phase 1+2)
967
+ Promise.allSettled(exchanges.map(async (exName) => {
968
+ try {
969
+ const adapter = await getAdapterForExchange(exName);
970
+ if (exName === "hyperliquid") {
971
+ const { HyperliquidSpotAdapter } = await import("../exchanges/hyperliquid-spot.js");
972
+ const { HyperliquidAdapter } = await import("../exchanges/hyperliquid.js");
973
+ const hlSpot = new HyperliquidSpotAdapter(adapter);
974
+ await hlSpot.init();
975
+ const bals = await hlSpot.getSpotBalances();
976
+ const markets = await hlSpot.getSpotMarkets();
977
+ const priceMap = new Map(markets.map(m => [m.baseToken.toUpperCase(), Number(m.markPrice)]));
978
+ for (const b of bals) {
979
+ const base = b.token.replace(/-SPOT$/i, "").toUpperCase();
980
+ if (base === "USDC" || Number(b.total) <= 0)
981
+ continue;
982
+ const price = priceMap.get(base) ?? 0;
983
+ const value = price * Number(b.total);
984
+ if (value < 1)
985
+ continue;
986
+ totalSpotValue += value;
987
+ spotRows.push([chalk.white.bold(base), chalk.gray("hyperliquid"), b.total, `$${formatUsd(price)}`, `$${formatUsd(value)}`]);
988
+ }
989
+ }
990
+ else if (exName === "lighter") {
991
+ const { LighterAdapter } = await import("../exchanges/lighter.js");
992
+ const { LighterSpotAdapter } = await import("../exchanges/lighter-spot.js");
993
+ const ltSpot = new LighterSpotAdapter(adapter);
994
+ await ltSpot.init();
995
+ const bals = await ltSpot.getSpotBalances();
996
+ const markets = await ltSpot.getSpotMarkets();
997
+ const priceMap = new Map(markets.map(m => [m.baseToken.toUpperCase(), Number(m.markPrice)]));
998
+ for (const b of bals) {
999
+ if (b.token === "USDC" || b.token === "USDC_SPOT" || Number(b.total) <= 0)
1000
+ continue;
1001
+ const price = priceMap.get(b.token.toUpperCase()) ?? 0;
1002
+ const value = price * Number(b.total);
1003
+ if (value < 1)
1004
+ continue;
1005
+ totalSpotValue += value;
1006
+ spotRows.push([chalk.white.bold(b.token), chalk.gray("lighter"), b.total, `$${formatUsd(price)}`, `$${formatUsd(value)}`]);
1007
+ }
1008
+ }
1009
+ }
1010
+ catch { /* spot not available */ }
1011
+ })),
1012
+ ]);
936
1013
  const summary = buildSummary(snapshots);
937
1014
  if (isJson()) {
938
1015
  return printJson(jsonOk(summary));
@@ -955,7 +1032,6 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
955
1032
  chalk.green("connected"),
956
1033
  ];
957
1034
  });
958
- // Totals row
959
1035
  balRows.push([
960
1036
  chalk.cyan.bold("TOTAL"),
961
1037
  chalk.cyan.bold(`$${formatUsd(summary.totalEquity)}`),
@@ -965,21 +1041,6 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
965
1041
  "",
966
1042
  ]);
967
1043
  console.log(makeTable(["Exchange", "Equity", "Available", "Margin Used", "uPnL", "Status"], balRows));
968
- // ── Positions + Funding ──
969
- // Fetch funding per exchange in parallel
970
- const fundingByExSym = new Map();
971
- await Promise.allSettled(exchanges.map(async (exName) => {
972
- try {
973
- const adapter = await getAdapterForExchange(exName);
974
- const payments = await adapter.getFundingPayments(200);
975
- for (const p of payments) {
976
- const sym = p.symbol.replace("-PERP", "").toUpperCase();
977
- const key = `${exName}:${sym}`;
978
- fundingByExSym.set(key, (fundingByExSym.get(key) ?? 0) + Number(p.payment));
979
- }
980
- }
981
- catch { /* skip */ }
982
- }));
983
1044
  if (summary.positions.length > 0) {
984
1045
  console.log(chalk.white.bold("\n Open Positions"));
985
1046
  const posRows = summary.positions.map(p => {
@@ -1005,65 +1066,7 @@ export function registerAccountCommands(program, getAdapter, isJson, getAdapterF
1005
1066
  else {
1006
1067
  console.log(chalk.gray("\n No open positions.\n"));
1007
1068
  }
1008
- // ── Spot Holdings ──
1009
- const spotRows = [];
1010
- let totalSpotValue = 0;
1011
- for (const exName of exchanges) {
1012
- try {
1013
- const adapter = await getAdapterForExchange(exName);
1014
- if (exName === "hyperliquid") {
1015
- const { HyperliquidSpotAdapter } = await import("../exchanges/hyperliquid-spot.js");
1016
- const hlSpot = new HyperliquidSpotAdapter(adapter);
1017
- await hlSpot.init();
1018
- const bals = await hlSpot.getSpotBalances();
1019
- const markets = await hlSpot.getSpotMarkets();
1020
- const priceMap = new Map(markets.map(m => [m.baseToken.toUpperCase(), Number(m.markPrice)]));
1021
- for (const b of bals) {
1022
- const base = b.token.replace(/-SPOT$/i, "").toUpperCase();
1023
- if (base === "USDC" || Number(b.total) <= 0)
1024
- continue;
1025
- const price = priceMap.get(base) ?? 0;
1026
- const value = price * Number(b.total);
1027
- if (value < 1)
1028
- continue; // skip dust
1029
- totalSpotValue += value;
1030
- spotRows.push([
1031
- chalk.white.bold(base),
1032
- chalk.gray("hyperliquid"),
1033
- b.total,
1034
- `$${formatUsd(price)}`,
1035
- `$${formatUsd(value)}`,
1036
- ]);
1037
- }
1038
- }
1039
- else if (exName === "lighter") {
1040
- const { LighterAdapter } = await import("../exchanges/lighter.js");
1041
- const { LighterSpotAdapter } = await import("../exchanges/lighter-spot.js");
1042
- const ltSpot = new LighterSpotAdapter(adapter);
1043
- await ltSpot.init();
1044
- const bals = await ltSpot.getSpotBalances();
1045
- const markets = await ltSpot.getSpotMarkets();
1046
- const priceMap = new Map(markets.map(m => [m.baseToken.toUpperCase(), Number(m.markPrice)]));
1047
- for (const b of bals) {
1048
- if (b.token === "USDC" || b.token === "USDC_SPOT" || Number(b.total) <= 0)
1049
- continue;
1050
- const price = priceMap.get(b.token.toUpperCase()) ?? 0;
1051
- const value = price * Number(b.total);
1052
- if (value < 1)
1053
- continue;
1054
- totalSpotValue += value;
1055
- spotRows.push([
1056
- chalk.white.bold(b.token),
1057
- chalk.gray("lighter"),
1058
- b.total,
1059
- `$${formatUsd(price)}`,
1060
- `$${formatUsd(value)}`,
1061
- ]);
1062
- }
1063
- }
1064
- }
1065
- catch { /* spot not available */ }
1066
- }
1069
+ // ── Spot Holdings (already fetched in parallel above) ──
1067
1070
  if (spotRows.length > 0) {
1068
1071
  console.log(chalk.white.bold("\n Spot Holdings"));
1069
1072
  console.log(makeTable(["Token", "Exchange", "Amount", "Price", "Value"], spotRows));
@@ -1,3 +1,3 @@
1
1
  import { Command } from "commander";
2
- import type { ExchangeAdapter } from "../exchanges/interface.js";
2
+ import type { ExchangeAdapter } from "../exchanges/index.js";
3
3
  export declare function registerAgentCommands(program: Command, getAdapter: () => Promise<ExchangeAdapter>, isJson: () => boolean): void;
@@ -1,3 +1,3 @@
1
1
  import { Command } from "commander";
2
- import type { ExchangeAdapter } from "../../exchanges/interface.js";
2
+ import { type ExchangeAdapter } from "../../exchanges/index.js";
3
3
  export declare function registerArbManageCommands(program: Command, getAdapterForExchange: (exchange: string) => Promise<ExchangeAdapter>, isJson: () => boolean): void;
@@ -1,12 +1,12 @@
1
1
  import chalk from "chalk";
2
2
  import { makeTable, formatUsd, formatPnl, printJson, jsonOk } from "../../utils.js";
3
+ import { SPOT_PERP_TOKEN_MAP } from "../../exchanges/index.js";
3
4
  import { readExecutionLog, logExecution } from "../../execution-log.js";
4
5
  import { toHourlyRate, computeAnnualSpread } from "../../funding.js";
5
6
  import { fetchPacificaPrices, fetchHyperliquidMeta, fetchLighterOrderBookDetails, fetchLighterFundingRates, } from "../../shared-api.js";
6
7
  import { computeBasisRisk } from "../../arb-utils.js";
7
8
  import { smartOrder } from "../../smart-order.js";
8
9
  import { removePosition as persistRemovePosition, getPositions as getArbStatePositions, loadArbState } from "../../arb-state.js";
9
- import { SPOT_PERP_TOKEN_MAP } from "../../exchanges/spot-interface.js";
10
10
  import { fetchAllBalances, computeRebalancePlan } from "../../rebalance.js";
11
11
  import { EXCHANGE_TO_CHAIN, getBestQuote } from "../../bridge-engine.js";
12
12
  import { computeEnhancedStats } from "../../arb-history-stats.js";
@@ -1,5 +1,5 @@
1
1
  import { Command } from "commander";
2
- import type { ExchangeAdapter } from "../exchanges/interface.js";
2
+ import type { ExchangeAdapter } from "../exchanges/index.js";
3
3
  interface FundingSnapshot {
4
4
  symbol: string;
5
5
  pacRate: number;
@@ -1,7 +1,7 @@
1
1
  import chalk from "chalk";
2
2
  import { formatUsd, printJson, jsonOk, makeTable } from "../utils.js";
3
3
  import { computeExecutableSize } from "../liquidity.js";
4
- import { computeMatchedSize, computeSpotPerpMatchedSize } from "../arb/sizing.js";
4
+ import { computeMatchedSize, computeSpotPerpMatchedSize } from "../arb/index.js";
5
5
  import { computeAnnualSpread, toHourlyRate } from "../funding.js";
6
6
  import { fetchPacificaPricesRaw, parsePacificaRaw, fetchHyperliquidMetaRaw, parseHyperliquidMetaRaw, fetchLighterOrderBookDetailsRaw, fetchLighterFundingRatesRaw, parseLighterRaw, } from "../shared-api.js";
7
7
  import { scanDexArb } from "../dex-asset-map.js";
@@ -1144,7 +1144,7 @@ export function registerArbAutoCommands(program, getAdapterForExchange, isJson,
1144
1144
  if (opts.compare)
1145
1145
  return handleCompare(isJson, opts.compare);
1146
1146
  if (opts.rates)
1147
- return handleRates(isJson, { symbol: opts.symbol, symbols: opts.symbols, all: opts.all, minSpread: opts.min });
1147
+ return handleRates(isJson, { symbol: opts.symbol, symbols: opts.symbols, all: opts.all, minSpread: opts.min, top: opts.top });
1148
1148
  if (opts.basis)
1149
1149
  return handleBasisScan(isJson, { minBasis: opts.min, symbol: typeof opts.basis === "string" ? opts.basis : opts.symbol });
1150
1150
  if (opts.hip3)
@@ -1226,7 +1226,9 @@ export function registerArbAutoCommands(program, getAdapterForExchange, isJson,
1226
1226
  if (!isJson())
1227
1227
  console.log(chalk.cyan(" Scanning perp-perp funding rate spreads...\n"));
1228
1228
  const spreads = await fetchFundingSpreads();
1229
- const filtered = spreads.filter(s => Math.abs(s.spread) >= minSpread);
1229
+ let filtered = spreads.filter(s => Math.abs(s.spread) >= minSpread);
1230
+ if (opts.top)
1231
+ filtered = filtered.slice(0, parseInt(opts.top));
1230
1232
  if (isJson()) {
1231
1233
  const perpPerp = filtered.map(s => {
1232
1234
  const grossSpread = Math.abs(s.spread);
@@ -1,5 +1,5 @@
1
1
  import { Command } from "commander";
2
- import type { ExchangeAdapter } from "../exchanges/interface.js";
2
+ import type { ExchangeAdapter } from "../exchanges/index.js";
3
3
  export declare function registerArbCommands(program: Command, isJson: () => boolean, getAdapterForExchange?: (exchange: string) => Promise<ExchangeAdapter>): void;
4
4
  export interface PriceSnapshot {
5
5
  symbol: string;
@@ -25,6 +25,7 @@ export declare function handleRates(isJson: () => boolean, opts: {
25
25
  symbols?: string;
26
26
  all?: boolean;
27
27
  minSpread: string;
28
+ top?: string;
28
29
  }): Promise<void>;
29
30
  export declare function handleBasisScan(isJson: () => boolean, opts: {
30
31
  minBasis: string;
@@ -278,6 +278,8 @@ export async function handleRates(isJson, opts) {
278
278
  saveFundingSnapshot(allRates);
279
279
  }
280
280
  catch { /* non-critical */ }
281
+ if (opts.top)
282
+ snapshot.symbols = snapshot.symbols.slice(0, parseInt(opts.top));
281
283
  if (isJson()) {
282
284
  // Enrich with 24h rate history for each symbol
283
285
  const now = new Date();
@@ -1,3 +1,3 @@
1
1
  import { Command } from "commander";
2
- import type { ExchangeAdapter } from "../exchanges/interface.js";
2
+ import type { ExchangeAdapter } from "../exchanges/index.js";
3
3
  export declare function registerBotCommands(program: Command, getAdapter: () => Promise<ExchangeAdapter>, getAdapterFor: (exchange: string) => Promise<ExchangeAdapter>, isJson: () => boolean): void;