Patch 2 max age exit#72
Open
kimilmawan-19 wants to merge 5 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.