dexbot 1.6.13 → 1.6.15

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 (114) hide show
  1. package/CHANGELOG.md +66 -4
  2. package/README.md +2 -2
  3. package/analysis/README.md +6 -6
  4. package/analysis/tradingview/README.md +2 -1
  5. package/claw/README.md +7 -7
  6. package/claw/docs/AI_BOT_LIBRARY_API.md +1 -1
  7. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
  8. package/claw/modules/claw_catalog.ts +8 -4
  9. package/claw/modules/dexbot_profiles.ts +59 -15
  10. package/claw/modules/types.ts +2 -1
  11. package/claw/package.json +1 -1
  12. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  14. package/claw/skills/margin-trading/SKILL.md +1 -1
  15. package/claw/skills/margin-trading/references/position-management.md +1 -1
  16. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +105 -31
  17. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +36 -2
  18. package/dist/dexbot.js +23 -3
  19. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +26 -11
  20. package/dist/modules/account_bots.d.ts +10 -6
  21. package/dist/modules/account_bots.js +13 -10
  22. package/dist/modules/account_orders.d.ts +36 -4
  23. package/dist/modules/account_orders.js +76 -5
  24. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
  25. package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
  26. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
  27. package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
  28. package/dist/modules/bitshares-native/subscriptions.js +1 -1
  29. package/dist/modules/bot_defaults.d.ts +29 -4
  30. package/dist/modules/bot_defaults.js +65 -10
  31. package/dist/modules/bot_settings.d.ts +4 -0
  32. package/dist/modules/bot_settings.js +58 -21
  33. package/dist/modules/config.js +6 -1
  34. package/dist/modules/constants.d.ts +13 -5
  35. package/dist/modules/constants.js +36 -5
  36. package/dist/modules/credit_runtime.d.ts +35 -5
  37. package/dist/modules/credit_runtime.js +219 -38
  38. package/dist/modules/dexbot_class.d.ts +23 -0
  39. package/dist/modules/dexbot_class.js +60 -17
  40. package/dist/modules/dexbot_cow_runtime.d.ts +62 -174
  41. package/dist/modules/dexbot_cow_runtime.js +350 -64
  42. package/dist/modules/dexbot_credential_client.d.ts +1 -16
  43. package/dist/modules/dexbot_credential_client.js +1 -1
  44. package/dist/modules/dexbot_fill_runtime.d.ts +2 -2
  45. package/dist/modules/dexbot_fill_runtime.js +16 -8
  46. package/dist/modules/dexbot_maintenance_runtime.d.ts +24 -81
  47. package/dist/modules/dexbot_maintenance_runtime.js +104 -70
  48. package/dist/modules/dexbot_startup_runtime.js +15 -2
  49. package/dist/modules/dexbot_state_recovery.js +17 -1
  50. package/dist/modules/key_store.d.ts +0 -5
  51. package/dist/modules/key_store.js +1 -1
  52. package/dist/modules/order/accounting.js +11 -11
  53. package/dist/modules/order/export.js +4 -4
  54. package/dist/modules/order/format.d.ts +15 -1
  55. package/dist/modules/order/format.js +19 -1
  56. package/dist/modules/order/genesis_policy.d.ts +1 -1
  57. package/dist/modules/order/genesis_policy.js +1 -1
  58. package/dist/modules/order/grid.d.ts +141 -12
  59. package/dist/modules/order/grid.js +666 -92
  60. package/dist/modules/order/grid_reconcile.d.ts +1 -1
  61. package/dist/modules/order/grid_reconcile.js +9 -8
  62. package/dist/modules/order/grid_reconcile_internal.js +61 -58
  63. package/dist/modules/order/index.d.ts +37 -9
  64. package/dist/modules/order/logger.js +2 -2
  65. package/dist/modules/order/manager.d.ts +10 -2
  66. package/dist/modules/order/manager.js +56 -31
  67. package/dist/modules/order/strategy.d.ts +2 -2
  68. package/dist/modules/order/strategy.js +51 -21
  69. package/dist/modules/order/sync_engine.js +22 -9
  70. package/dist/modules/order/utils/math.d.ts +101 -29
  71. package/dist/modules/order/utils/math.js +215 -84
  72. package/dist/modules/order/utils/order.d.ts +58 -58
  73. package/dist/modules/order/utils/order.js +135 -106
  74. package/dist/modules/order/utils/system.d.ts +193 -6
  75. package/dist/modules/order/utils/system.js +394 -31
  76. package/dist/modules/order/utils/validate.d.ts +1 -1
  77. package/dist/modules/order/utils/validate.js +71 -59
  78. package/dist/modules/runtime_settings.d.ts +1 -1
  79. package/dist/modules/runtime_settings.js +3 -3
  80. package/dist/modules/types.d.ts +55 -4
  81. package/dist/scripts/analyze-credit.js +44 -27
  82. package/dist/scripts/analyze-orders.d.ts +1 -1
  83. package/dist/scripts/analyze-orders.js +4 -4
  84. package/dist/scripts/diagnose-pool-history.js +35 -30
  85. package/dist/scripts/divergence-calc.js +6 -6
  86. package/dist/scripts/pnl.js +1 -1
  87. package/dist/scripts/rich_list.d.ts +18 -0
  88. package/dist/scripts/rich_list.js +461 -0
  89. package/dist/scripts/run-tests.js +80 -4
  90. package/dist/scripts/validate_bots.d.ts +1 -1
  91. package/dist/scripts/validate_bots.js +3 -3
  92. package/dist/unlock.d.ts +2 -1
  93. package/dist/unlock.js +11 -5
  94. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -2
  95. package/docs/COW_INVARIANTS.md +12 -6
  96. package/docs/DEXBOT_COMPARISON.md +7 -7
  97. package/docs/EVOLUTION.md +10 -8
  98. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
  99. package/docs/GRID_PRICE_INVARIANT.md +3 -3
  100. package/docs/GRID_RECALCULATION.md +4 -1
  101. package/docs/GRID_RECONCILE.md +4 -4
  102. package/docs/LIFECYCLE.md +11 -11
  103. package/docs/LOGGING.md +30 -1
  104. package/docs/MPA_CREDIT_USAGE.md +11 -6
  105. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +170 -12
  106. package/docs/README.md +3 -3
  107. package/docs/WORKFLOW.md +1 -0
  108. package/docs/architecture.md +62 -8
  109. package/docs/developer_guide.md +12 -3
  110. package/market_adapter/README.md +4 -4
  111. package/modules/README.md +1 -1
  112. package/package.json +2 -1
  113. package/scripts/README.md +59 -32
  114. package/tests/README.md +12 -3
@@ -118,7 +118,27 @@ function resolveChartStorageKey(meta = {}, baseIntervalSeconds = 0) {
118
118
  }
119
119
  function generateHTML(data, title = 'TradingView Style Research') {
120
120
  const rawCandles = Array.isArray(data.candles) ? data.candles : [];
121
- const candles = rawCandles.map(normalizeCandle).filter(Boolean);
121
+ const normalizedCandles = rawCandles
122
+ .map(normalizeCandle)
123
+ .filter((c) => c != null);
124
+ // Data-quality guard: uPlot, inferBaseIntervalSeconds and aggregateCandles all
125
+ // assume ascending bucket time, and an out-of-order series silently corrupts
126
+ // the chart (zig-zag lines, wrong base interval, buckets split during
127
+ // aggregation). Normalize order at the single entry point so every source is
128
+ // safe. A stable sort is a no-op for already-ascending input, so valid charts
129
+ // render unchanged; only bad input is reordered (and reported).
130
+ let outOfOrder = false;
131
+ for (let i = 1; i < normalizedCandles.length; i++) {
132
+ if (normalizedCandles[i].time < normalizedCandles[i - 1].time) {
133
+ outOfOrder = true;
134
+ break;
135
+ }
136
+ }
137
+ const candles = outOfOrder
138
+ ? normalizedCandles.slice().sort((a, b) => a.time - b.time)
139
+ : normalizedCandles;
140
+ if (outOfOrder)
141
+ console.warn('[TradingView] candle input was out of order; sorted ascending before rendering');
122
142
  if (candles.length === 0)
123
143
  throw new Error('No candle data in input');
124
144
  const meta = data.meta || {};
@@ -126,6 +146,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
126
146
  ? Number(meta.intervalSeconds)
127
147
  : inferBaseIntervalSeconds(candles, 3600);
128
148
  const timeframes = [
149
+ { label: '1h', seconds: 3600 },
129
150
  { label: '4h', seconds: 14400 },
130
151
  { label: '1d', seconds: 86400 },
131
152
  { label: '1w', seconds: 604800 },
@@ -211,6 +232,15 @@ function generateHTML(data, title = 'TradingView Style Research') {
211
232
  const storageKey = typeof data.storageKey === 'string' && data.storageKey.length > 0
212
233
  ? data.storageKey
213
234
  : resolveChartStorageKey(meta, baseIntervalSeconds);
235
+ // Data-freshness anchor for the in-page live age badge: the newest candle's
236
+ // bucket time (epoch seconds), falling back to the source file's
237
+ // `meta.updatedAt`. Null hides the age (non-JSON sources may carry neither).
238
+ const lastCandleEntry = candles.length ? candles[candles.length - 1] : null;
239
+ const lastCandleSec = Number(lastCandleEntry?.time);
240
+ const metaUpdatedMs = Date.parse(String(meta.updatedAt ?? ''));
241
+ const dataUpdatedAtSec = Number.isFinite(lastCandleSec) && lastCandleSec > 0
242
+ ? Math.floor(lastCandleSec)
243
+ : (Number.isFinite(metaUpdatedMs) ? Math.floor(metaUpdatedMs / 1000) : null);
214
244
  const payload = {
215
245
  storageKey,
216
246
  syncKey: TRADINGVIEW_SYNC_KEY,
@@ -247,6 +277,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
247
277
  pairLabelInverse,
248
278
  poolLabel,
249
279
  intervalLabel,
280
+ intervalSeconds: baseIntervalSeconds,
281
+ dataUpdatedAtSec,
250
282
  amaDefaultsSource: marketProfiles ? 'market_profiles' : 'constants',
251
283
  volumeIsCount: !!meta?.feed,
252
284
  };
@@ -280,8 +312,16 @@ function generateHTML(data, title = 'TradingView Style Research') {
280
312
  backdrop-filter: blur(10px);
281
313
  }
282
314
  #brand { display: flex; flex-direction: column; gap: 4px; min-width: 240px; }
315
+ #title-row { display: flex; align-items: baseline; gap: 10px; }
283
316
  #title { font-size: 15px; font-weight: 700; color: #f5f8fb; }
284
- #subtitle { font-size: 11px; color: #b9c6d4; text-transform: uppercase; letter-spacing: 0.6px; }
317
+ #subtitle { font-size: 12px; color: #b9c6d4; text-transform: uppercase; letter-spacing: 0.6px; }
318
+ #data-age { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: #8290a2; letter-spacing: 0.2px; }
319
+ #data-age::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.18); }
320
+ #data-age.is-stale { color: #d8b36a; }
321
+ #data-age.is-stale::before { background: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,0.18); }
322
+ #data-age.is-outdated { color: #e08585; }
323
+ #data-age.is-outdated::before { background: #ef5350; box-shadow: 0 0 0 2px rgba(239,83,80,0.18); }
324
+ #data-age.is-unknown::before { background: #475569; box-shadow: none; }
285
325
  #toolbar { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
286
326
  .toolbar-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 12px; align-items: center; }
287
327
  .group { display: inline-flex; align-items: center; gap: 8px; padding-left: 12px; border-left: 1px solid #263241; }
@@ -522,8 +562,11 @@ function generateHTML(data, title = 'TradingView Style Research') {
522
562
  <div id="app">
523
563
  <div id="topbar">
524
564
  <div id="brand">
525
- <div id="title">${escapeHtml(title)}</div>
526
- <div id="subtitle">${escapeHtml(poolLabel)} · ${escapeHtml(pairLabelNormal)} · ${escapeHtml(intervalLabel)} base · indicators from 1h · volume · uPlot</div>
565
+ <div id="title-row">
566
+ <div id="title">${escapeHtml(title)}</div>
567
+ <span id="data-age" title="Age of the newest candle, recomputed live in the browser. Fresh: under 24h, stale: 1–7 days, out of date: over a week.">—</span>
568
+ </div>
569
+ <div id="subtitle">${escapeHtml(poolLabel)} · ${escapeHtml(pairLabelNormal)} · ${escapeHtml(intervalLabel)} base · indicators from 1h</div>
527
570
  </div>
528
571
  <div id="toolbar">
529
572
  <div class="toolbar-row primary-toolbar-row">
@@ -641,6 +684,37 @@ function generateHTML(data, title = 'TradingView Style Research') {
641
684
  const volumeEl = document.getElementById('volume-chart');
642
685
  const baseCandles = Array.isArray(payload.candles) ? payload.candles.slice() : [];
643
686
  const baseCloseValues = baseCandles.map((c) => c.close);
687
+ // Live data-age badge: recomputed from the clock every minute, so a chart
688
+ // saved or opened later shows how stale its newest candle is. The
689
+ // freshness anchor is the newest candle's bucket time, embedded at
690
+ // generation time; the interval sets the color thresholds.
691
+ const dataAgeEl = document.getElementById('data-age');
692
+ const dataUpdatedAtSec = Number(payload.dataUpdatedAtSec) > 0 ? Number(payload.dataUpdatedAtSec) : NaN;
693
+ function formatDataAge(sec) {
694
+ const totalMin = Math.floor(sec / 60);
695
+ if (totalMin < 60) return totalMin + 'm';
696
+ const totalHours = Math.floor(totalMin / 60);
697
+ if (totalHours < 24) return totalHours + 'h ' + String(totalMin % 60).padStart(2, '0') + 'm';
698
+ return Math.floor(totalHours / 24) + 'd ' + (totalHours % 24) + 'h';
699
+ }
700
+ function refreshDataAge() {
701
+ if (!dataAgeEl) return;
702
+ if (!Number.isFinite(dataUpdatedAtSec)) {
703
+ dataAgeEl.className = 'is-unknown';
704
+ dataAgeEl.textContent = '—';
705
+ return;
706
+ }
707
+ const ageSec = Math.max(0, Date.now() / 1000 - dataUpdatedAtSec);
708
+ // Fresh: under 24h. Stale: 1d–7d. Out of date: over a week.
709
+ const DAY = 86400;
710
+ const level = ageSec < DAY ? 'fresh'
711
+ : ageSec < DAY * 7 ? 'stale' : 'outdated';
712
+ dataAgeEl.className = level === 'fresh' ? '' : 'is-' + level;
713
+ dataAgeEl.textContent = formatDataAge(ageSec);
714
+ dataAgeEl.title = 'Newest candle in this chart is ' + Math.round(ageSec / 60) + ' minute(s) old (computed live in the browser).';
715
+ }
716
+ refreshDataAge();
717
+ setInterval(refreshDataAge, 60000);
644
718
  const timeframes = Array.isArray(payload.timeframes) ? payload.timeframes.slice() : [];
645
719
  const timeframeMap = new Map(timeframes.map((item) => [item.label, item]));
646
720
  const STORAGE_KEY = typeof payload.storageKey === 'string' && payload.storageKey.length > 0
@@ -1134,7 +1208,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
1134
1208
  function refreshSubtitle() {
1135
1209
  const subtitleEl = document.getElementById('subtitle');
1136
1210
  if (!subtitleEl) return;
1137
- subtitleEl.textContent = payload.poolLabel + ' · ' + getPairLabel() + ' · ' + payload.intervalLabel + ' base · indicators from 1h · volume · uPlot';
1211
+ subtitleEl.textContent = payload.poolLabel + ' · ' + getPairLabel() + ' · ' + payload.intervalLabel + ' base · indicators from 1h';
1138
1212
  }
1139
1213
  function snapInitOffset(value) {
1140
1214
  const next = Math.round(Number(value) || 0);
@@ -2314,7 +2388,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
2314
2388
  return { hooks: { draw: [drawSimBand, drawSimResets] } };
2315
2389
  }
2316
2390
  function buildData() {
2317
- const tf = timeframeMap.get(currentTimeframe) || timeframeMap.get(defaultTimeframe.label) || timeframes[0];
2391
+ const tf = timeframeMap.get(currentTimeframe) || timeframeMap.get(payload.defaultTimeframe) || timeframes[0];
2318
2392
  currentSeriesState = getSeriesState(currentPairMode);
2319
2393
  currentSeriesCandles = currentSeriesState.candles;
2320
2394
  currentSeriesCloseValues = currentSeriesState.closeValues;
@@ -2637,8 +2711,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
2637
2711
  // Spread = best buy/best sell gap.
2638
2712
  // Pair-aware: order prices invert (1/p) with the candles so B/A shows
2639
2713
  // the same levels in display units (side colors preserved).
2640
- let reserveLine = null;
2641
- let reserveLabel = null;
2714
+ let edgeLine = null;
2715
+ let edgeLabel = null;
2642
2716
  let ceilingLine = null;
2643
2717
  let ceilingLabel = null;
2644
2718
  let spreadMidLabel = null;
@@ -2670,7 +2744,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
2670
2744
  return (overRect.top - rootRect.top) + (1 - frac) * overRect.height;
2671
2745
  }
2672
2746
  function hideOverlayNodes() {
2673
- [reserveLine, reserveLabel, ceilingLine, ceilingLabel, spreadMidLabel, orderBuyLabel, orderSellLabel].forEach((n) => { if (n) n.style.display = 'none'; });
2747
+ [edgeLine, edgeLabel, ceilingLine, ceilingLabel, spreadMidLabel, orderBuyLabel, orderSellLabel].forEach((n) => { if (n) n.style.display = 'none'; });
2674
2748
  orderLineDivs.forEach((d) => { d.style.display = 'none'; });
2675
2749
  orderPriceTags.forEach((t) => { t.style.display = 'none'; });
2676
2750
  }
@@ -2678,15 +2752,15 @@ function generateHTML(data, title = 'TradingView Style Research') {
2678
2752
  if (!u || !u.over || !currentCandles.length) return;
2679
2753
  if (!currentOrdersVisible || (!hasOrders && !hasBounds)) { hideOverlayNodes(); return; }
2680
2754
  try { if (getComputedStyle(u.root).position === 'static') u.root.style.position = 'relative'; } catch (e) {}
2681
- if (!reserveLine || reserveLine.parentNode !== u.root) {
2682
- if (reserveLine && reserveLine.parentNode) reserveLine.parentNode.removeChild(reserveLine);
2683
- if (reserveLabel && reserveLabel.parentNode) reserveLabel.parentNode.removeChild(reserveLabel);
2684
- reserveLine = document.createElement('div');
2685
- reserveLine.style.cssText = 'position:absolute;z-index:1;pointer-events:none;height:0;border-top:2px dashed #f97316;opacity:0.7;left:0;right:0;display:none;';
2686
- reserveLabel = document.createElement('div');
2687
- reserveLabel.style.cssText = 'position:absolute;z-index:25;pointer-events:none;font:600 10px Segoe UI, sans-serif;line-height:15px;height:15px;padding:0 5px;border-radius:3px;color:#f97316;background:rgba(30,41,59,0.9);white-space:nowrap;display:none;';
2688
- u.root.appendChild(reserveLine);
2689
- u.root.appendChild(reserveLabel);
2755
+ if (!edgeLine || edgeLine.parentNode !== u.root) {
2756
+ if (edgeLine && edgeLine.parentNode) edgeLine.parentNode.removeChild(edgeLine);
2757
+ if (edgeLabel && edgeLabel.parentNode) edgeLabel.parentNode.removeChild(edgeLabel);
2758
+ edgeLine = document.createElement('div');
2759
+ edgeLine.style.cssText = 'position:absolute;z-index:1;pointer-events:none;height:0;border-top:2px dashed #f97316;opacity:0.7;left:0;right:0;display:none;';
2760
+ edgeLabel = document.createElement('div');
2761
+ edgeLabel.style.cssText = 'position:absolute;z-index:25;pointer-events:none;font:600 10px Segoe UI, sans-serif;line-height:15px;height:15px;padding:0 5px;border-radius:3px;color:#f97316;background:rgba(30,41,59,0.9);white-space:nowrap;display:none;';
2762
+ u.root.appendChild(edgeLine);
2763
+ u.root.appendChild(edgeLabel);
2690
2764
  }
2691
2765
  // Grid bounds span the full DEXBot grid (live + virtual slots
2692
2766
  // in base units), never calculated: bottom = lowest grid buy,
@@ -2699,7 +2773,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
2699
2773
  const gridLow = Number.isFinite(rawLow) && rawLow > 0 ? rawLow : null;
2700
2774
  const gridHigh = Number.isFinite(rawHigh) && rawHigh > 0 ? rawHigh : null;
2701
2775
  const inversePairs = normalizePairMode(currentPairMode) === 'inverse';
2702
- const reservePrice = inversePairs
2776
+ const edgePrice = inversePairs
2703
2777
  ? (gridHigh != null ? 1 / gridHigh : null)
2704
2778
  : gridLow;
2705
2779
  const ceilingPrice = inversePairs
@@ -2708,20 +2782,20 @@ function generateHTML(data, title = 'TradingView Style Research') {
2708
2782
  const ys = u.scales.y || {};
2709
2783
  const rootRect = u.root.getBoundingClientRect();
2710
2784
  const overRect = u.over.getBoundingClientRect();
2711
- const y = reservePrice != null ? yForPriceCached(ys, overRect, rootRect, reservePrice) : null;
2785
+ const y = edgePrice != null ? yForPriceCached(ys, overRect, rootRect, edgePrice) : null;
2712
2786
  if (y == null) {
2713
- reserveLine.style.display = 'none';
2714
- reserveLabel.style.display = 'none';
2787
+ edgeLine.style.display = 'none';
2788
+ edgeLabel.style.display = 'none';
2715
2789
  } else {
2716
- reserveLine.style.display = 'block';
2717
- reserveLine.style.top = y + 'px';
2790
+ edgeLine.style.display = 'block';
2791
+ edgeLine.style.top = y + 'px';
2718
2792
  const lastClose = currentCandles[currentCandles.length - 1].close;
2719
- const dipRaw = Number.isFinite(lastClose) && lastClose > 0 ? (lastClose - reservePrice) / lastClose * 100 : NaN;
2793
+ const dipRaw = Number.isFinite(lastClose) && lastClose > 0 ? (lastClose - edgePrice) / lastClose * 100 : NaN;
2720
2794
  const dipTxt = Number.isFinite(dipRaw) ? (dipRaw >= 0 ? '-' : '+') + Math.abs(Math.round(dipRaw)) + '%' : '-';
2721
- reserveLabel.style.display = 'block';
2722
- reserveLabel.textContent = 'reserve ' + fmtPriceLabel(reservePrice) + ' (' + dipTxt + ')';
2723
- reserveLabel.style.left = '8px';
2724
- reserveLabel.style.top = (y - 16) + 'px';
2795
+ edgeLabel.style.display = 'block';
2796
+ edgeLabel.textContent = 'reserve ' + fmtPriceLabel(edgePrice) + ' (' + dipTxt + ')';
2797
+ edgeLabel.style.left = '8px';
2798
+ edgeLabel.style.top = (y - 16) + 'px';
2725
2799
  }
2726
2800
  if (!ceilingLine || ceilingLine.parentNode !== u.root) {
2727
2801
  if (ceilingLine && ceilingLine.parentNode) ceilingLine.parentNode.removeChild(ceilingLine);
@@ -2878,8 +2952,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
2878
2952
  }
2879
2953
  }
2880
2954
  function resetOverlayNodes() {
2881
- reserveLine = null;
2882
- reserveLabel = null;
2955
+ edgeLine = null;
2956
+ edgeLabel = null;
2883
2957
  ceilingLine = null;
2884
2958
  ceilingLabel = null;
2885
2959
  spreadMidLabel = null;
@@ -199,6 +199,9 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
199
199
  ${uplotInlineTags()}
200
200
  <style>
201
201
  ${sharedChartCSS()}
202
+ /* Panel titles sit at the top-right; make them clearly readable
203
+ (shared CSS uses a very dark #30363d that vanishes on the dark bg). */
204
+ .section-label { color: #c9d1d9; font-size: 10px; }
202
205
  #price-panel { flex: 0 0 34%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
203
206
  #ama-panel { flex: 0 0 14%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
204
207
  #kalman-panel { flex: 0 0 21%; min-height: 0; position: relative; border-bottom: 1px solid #30363d; }
@@ -256,11 +259,12 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
256
259
  .ctrl.off .val { color: #3fb950; }
257
260
  .ctrl.nz input[type="range"] { accent-color: #8b949e; }
258
261
  .ctrl.nz .val { color: #8b949e; }
259
- .copy-btn, .paste-btn { pointer-events: auto; margin-left: 6px; padding: 2px 10px; font-size: 10px; background: #21262d; color: #8b949e; border: 1px solid #30363d; border-radius: 4px; cursor: pointer; }
260
- .copy-btn:hover, .paste-btn:hover { background: #30363d; color: #e6edf3; }
262
+ .copy-btn, .paste-btn, .reset-btn { pointer-events: auto; margin-left: 6px; padding: 2px 10px; font-size: 10px; background: #21262d; color: #8b949e; border: 1px solid #30363d; border-radius: 4px; cursor: pointer; }
263
+ .copy-btn:hover, .paste-btn:hover, .reset-btn:hover { background: #30363d; color: #e6edf3; }
261
264
  .copy-btn.copied { color: #3fb950; border-color: #3fb950; }
262
265
  .paste-btn.pasted { color: #58a6ff; border-color: #58a6ff; }
263
266
  .paste-btn.error { color: #f85149; border-color: #f85149; }
267
+ .reset-btn.reset { color: #d29922; border-color: #d29922; }
264
268
  #paste-confirm { display: none; position: fixed; background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 14px 16px; z-index: 1000; box-shadow: 0 4px 24px rgba(0,0,0,0.7); min-width: 200px; }
265
269
  #paste-confirm-title { font-size: 10px; color: #8b949e; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
266
270
  #paste-confirm-vals { font-size: 11px; font-family: monospace; color: #e6edf3; line-height: 1.7; margin-bottom: 12px; }
@@ -346,6 +350,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
346
350
  <div class="ctrl regime"><label for="regime-slider">regi</label><input type="range" id="regime-slider" min="0" max="${REGI_MAX * 100}" value="${regimeInitSlider}" title="Regime Sensitivity"><span class="val" id="regime-value">${defaultRegimeSensitivity.toFixed(2)}</span></div>
347
351
  <button class="copy-btn" id="copy-params-btn">copy</button>
348
352
  <button class="paste-btn" id="paste-params-btn">paste</button>
353
+ <button class="reset-btn" id="reset-params-btn">reset</button>
349
354
  </div>
350
355
  <div id="output-chart"></div>
351
356
  </div>
@@ -1285,6 +1290,27 @@ function applyParams(p, btn) {
1285
1290
 
1286
1291
  const LS_KEY = 'dw_research_params';
1287
1292
 
1293
+ // Factory defaults captured server-side; the reset button restores
1294
+ // every knob to these values.
1295
+ const RESET_PARAMS = ${JSON.stringify({
1296
+ alpha: defaultAlpha,
1297
+ amaMaxSlopePct: defaultAmaMaxSlopePct,
1298
+ kalmanMaxSlopePct: defaultKalmanMaxSlopePct,
1299
+ minOutputThreshold: defaultMinOutputThreshold,
1300
+ gain: defaultGain,
1301
+ kalmanSmoothPct: defaultKalmanSmoothPct,
1302
+ kalmanDispScaleMult: defaultKalmanDispScaleMult,
1303
+ dispScaleMinPct: defaultDispScaleMinPct,
1304
+ kalmanDispThresholdMult: defaultKalmanDispThresholdMult,
1305
+ kalmanSmoothSpanPct: defaultKalmanSmoothSpanPct,
1306
+ signalConfirmBars: defaultSignalConfirmBars,
1307
+ clipPct: defaultClipPct,
1308
+ neutralZonePct: defaultNeutralZone,
1309
+ regimeSensitivity: defaultRegimeSensitivity,
1310
+ dispWeight: defaultDispWeight,
1311
+ lookbackBars,
1312
+ })};
1313
+
1288
1314
  document.getElementById('copy-params-btn').addEventListener('click', () => {
1289
1315
  const btn = document.getElementById('copy-params-btn');
1290
1316
  const params = {
@@ -1340,6 +1366,14 @@ function applyParams(p, btn) {
1340
1366
  ta.addEventListener('keydown', (e) => { if (e.key === 'Escape') cleanup(); });
1341
1367
  setTimeout(cleanup, 10000);
1342
1368
  });
1369
+
1370
+ document.getElementById('reset-params-btn').addEventListener('click', () => {
1371
+ const btn = document.getElementById('reset-params-btn');
1372
+ applyParams(RESET_PARAMS);
1373
+ btn.textContent = 'reset!';
1374
+ btn.classList.add('reset');
1375
+ setTimeout(() => { btn.textContent = 'reset'; btn.classList.remove('reset'); }, 1500);
1376
+ });
1343
1377
  }
1344
1378
 
1345
1379
  ${sizeChartsFn([['priceChart', 'price-panel'], ['amaChart', 'ama-panel'], ['kalmanChart', 'kalman-panel'], ['outputChart', 'output-panel']])}
package/dist/dexbot.js CHANGED
@@ -47,7 +47,7 @@ const __dirname = _esmDirname(__filename);
47
47
  * Runtime: dexbot start [bot] | stop | reload | restart | delete | status | pm2
48
48
  * Trading: dexbot test <bot> | drystart <bot> | reset {all|<bot>}
49
49
  * Config: dexbot bot | key | enable {all|<bot>} | disable {all|<bot>} | default | update
50
- * Analysis: dexbot order [<bot>] | export <bot> | credit [<bot>]
50
+ * Analysis: dexbot order [<bot>] | export <bot> | credit [<bot>] | rich <asset...>
51
51
  * dexbot tv <target> | dw <target> | pnl <account>
52
52
  * Files: dexbot clear | clear-orders | clear-market-adapter | clear-all
53
53
  *
@@ -142,7 +142,7 @@ if (typeof credentialPolicy.checkPolicyFileSecurity === 'function')
142
142
  // Primary CLI driver that manages tracked bots and helper utilities such as key/bot editors.
143
143
  const PROFILES_BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
144
144
  const PROFILES_DIR = PATHS.PROFILES_DIR;
145
- const CLI_COMMANDS = ['start', 'test', 'reset', 'default', 'disable', 'enable', 'drystart', 'key', 'bot', 'pm2', 'update', 'export', 'order', 'credit', 'tv', 'dw', 'pnl', 'git', 'clear', 'clear-orders', 'clear-market-adapter', 'clear-all', 'status', 'unlock', 'delete', 'stop', 'restart', 'reload', 'help'];
145
+ const CLI_COMMANDS = ['start', 'test', 'reset', 'default', 'disable', 'enable', 'drystart', 'key', 'bot', 'pm2', 'update', 'export', 'order', 'credit', 'rich', 'tv', 'dw', 'pnl', 'git', 'clear', 'clear-orders', 'clear-market-adapter', 'clear-all', 'status', 'unlock', 'delete', 'stop', 'restart', 'reload', 'help'];
146
146
  const COMMAND_ALIASES = { orders: 'order', keys: 'key', bots: 'bot', stat: 'status', stats: 'status', start: 'unlock', defaults: 'default', stp: 'stop', stopall: 'stop', restartall: 'restart', reloadall: 'reload' };
147
147
  const CLI_HELP_FLAGS = ['-h', '--help'];
148
148
  const CLI_EXAMPLES_FLAG = '--cli-examples';
@@ -157,6 +157,7 @@ const CLI_EXAMPLES = [
157
157
  { title: 'Export bot trades', command: 'dexbot export <bot>', notes: 'Write trades and settings to CSV/JSON.' },
158
158
  { title: 'Analyze order grids', command: 'dexbot order', notes: 'Spread, increment, and funds; --export for HTML.' },
159
159
  { title: 'Show live credit positions', command: 'dexbot credit', notes: 'Summed MPA + borrowed-credit positions per bot.' },
160
+ { title: 'Asset rich list', command: 'dexbot rich <asset> [<asset...>]', notes: 'Top holder(s) per asset from the chain asset holders API.' },
160
161
  { title: 'Chart a bot, pool, or pair', command: 'dexbot tv <bot|pool-id|AssetA/AssetB> --month 3', notes: 'OHLC chart; --feed charts MPA price-feed history.' },
161
162
  { title: 'PnL report', command: 'dexbot pnl <bot|account> --month 3 [--pair BASE/QUOTE]', notes: 'Self-contained HTML PnL report for the resolved bot or chain account.' }
162
163
  ];
@@ -213,6 +214,7 @@ function printCLIUsage() {
213
214
  ['order [<bot>]', 'Analyze persisted order grids; --export for HTML.'],
214
215
  ['export <bot>', 'Export bot trades/settings to CSV/JSON.'],
215
216
  ['credit [<bot>]', 'Show live MPA and borrowed-credit positions.'],
217
+ ['rich <asset...>', 'Per-asset rich list / top holder; --top N, --json.'],
216
218
  ['tv <target>', 'OHLC chart for <bot|pool-id|AssetA/AssetB>; --month N (default 3), --feed for MPA price-feed history.'],
217
219
  ['dw <target>', 'Dynamic-weight research chart; same targets and flags as tv.'],
218
220
  ['pnl <account>', 'HTML PnL report for a bot or account; --month N, optional --pair BASE/QUOTE filter.'],
@@ -260,7 +262,7 @@ if (cliArgs.some(arg => CLI_HELP_FLAGS.includes(arg))) {
260
262
  // so the script prints its usage. Only scripts with offline help handling
261
263
  // belong here — forwarding to a script without it could misinterpret the
262
264
  // flag as input (e.g. a bot-name filter triggering live work).
263
- const HELP_OWNING_COMMANDS = new Set(['credit', 'tv', 'dw', 'pnl']);
265
+ const HELP_OWNING_COMMANDS = new Set(['credit', 'rich', 'tv', 'dw', 'pnl']);
264
266
  const requestedCommand = COMMAND_ALIASES[cliArgs[0]] ?? cliArgs[0];
265
267
  if (!HELP_OWNING_COMMANDS.has(requestedCommand)) {
266
268
  printCLIUsage();
@@ -1008,6 +1010,24 @@ async function handleCLICommands() {
1008
1010
  process.exit(result.status ?? 0);
1009
1011
  return true;
1010
1012
  }
1013
+ case 'rich': {
1014
+ const { spawnSync } = require('child_process');
1015
+ const scriptArgs = buildRuntimeScriptArgs({
1016
+ codeRoot: __dirname,
1017
+ scriptSegments: ['scripts', 'rich_list'],
1018
+ scriptArgs: cliArgs.slice(1),
1019
+ });
1020
+ const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
1021
+ cwd: PATHS.PROJECT_ROOT,
1022
+ stdio: 'inherit',
1023
+ });
1024
+ if (result.error) {
1025
+ console.error(`rich: ${result.error.message}`);
1026
+ process.exit(1);
1027
+ }
1028
+ process.exit(result.status ?? 0);
1029
+ return true;
1030
+ }
1011
1031
  case 'git': {
1012
1032
  // Repository statistics analyzer (scripts/analyze-git.ts): parses
1013
1033
  // git history and writes analysis/charts/repo-stats.html. Git-only;
@@ -79,14 +79,16 @@ function computeHuberWindowSlopePct(amaValues, index, lookbackBars, hub = AMA_SL
79
79
  return null;
80
80
  // Local linear fit needs the full window at both ends; reject non-positive
81
81
  // values anywhere in the window (Number(null) is 0) before fitting.
82
- const y = [];
83
- for (let k = index - bars; k <= index; k++) {
84
- const v = Number(amaValues[k]);
82
+ // The window is exactly [index - bars, index], so n is known up front and
83
+ // y can be pre-sized (no per-bar push growth).
84
+ const n = bars + 1;
85
+ const y = new Array(n);
86
+ for (let i = 0; i < n; i++) {
87
+ const v = Number(amaValues[index - bars + i]);
85
88
  if (!Number.isFinite(v) || v <= 0)
86
89
  return null;
87
- y.push(Math.log(v));
90
+ y[i] = Math.log(v);
88
91
  }
89
- const n = y.length;
90
92
  // Fill any missing field from the canonical constant. Production never passes
91
93
  // `hub` (the default is the constant), so this only guards a partial override
92
94
  // from silently skipping the IRLS loop or injecting NaN weights.
@@ -116,18 +118,31 @@ function computeHuberWindowSlopePct(amaValues, index, lookbackBars, hub = AMA_SL
116
118
  const a = sw === 0 ? 0 : (swy - b * swx) / sw;
117
119
  return { a, b };
118
120
  };
119
- let fit = wls(new Array(n).fill(1)); // OLS initialisation
121
+ // Scratch buffers are reused across the IRLS passes instead of allocating a
122
+ // fresh resid/abs/w triple (plus the sort copy) every iteration. This is the
123
+ // per-bar hot path of the dynamic-weight series, so the allocations dominate
124
+ // the fit arithmetic at the 16-bar window. The loops keep the original
125
+ // operation order so the returned slope is bit-for-bit unchanged.
126
+ const ones = new Array(n).fill(1);
127
+ const resid = new Array(n);
128
+ const abs = new Array(n);
129
+ const w = new Array(n);
130
+ let fit = wls(ones); // OLS initialisation
120
131
  for (let iter = 0; iter < hubIterations; iter++) {
121
- const resid = y.map((v, i) => v - (fit.a + fit.b * (i - xMean)));
122
- const abs = resid.map(Math.abs).sort((p, q) => p - q);
123
- const mid = abs.length >> 1;
124
- const mad = abs.length % 2 === 1 ? abs[mid] : (abs[mid - 1] + abs[mid]) / 2;
132
+ for (let i = 0; i < n; i++)
133
+ resid[i] = y[i] - (fit.a + fit.b * (i - xMean));
134
+ for (let i = 0; i < n; i++)
135
+ abs[i] = Math.abs(resid[i]);
136
+ abs.sort((p, q) => p - q);
137
+ const mid = n >> 1;
138
+ const mad = n % 2 === 1 ? abs[mid] : (abs[mid - 1] + abs[mid]) / 2;
125
139
  // Floor the robust scale. On piecewise-perfect data (a pure ramp, a
126
140
  // constant series) the MAD can collapse to ~0, which makes the Huber
127
141
  // weights degenerate and the weighted fit unstable; the floor is far
128
142
  // below any real per-bar signal (the reset gate is ~7e-5 here).
129
143
  const s = Math.max(1.4826 * mad, hubScaleFloor);
130
- const w = resid.map((r) => Math.min(1, (hubC * s) / Math.max(Math.abs(r), 1e-12)));
144
+ for (let i = 0; i < n; i++)
145
+ w[i] = Math.min(1, (hubC * s) / Math.max(Math.abs(resid[i]), 1e-12));
131
146
  const next = wls(w);
132
147
  const moved = Math.abs(next.b - fit.b);
133
148
  fit = next;
@@ -64,8 +64,8 @@
64
64
  * "targetSpreadPercent": 2,
65
65
  * "weightDistribution": { "sell": 1, "buy": 1 },
66
66
  * "botFunds": { "sell": "100%", "buy": "100%" },
67
- * "activeOrders": { "sell": 20, "buy": 20 },
68
- * "reserveOrders": { "buy": 0, "sell": 0 }, // Edge reserves: extra live orders (buy: floor, sell: ceiling)
67
+ * "coreOrders": { "sell": 20, "buy": 20 },
68
+ * "edgeOrders": { "buy": 0, "sell": 0 }, // Edge orders: extra live orders (buy: floor, sell: ceiling)
69
69
  * "poolRef": null, // Optional pinned pool ID for startPrice "pool"
70
70
  * "debtPolicy": { ... }, // MPA/credit lending policy — docs/MPA_CREDIT_USAGE.md
71
71
  * "min_BTS_value": 0, // Minimum BTS value threshold for operations
@@ -157,6 +157,9 @@ declare function loadGeneralSettings(): {
157
157
  FILL_TOTALS_RETRY_MAX_MS: number;
158
158
  SPREAD_STALE_WARN_MS: number;
159
159
  SPREAD_STALE_ESCALATE_MS: number;
160
+ SPREAD_CORRECTION_MAX_ATTEMPTS: number;
161
+ SPREAD_STALE_TRANSIENT_GRACE: number;
162
+ SPREAD_CORRECTION_SYNC_FRESH_MS: number;
160
163
  SPREAD_STALE_RESYNC_COOLDOWN_MS: number;
161
164
  BOUNDARY_HOLD_RESYNC_THRESHOLD: number;
162
165
  BOUNDARY_HOLD_RESYNC_COOLDOWN_MS: number;
@@ -379,11 +382,11 @@ declare function loadGeneralSettings(): {
379
382
  sell: string;
380
383
  buy: string;
381
384
  };
382
- activeOrders: {
385
+ coreOrders: {
383
386
  sell: number;
384
387
  buy: number;
385
388
  };
386
- reserveOrders: {
389
+ edgeOrders: {
387
390
  buy: number;
388
391
  sell: number;
389
392
  };
@@ -392,6 +395,7 @@ declare function loadGeneralSettings(): {
392
395
  FILL_PROCESSING: {
393
396
  MODE: string;
394
397
  OPERATION_TYPE: number;
398
+ COALESCE_BACKLOG_REPLAY: boolean;
395
399
  MAX_CONSECUTIVE_CONSUMER_FAILURES: number;
396
400
  CONSUMER_BACKOFF_INITIAL_MS: number;
397
401
  CONSUMER_BACKOFF_MAX_MS: number;
@@ -682,7 +686,7 @@ declare function isPoolRefClearInput(value: unknown): boolean;
682
686
  interface BotDraft extends UnknownRecord {
683
687
  accountId?: string;
684
688
  active?: boolean;
685
- activeOrders: {
689
+ coreOrders: {
686
690
  sell?: number;
687
691
  buy?: number;
688
692
  };
@@ -700,7 +704,7 @@ interface BotDraft extends UnknownRecord {
700
704
  name?: string;
701
705
  poolRef?: string | null;
702
706
  preferredAccount?: string;
703
- reserveOrders?: {
707
+ edgeOrders?: {
704
708
  sell?: number;
705
709
  buy?: number;
706
710
  };
@@ -64,8 +64,8 @@
64
64
  * "targetSpreadPercent": 2,
65
65
  * "weightDistribution": { "sell": 1, "buy": 1 },
66
66
  * "botFunds": { "sell": "100%", "buy": "100%" },
67
- * "activeOrders": { "sell": 20, "buy": 20 },
68
- * "reserveOrders": { "buy": 0, "sell": 0 }, // Edge reserves: extra live orders (buy: floor, sell: ceiling)
67
+ * "coreOrders": { "sell": 20, "buy": 20 },
68
+ * "edgeOrders": { "buy": 0, "sell": 0 }, // Edge orders: extra live orders (buy: floor, sell: ceiling)
69
69
  * "poolRef": null, // Optional pinned pool ID for startPrice "pool"
70
70
  * "debtPolicy": { ... }, // MPA/credit lending policy — docs/MPA_CREDIT_USAGE.md
71
71
  * "min_BTS_value": 0, // Minimum BTS value threshold for operations
@@ -1274,7 +1274,7 @@ async function promptBotData(base = {}, index = 0, baseIndex = index) {
1274
1274
  console.log(`${COLORS.yellowBold}2) Identity:${COLORS.reset} ${COLORS.orange}Name:${COLORS.reset} ${data.name || '?'}, ${COLORS.orange}Account:${COLORS.reset} ${data.preferredAccount || '?'} | ${COLORS.orange}Active:${COLORS.reset} ${colorBooleanFlag(data.active, true)}, ${COLORS.orange}DryRun:${COLORS.reset} ${colorBooleanFlag(data.dryRun, false)}`);
1275
1275
  console.log(`${COLORS.yellowBold}3) Price:${COLORS.reset} ${COLORS.orange}Range:${COLORS.reset} [${colorPriceRangeValue(data.minPrice)} - ${colorPriceRangeValue(data.maxPrice)}] | ${COLORS.orange}Start:${COLORS.reset} ${colorStartPriceValue(data.startPrice)}, ${COLORS.orange}Pool:${COLORS.reset} ${formatPoolRefLabel(data)} | ${COLORS.orange}GridPrice:${COLORS.reset} ${colorGridPriceValue(data.gridPrice)}`);
1276
1276
  console.log(`${COLORS.yellowBold}4) Grid:${COLORS.reset} ${COLORS.orange}Weights:${COLORS.reset} (S:${data.weightDistribution.sell}, B:${data.weightDistribution.buy}) | ${COLORS.orange}Increment:${COLORS.reset} ${data.incrementPercent}%, ${COLORS.orange}Spread:${COLORS.reset} ${data.targetSpreadPercent}%`);
1277
- console.log(`${COLORS.yellowBold}5) Inventory:${COLORS.reset} ${COLORS.orange}Sell:${COLORS.reset} ${colorPercentageInput(data.botFunds.sell)}, ${COLORS.orange}Buy:${COLORS.reset} ${colorPercentageInput(data.botFunds.buy)} | ${COLORS.orange}MarketOrder:${COLORS.reset} (S:${data.activeOrders.sell}, B:${data.activeOrders.buy}) | ${COLORS.orange}EdgeOrder:${COLORS.reset} (S:${data.reserveOrders?.sell ?? 0}, B:${data.reserveOrders?.buy ?? 0})`);
1277
+ console.log(`${COLORS.yellowBold}5) Inventory:${COLORS.reset} ${COLORS.orange}Sell:${COLORS.reset} ${colorPercentageInput(data.botFunds.sell)}, ${COLORS.orange}Buy:${COLORS.reset} ${colorPercentageInput(data.botFunds.buy)} | ${COLORS.orange}CoreOrder:${COLORS.reset} (S:${data.coreOrders.sell}, B:${data.coreOrders.buy}) | ${COLORS.orange}EdgeOrder:${COLORS.reset} (S:${data.edgeOrders?.sell ?? 0}, B:${data.edgeOrders?.buy ?? 0})`);
1278
1278
  {
1279
1279
  const flags = adapterFlags();
1280
1280
  const inert = !isAmaGridPriceDraft() && (flags.ama || flags.dynamicWeight || flags.asymmetricBounds);
@@ -1418,23 +1418,23 @@ async function promptBotData(base = {}, index = 0, baseIndex = index) {
1418
1418
  const fBuy = await askNumberOrPercentage('botFunds buy amount', data.botFunds.buy);
1419
1419
  if (fBuy === undefined || fBuy === '\x1b')
1420
1420
  break;
1421
- const oSell = await askIntegerInRange('activeOrders sell count', data.activeOrders.sell, 1, 100);
1421
+ const oSell = await askIntegerInRange('coreOrders sell count', data.coreOrders.sell, 1, 100);
1422
1422
  if (typeof oSell !== 'number')
1423
1423
  break;
1424
- const oBuy = await askIntegerInRange('activeOrders buy count', data.activeOrders.buy, 1, 100);
1424
+ const oBuy = await askIntegerInRange('coreOrders buy count', data.coreOrders.buy, 1, 100);
1425
1425
  if (typeof oBuy !== 'number')
1426
1426
  break;
1427
- const rBuy = await askIntegerInRange('reserveOrders buy floor count (0 disables)', data.reserveOrders?.buy ?? 0, 0, 100);
1427
+ const rBuy = await askIntegerInRange('edgeOrders buy floor count (0 disables)', data.edgeOrders?.buy ?? 0, 0, 100);
1428
1428
  if (typeof rBuy !== 'number')
1429
1429
  break;
1430
- const rSell = await askIntegerInRange('reserveOrders sell ceiling count (0 disables)', data.reserveOrders?.sell ?? 0, 0, 100);
1430
+ const rSell = await askIntegerInRange('edgeOrders sell ceiling count (0 disables)', data.edgeOrders?.sell ?? 0, 0, 100);
1431
1431
  if (typeof rSell !== 'number')
1432
1432
  break;
1433
1433
  data.botFunds.sell = fSell;
1434
1434
  data.botFunds.buy = fBuy;
1435
- data.activeOrders.sell = oSell;
1436
- data.activeOrders.buy = oBuy;
1437
- data.reserveOrders = { buy: rBuy, sell: rSell };
1435
+ data.coreOrders.sell = oSell;
1436
+ data.coreOrders.buy = oBuy;
1437
+ data.edgeOrders = { buy: rBuy, sell: rSell };
1438
1438
  showMenu = true;
1439
1439
  break;
1440
1440
  case '6': {
@@ -1743,6 +1743,9 @@ async function main() {
1743
1743
  saveBotsConfig(config, filePath);
1744
1744
  result.commitAdapter?.();
1745
1745
  console.log(`\nAdded bot '${result.data.name}' to ${path.basename(filePath)}.`);
1746
+ // Return to the Actions menu instead of immediately
1747
+ // opening another blank New Bot editor.
1748
+ break;
1746
1749
  }
1747
1750
  catch (err) {
1748
1751
  console.log(`\n❌ Invalid input: ${getErrorMessage(err)}\n`);