@t2000/cli 0.22.7 → 0.22.8

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.
package/dist/index.js CHANGED
@@ -2323,9 +2323,16 @@ function registerInvest(program2) {
2323
2323
  }
2324
2324
  const pin = await resolvePin();
2325
2325
  const agent = await T200024.create({ pin, keyPath: opts.key });
2326
+ const sym = asset.toUpperCase();
2327
+ const strategyAmount = agent.portfolio.getStrategyAmountForAsset(sym);
2328
+ const directAmount = agent.portfolio.getDirectAmount(sym);
2329
+ if (isAll && strategyAmount > 0) {
2330
+ console.log(pc14.yellow(` \u26A0 This will sell ALL ${sym} including ${formatAssetAmount4(strategyAmount, sym)} from strategies`));
2331
+ console.log(pc14.dim(` To sell only strategy positions: t2000 invest strategy sell <strategy-name>`));
2332
+ }
2326
2333
  const usdAmount = isAll ? "all" : parseFloat(amount);
2327
2334
  const result = await agent.investSell({
2328
- asset: asset.toUpperCase(),
2335
+ asset: sym,
2329
2336
  usdAmount,
2330
2337
  maxSlippage: parseFloat(opts.slippage) / 100
2331
2338
  });
@@ -2334,7 +2341,6 @@ function registerInvest(program2) {
2334
2341
  return;
2335
2342
  }
2336
2343
  printBlank();
2337
- const sym = asset.toUpperCase();
2338
2344
  printSuccess(`Sold ${formatAssetAmount4(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2339
2345
  printKeyValue("Proceeds", formatUsd15(result.usdValue));
2340
2346
  if (result.realizedPnL !== void 0) {
@@ -2351,6 +2357,67 @@ function registerInvest(program2) {
2351
2357
  handleError(error);
2352
2358
  }
2353
2359
  });
2360
+ investCmd.command("sell-all").description("Sell ALL investment positions (direct + strategies)").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percent", "3").action(async (opts) => {
2361
+ try {
2362
+ const pin = await resolvePin();
2363
+ const agent = await T200024.create({ pin, keyPath: opts.key });
2364
+ const positions = agent.portfolio.getPositions();
2365
+ if (positions.length === 0) {
2366
+ if (isJsonMode()) {
2367
+ printJson({ sold: [] });
2368
+ return;
2369
+ }
2370
+ printBlank();
2371
+ printInfo("No investment positions to sell");
2372
+ printBlank();
2373
+ return;
2374
+ }
2375
+ if (isJsonMode()) {
2376
+ const results = [];
2377
+ for (const pos of positions) {
2378
+ const result = await agent.investSell({
2379
+ asset: pos.asset,
2380
+ usdAmount: "all",
2381
+ maxSlippage: parseFloat(opts.slippage) / 100
2382
+ });
2383
+ results.push(result);
2384
+ }
2385
+ printJson(results);
2386
+ return;
2387
+ }
2388
+ printBlank();
2389
+ printHeader("Selling all positions");
2390
+ printSeparator();
2391
+ let totalProceeds = 0;
2392
+ let totalPnL = 0;
2393
+ for (const pos of positions) {
2394
+ try {
2395
+ const result = await agent.investSell({
2396
+ asset: pos.asset,
2397
+ usdAmount: "all",
2398
+ maxSlippage: parseFloat(opts.slippage) / 100
2399
+ });
2400
+ const pnl = result.realizedPnL ?? 0;
2401
+ const pnlColor = pnl >= 0 ? pc14.green : pc14.red;
2402
+ const pnlSign = pnl >= 0 ? "+" : "";
2403
+ printKeyValue(pos.asset, `${formatUsd15(result.usdValue)} ${pnlColor(`${pnlSign}${formatUsd15(pnl)}`)}`);
2404
+ totalProceeds += result.usdValue;
2405
+ totalPnL += pnl;
2406
+ } catch (err) {
2407
+ const msg = err instanceof Error ? err.message : String(err);
2408
+ console.error(pc14.yellow(` \u26A0 ${pos.asset}: ${msg}`));
2409
+ }
2410
+ }
2411
+ printSeparator();
2412
+ printKeyValue("Total proceeds", formatUsd15(totalProceeds));
2413
+ const rpnlColor = totalPnL >= 0 ? pc14.green : pc14.red;
2414
+ const rpnlSign = totalPnL >= 0 ? "+" : "";
2415
+ printKeyValue("Realized P&L", rpnlColor(`${rpnlSign}${formatUsd15(totalPnL)}`));
2416
+ printBlank();
2417
+ } catch (error) {
2418
+ handleError(error);
2419
+ }
2420
+ });
2354
2421
  investCmd.command("earn <asset>").description("Deposit invested asset into best-rate lending protocol").option("--key <path>", "Key file path").option("--protocol <name>", "Force a specific protocol (navi, suilend)").action(async (asset, opts) => {
2355
2422
  try {
2356
2423
  const pin = await resolvePin();