Skip to content

Patch 2 max age exit#72

Open
kimilmawan-19 wants to merge 5 commits into
yunus-0x:mainfrom
kimilmawan-19:patch-2-max-age-exit
Open

Patch 2 max age exit#72
kimilmawan-19 wants to merge 5 commits into
yunus-0x:mainfrom
kimilmawan-19:patch-2-max-age-exit

Conversation

@kimilmawan-19

Copy link
Copy Markdown

No description provided.

Ubuntu and others added 5 commits May 17, 2026 18:50
Adds Rule 6 to getDeterministicCloseRule: closes positions that have
exceeded maxPositionAgeMinutes (default 48h / 2880 min). Respects
pnlSuspect guard consistent with Rules 1-2.
- tools/market-data.js: DexScreener integration (60s cache, 5s timeout,
  returns null on any failure)
- config.js: emergencyExits.volumeCollapse + rapidPriceDrop defaults
- state.js: peak_volume_5m_usd, last_market_data_at, volume_history fields
  + batchUpdateMarketData() for single-write bulk state update
- index.js: fetch market data once per unique pool per management cycle;
  getDeterministicCloseRule gains optional marketData param; Rule 7
  (volume collapse: >70% drop from peak + 2x sell pressure) and Rule 8
  (rapid dump: <-8% in 5m with negative PnL); decision-log on trigger;
  /test-emergency-exit <n> REPL dry-run command
- telegram.js: notifyEmergencyExit() with volume/sell-pressure details
- user-config.example.json: emergencyExits sample config
- test/market-data.test.js: 18 unit tests (fetch, cache, error paths)
- test/emergency-exit.test.js: 15 unit tests (rule logic, edge cases)
Bug fixes:
- index.js: PnL poll (30s fast path) was calling getDeterministicCloseRule
  without marketData, making Rules 7 & 8 unreachable from the poll.
  Now fetches DexScreener data (60s cache) per position before evaluating.
- index.js: management cycle silently skipped emergency rules when
  DexScreener returned null. Now logs a warning per position.

Logging additions:
- tools/market-data.js: latency tracking per fetch, cache hit/miss
  counters, getMarketDataStats() export, latency in all log lines
- index.js: [pnl_poll] vs [mgmt_cycle] prefix on Rule 7/8 trigger logs
  to track which path catches more emergency exits

New REPL command:
- /test-pnl-poll <n>: simulates the 30s poll for position n, shows
  DexScreener data (cache HIT/MISS + latency), trailing TP state,
  which rule would trigger, and session cache stats
Queued commands (e.g. /test-pnl-poll) were silently dropped because
drainTelegramQueue() was only called from the REPL finally block, not
from runManagementCycle or runScreeningCycle. Commands sent while the
bot was busy would be queued but never processed after the cycle ended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants